Skip to content

fix(image): reject non-positive duration in saveGif()#9015

Open
Gooh456 wants to merge 1 commit into
processing:mainfrom
Gooh456:fix/savegif-nonpositive-duration
Open

fix(image): reject non-positive duration in saveGif()#9015
Gooh456 wants to merge 1 commit into
processing:mainfrom
Gooh456:fix/savegif-nonpositive-duration

Conversation

@Gooh456

@Gooh456 Gooh456 commented Jul 24, 2026

Copy link
Copy Markdown

dug into #8710. root cause is in saveGif() (src/image/loading_displaying.js):

with duration <= 0, nFrames comes out 0, so the capture loop records no frames and frames stays empty. later _generateGlobalPalette does new Uint8Array(frames.length * frames[0].length)frames[0] is undefined, hence the reported TypeError: Cannot read properties of undefined (reading 'length'). same thing happens for any negative duration.

every other bad argument in saveGif() (fileName, delay, units, silent, ...) already throws up front. duration was the one gap, so this guards it the same way and throws a RangeError before recording starts instead of blowing up deep in palette generation.

added a small regression test in test/unit/image/downloading.js asserting saveGif('myGif', 0) and a negative value reject.

Fixes #8710

saveGif('name', 0) or a negative duration captures zero frames, then
_generateGlobalPalette does `new Uint8Array(frames.length * frames[0].length)`
with frames empty, so frames[0] is undefined and it throws
"Cannot read properties of undefined (reading 'length')".

Every other bad param in saveGif already throws up front, so guard duration
the same way and throw a RangeError before recording starts.

Fixes processing#8710

Signed-off-by: Kyue <164024549+Gooh456@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

saveGif() crashes when duration <= 0 (empty frame list path)

1 participant