Skip to content

Make uint32_t to zend_long conversion explicit in unpack() - #24258

Open
ushevchenko wants to merge 1 commit into
php:masterfrom
ushevchenko:issue-24257-unpack-uint32-cast
Open

ushevchenko wants to merge 1 commit into
php:masterfrom
ushevchenko:issue-24257-unpack-uint32-cast

Conversation

@ushevchenko

Copy link
Copy Markdown

Fixes #24257

unpack() converts a uint32_t to zend_long implicitly for the L, N and V formats. On 32-bit builds this conversion is implementation-defined for values above INT32_MAX. The signed variant (l) in the same block already uses an explicit cast.

This change makes the conversion explicit. The returned values do not change on any platform, so no test was added.

The issue was identified by static analysis (Svace) and has not been reproduced at runtime on a 32-bit build.

Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.

Problem:
In unpack(), a uint32_t value is implicitly converted to zend_long
for the L, N and V formats. On 32-bit builds values above INT32_MAX
may become negative; the conversion is implementation-defined.
Solution: add an explicit (zend_long) cast. The returned values do not
change on any platform.
Signed-off-by: Uliya Shevchenko <u.shevchenko@fobos-nt.ru>
Signed-off-by: Georgij Tsarin <crystarm@altlinux.org>
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.

Potential incorrect sign conversion of uint32_t to zend_long in unpack() on 32-bit builds (ext/standard/pack.c)

1 participant