fix(posters): validate SVG icon dimensions and file type (#350)

Validates SVG dimensions before scale calculation to prevent division
by zero. Warns when non-SVG files passed with hint about required format.

Co-authored-by: bitr8 <bitr8@users.noreply.github.com>
This commit is contained in:
bitr8
2026-01-14 08:18:07 +11:00
committed by GitHub
parent 287befaa50
commit be53722678
+20
View File
@@ -1302,6 +1302,11 @@ async function embedSVGIconInSVG(
// Only process SVG files in this function
if (!filename.toLowerCase().endsWith('.svg')) {
logger.warn('Icon is not an SVG file, cannot embed in poster', {
iconPath,
filename,
hint: 'Custom icons must be SVG format for poster templates',
});
return null;
}
@@ -1332,6 +1337,21 @@ async function embedSVGIconInSVG(
if (heightMatch) svgHeight = parseFloat(heightMatch[1]);
}
// Validate SVG dimensions - prevent division by zero or NaN
if (
!Number.isFinite(svgWidth) ||
!Number.isFinite(svgHeight) ||
svgWidth <= 0 ||
svgHeight <= 0
) {
logger.warn('Invalid SVG dimensions, cannot embed icon', {
iconPath,
svgWidth,
svgHeight,
});
return null;
}
// Calculate scale to fit the element dimensions while maintaining aspect ratio
const scaleX = element.width / svgWidth;
const scaleY = element.height / svgHeight;