[php-src] master: Fix: SIGN_EXTENSION (#24258)
| From: | ushevchenko via GitHub | Date: | Tue, 13 Oct 2026 17:18:04 +0000 |
| Subject: | [php-src] master: Fix: SIGN_EXTENSION (#24258) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142239@lists.php.net to get a copy of this message | ||
Author: ushevchenko (ushevchenko)
Committer: GitHub (web-flow)
Pusher: ndossche
Date: 2026-10-13T19:18:01+02:00
Commit: https://github.com/php/php-src/commit/f1b9b1ac1a5609c011122d71e42220e7d5a48930
Raw diff: https://github.com/php/php-src/commit/f1b9b1ac1a5609c011122d71e42220e7d5a48930.diff
Fix: SIGN_EXTENSION (#24258)
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>
Changed paths:
M ext/standard/pack.c
Diff:
diff --git a/ext/standard/pack.c b/ext/standard/pack.c
index 969f5a2db742..3c6bb7c35e2f 100644
--- a/ext/standard/pack.c
+++ b/ext/standard/pack.c
@@ -1260,7 +1260,7 @@ PHP_FUNCTION(unpack)
if (type == 'l') {
v = (int32_t) x;
} else {
- v = x;
+ v = (zend_long) x;
}
ZVAL_LONG(&val, v);