Fix integer underflow in exif HEIF parsing#20630
Closed
Oblivionsage wants to merge 2 commits intophp:masterfrom
Closed
Fix integer underflow in exif HEIF parsing#20630Oblivionsage wants to merge 2 commits intophp:masterfrom
Oblivionsage wants to merge 2 commits intophp:masterfrom
Conversation
When pos.size is less than 2, the subtraction pos.size - 2 causes an unsigned integer underflow, resulting in a ~4GB allocation attempt. Add minimum size check (pos.size >= 2) to prevent the underflow.
ndossche
approved these changes
Dec 2, 2025
Member
ndossche
left a comment
There was a problem hiding this comment.
Thanks!
For the future, this should actually target the PHP-8.5 branch. That's because bugfixes always should target the lowest supported branch and we will merge upwards.
Doesn't matter now as I'll just cherry-pick into the right branch.
Leaving this open for a bit to see if anyone else has comments.
bukka
reviewed
Dec 2, 2025
Member
bukka
left a comment
There was a problem hiding this comment.
Can you add a test with that malicious image that you have?
Contributor
Author
added a test in the second commit , it patches image029.heic to set extent_length=1 and verifies the fix handles it gracefully |
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.
When pos.size is less than 2, the subtraction pos.size - 2 causes an unsigned integer underflow, resulting in a ~4GB allocation attempt.
Add minimum size check (pos.size >= 2) to prevent the underflow.
Closes #20631