fix(image): reject non-positive duration in saveGif()#9015
Open
Gooh456 wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
dug into #8710. root cause is in
saveGif()(src/image/loading_displaying.js):with
duration <= 0,nFramescomes out0, so the capture loop records no frames andframesstays empty. later_generateGlobalPalettedoesnew Uint8Array(frames.length * frames[0].length)—frames[0]isundefined, hence the reportedTypeError: 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 aRangeErrorbefore 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