Skip to content

Commit 2295fa9

Browse files
author
Andrey Kovalev
committed
ext/standard/image.c: Fix unsafe integer conversion
- Add checks for image dimensions (width/height/bits/channels) against ZEND_LONG_MAX. - Prevent sign-bit override when converting unsigned int to zend_long on 32-bit platforms. - Ensure consistent behavior across architectures for getimagesize() results. Reported-by: Dmitriy Fedin <[email protected]> Signed-off-by: Andrey Kovalev <[email protected]>
1 parent 042a975 commit 2295fa9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ext/standard/image.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,12 @@ static void php_getimagesize_from_stream(php_stream *stream, char *input, zval *
15201520
break;
15211521
}
15221522

1523-
if (result) {
1523+
if (result &&
1524+
result->width <= ZEND_LONG_MAX &&
1525+
result->height <= ZEND_LONG_MAX &&
1526+
result->bits <= ZEND_LONG_MAX &&
1527+
result->channels <= ZEND_LONG_MAX)
1528+
{
15241529
char temp[MAX_LENGTH_OF_LONG * 2 + sizeof("width=\"\" height=\"\"")];
15251530
array_init(return_value);
15261531
add_index_long(return_value, 0, result->width);

0 commit comments

Comments
 (0)