Skip to content

Throw when the size does not fit into an int in PharFileInfo::getCompressedSize() - #23719

Open
PavlNekrasov wants to merge 1 commit into
php:masterfrom
PavlNekrasov:fix/phar-getcompressedsize-sign-extension
Open

PavlNekrasov wants to merge 1 commit into
php:masterfrom
PavlNekrasov:fix/phar-getcompressedsize-sign-extension

Conversation

@PavlNekrasov

Copy link
Copy Markdown

fix #23718

Throw a BadMethodCallException on platforms where the size does not fit into a zend_long, 64-bit platforms are unaffected.

Signed-off-by: p.nekrasov@fobos-nt.ru
Signed-off-by: crystarm@altlinux.org

Problem:
The field compressed_filesize is a uint32_t, but
PharFileInfo::getCompressedSize() returns it with RETURN_LONG. zend_long
is 32-bit on 32-bit platforms, so a size above ZEND_LONG_MAX is reported
as a negative number there and correctly on 64-bit ones.

Solution:
Throw a BadMethodCallException on platforms where the size does not fit
into a zend_long, 64-bit platforms are unaffected.

Signed-off-by: p.nekrasov@fobos-nt.ru
Signed-off-by: crystarm@altlinux.org
@LamentXU123

LamentXU123 commented Sep 17, 2026

Copy link
Copy Markdown
Member

Hi. Thanks for the PR. Several questions:

  1. Do you think this as a bugfix should target lower branches?
  2. Perhaps a better PR title?
  3. While at it, are there similar bugs in the extension? From the first glance I think there may be. But I might be wrong.
  4. Can you add tests if applicable? Also perhaps NEWS?

Code wise I think this is correct.

@PavlNekrasov PavlNekrasov changed the title Fix: SIGN_EXTENSION Throw when the size does not fit into an int in PharFileInfo::getCompressedSize() Sep 17, 2026

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many such instances and people deal with negative values routinely. So I don't see why this (and other such issues) should be fixed.

Also if you are going to throw an exception don't use an SPL Exception (expecially one that makes no sense)

@LamentXU123

Copy link
Copy Markdown
Member

There are many such instances and people deal with negative values routinely. So I don't see why this (and other such issues) should be fixed.

I am not very sure about the convention here. But I do find many such instance in the code base (getSize()、filesize() and stat() and perhaps mount()).

Also if you are going to throw an exception don't use an SPL Exception (expecially one that makes no sense)

Can you explain the reason here? I am not familiar with SPL Exception so I can't tell why but I am willing to know, because I see some usage of this in the code base.

@Girgias

Girgias commented Sep 17, 2026

Copy link
Copy Markdown
Member

There are many such instances and people deal with negative values routinely. So I don't see why this (and other such issues) should be fixed.

I am not very sure about the convention here. But I do find many such instance in the code base (getSize()、filesize() and stat() and perhaps mount()).

Instance that throw an error if a u32 does not fit in a zend_long? I'm not sure I understand the sentence correctly.

Also if you are going to throw an exception don't use an SPL Exception (expecially one that makes no sense)

Can you explain the reason here? I am not familiar with SPL Exception so I can't tell why but I am willing to know, because I see some usage of this in the code base.

SPL exceptions are just bad, but also one shouldn't be throwing an exception from a different extension Phar, expecially for Phar related errors, PharException exists for a reason. Moreover our coding style policy says:

An extension MUST NOT throw exceptions that it did not define itself, except for the global TypeError or ValueError exceptions thrown during parameter parsing and parameter validation, and (subclasses of) exceptions that are already defined to be thrown by a class that is subclassed itself. If an extension uses external functionality that may throw an exception it MUST wrap any exception thrown by that functionality into an appropriate exception of its own. It MUST set the $previous property to the original exception when doing so.

See also #21766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sign extension at phar_object.c

3 participants