prevent division by zero when image width or height is 0

catch error early before starting the decode/paint loop
This commit is contained in:
Frank
2025-11-06 23:09:09 +01:00
parent 10b3ac0eb1
commit 698da84b4a

View File

@@ -158,6 +158,12 @@ byte renderImageToSegment(Segment &seg) {
if (millis() - lastFrameDisplayTime < wait) return IMAGE_ERROR_WAITING;
decoder.getSize(&gifWidth, &gifHeight);
// bad gif size: prevent division by zero
if (gifWidth == 0 || gifHeight == 0) {
gifDecodeFailed = true;
USER_PRINTF("Invalid GIF dimensions: %dx%d\n", gifWidth, gifHeight);
return IMAGE_ERROR_GIF_DECODE;
}
// softhack007: pre-calculate upscaling for speedup
expandX = (seg_cols+(gifWidth-1)) / gifWidth;
expandY = (seg_rows+(gifHeight-1)) / gifHeight;