Bound the HEIF meta box allocation by the file size - #226
Closed
iliaal wants to merge 1 commit into
Closed
Conversation
exif_scan_HEIF_header() allocated box.size - box_header_size with only a lower bound, so a 37-byte file could claim a 128MB meta box and force the allocation before any read is attempted. The second allocation in the same block is already bounded by pos.size < ImageInfo->FileSize; apply the same bound to the first. Closes phpGH-23201
iliaal
force-pushed
the
fix/exif-heif-meta-box-bound
branch
from
August 10, 2026 18:12
d4d0204 to
e909091
Compare
Owner
Author
|
Promoted upstream: php#23201 |
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.
exif_scan_HEIF_header()takes the meta box size straight from the file and allocates it with only a lower bound of 36, so a 37-byte HEIF claiming a 128MB box forces that allocation before a single byte is read.memory_limitstops it, so this is hardening rather than a vulnerability, but the same block already bounds its second allocation by pos.size < ImageInfo->FileSize and the first one should match.With memory_limit=32M that is "Allowed memory size of 33554432 bytes exhausted (tried to allocate 134217720 bytes)" from a 37-byte file. PHP-8.4 has no HEIF parser, so this starts at 8.5.