From c84ba3bdf69a61309a5bbd07c7d8f32044fc8bc6 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 8 Feb 2024 17:17:46 +0200 Subject: [PATCH] Prevent crashes when computing aspect ratios on zero media width or height --- .../Timeline/TimelineItems/RoomTimelineItemFactory.swift | 6 +++--- changelog.d/pr-2437.bugfix | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changelog.d/pr-2437.bugfix diff --git a/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift b/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift index a109dcdee..d87b0925e 100644 --- a/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift +++ b/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift @@ -134,7 +134,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol { var aspectRatio: CGFloat? let width = imageInfo.width.map(CGFloat.init) let height = imageInfo.height.map(CGFloat.init) - if let width, let height { + if let width, let height, width > 0, height > 0 { aspectRatio = width / height } @@ -488,7 +488,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol { let height = messageContent.info?.height.map(CGFloat.init) var aspectRatio: CGFloat? - if let width, let height { + if let width, let height, width > 0, height > 0 { aspectRatio = width / height } @@ -508,7 +508,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol { let height = messageContent.info?.height.map(CGFloat.init) var aspectRatio: CGFloat? - if let width, let height { + if let width, let height, width > 0, height > 0 { aspectRatio = width / height } diff --git a/changelog.d/pr-2437.bugfix b/changelog.d/pr-2437.bugfix new file mode 100644 index 000000000..f9c59983e --- /dev/null +++ b/changelog.d/pr-2437.bugfix @@ -0,0 +1 @@ +Prevent crashes when computing aspect ratios on zero media width or height \ No newline at end of file