Skip to content

Commit

Permalink
Guards against creating very large UImages from SVGs
Browse files Browse the repository at this point in the history
Fixes openhab#817

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
  • Loading branch information
digitaldan committed Sep 14, 2024
1 parent a0b2c22 commit fa29577
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions openHAB/OpenHABSitemapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ struct OpenHABImageProcessor: ImageProcessor {
let svgkSourceNSData = SVGKSourceNSData.source(from: data, urlForRelativeLinks: nil)
let parseResults = SVGKParser.parseSource(usingDefaultSVGKParser: svgkSourceNSData)
if parseResults?.parsedDocument != nil, let image = SVGKImage(parsedSVG: parseResults, from: svgkSourceNSData), image.hasSize() {
if image.size.width > 1000 || image.size.height > 1000 {
return UIImage(named: "error.png") // Avoid too-large images which cause memory issues
}
return image.uiImage
} else {
return UIImage(named: "error.png")
Expand Down

0 comments on commit fa29577

Please sign in to comment.