Reject non-positive duration in saveGif to avoid empty-frames crash#8740
Open
Chessing234 wants to merge 1 commit intoprocessing:mainfrom
Open
Reject non-positive duration in saveGif to avoid empty-frames crash#8740Chessing234 wants to merge 1 commit intoprocessing:mainfrom
Chessing234 wants to merge 1 commit intoprocessing:mainfrom
Conversation
When saveGif is called with duration <= 0, the main recording loop never runs and the frames array stays empty. _generateGlobalPalette then reads frames[0].length, producing a cryptic TypeError. Validate duration > 0 up front with a clear error, matching the existing type checks. Fixes processing#8710
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.
Bug
saveGif('test', 0)(or any non-positive duration) crashes withTypeError: Cannot read properties of undefined (reading 'length')instead of a friendly error. Reported in #8710.Root cause
In
src/image/loading_displaying.js,saveGifvalidates thatdurationis a number but not its range. Whenduration <= 0:nFrames = duration * _frameRateis<= 0while (frameIterator < totalNumberOfFrames)loop never executesframesstays[]_generateGlobalPalette(frames)then readsframes[0].lengthon line 597 and throws.Fix
Add a 3-line range check directly after the existing
typeof durationcheck, in the same style as the surrounding validators:Why this is correct
duration > 0; existing tests intest/unit/image/downloading.jscontinue to pass unchanged.Fixes #8710