Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a potential integer overflow in the LZW encoding logic for very large GIFs (65,535 x 65,535 pixels). The overflow occurs when calculating the malloc size for LZW data, where the sum of numPixel + 2 + maxResets can exceed the maximum value of a 32-bit unsigned integer (4,294,967,295). The fix casts numPixel to size_t before the arithmetic, ensuring the entire expression is evaluated using the larger type.
Changes:
- Cast
numPixeltosize_tin malloc size calculation to prevent integer overflow for maximum-sized GIFs
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
110238f to
d4b5e9d
Compare
MCLoebl
approved these changes
Feb 21, 2026
dloebl
added a commit
that referenced
this pull request
Feb 22, 2026
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.
Regression introduced with v0.5.1/#84.
There is potentially a small integer overflow in the LZW encoding logic affecting very large GIFs (65.535 x 65.535):
u32:numPixelis at max4.294.836.225:(2^16-1)^2u32:maxResetsis at max1.119.029:4.294.836.225/3838And now
4.294.836.225+1.119.029+2is4.295.955.256- which is above the maximum value a 32-bit unsigned integer can hold4.294.967.295(2^32-1).The fix is to simply cast to
size_tbefore the calculation:This is only affecting very large GIFs (at the very end of the dimension limit), with small color palettes.
In a follow-up, we can also make this handling more gracefully on 32-bit systems - but for now it's fine.