Repository navigation
ext/phar: 32-bit/64-bit divergence parsing tar entries with size ≥ 2 GiB (uint32_t → zend_off_t) - #24242
Open
PavlNekrasov wants to merge 1 commit into
Open
ext/phar: 32-bit/64-bit divergence parsing tar entries with size ≥ 2 GiB (uint32_t → zend_off_t)#24242PavlNekrasov wants to merge 1 commit into
PavlNekrasov wants to merge 1 commit into
Conversation
LamentXU123
requested changes
Oct 10, 2026
| { | ||
| zend_off_t offset = php_stream_tell(fp); | ||
|
|
||
| if (offset < 0 || (uint64_t) size > (uint64_t) ZEND_LONG_MAX |
Member
There was a problem hiding this comment.
This is causing CI error. size is uint32_t which is impossible to be bigger than ZEND_LONG_MAX in 64 bit
Tar entry sizes at or above 2 GiB cannot be represented by the signed zend_off_t used by php_stream_seek() on 32-bit systems. In addition, rounding an entry size to a 512-byte boundary can overflow uint32_t, and unchecked php_stream_tell() failures can be converted to valid size_t values. Reject archive and entry sizes outside the supported stream offset range, check rounding before it occurs, and validate data skips against the archive length. Signed-off-by: Pavel Nekrasov <p.nekrasov@fobos-nt.ru> Signed-off-by: Georgij Tsarin <crystarm@altlinux.org>
PavlNekrasov
force-pushed
the
fix/phar-tar-32bit-size-bounds
branch
from
October 11, 2026 10:14
2008b88 to
455df08
Compare
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.
Description:
The tar header's
sizefield is read asuint32_tand passed as-is tophp_stream_seek()(offset is signedzend_off_t). On 32-bit,zend_off_tisint32, so sizes with the high bit set wrap into a negative offset — UBSan flags it,getSize()returns a negative value, and the corrupt/truncated check never triggers. On 64-bit the same size fits and the entry is correctly rejected as truncated.Reproducer:
With
test.tar(entrybigfile, header size0xC0000000= 3221225472):32-bit:
UBSan:
64-bit:
Env: PHP 8.3.31; 32-bit and 64-bit builds.
Found by Linux Verification Center (linuxtesting.org) with SVACE