Skip to content

Commit 0b1fae9

Browse files
author
Andrey Kovalev
committed
ext/standard/image.c: Fix unsafe integer conversion
- Add checks for image dimensions (width/height/bits/channels) against INT32_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 0b1fae9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ext/standard/image.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "php.h"
1919
#include <stdio.h>
20+
#include <stdint.h>
2021
#ifdef HAVE_FCNTL_H
2122
#include <fcntl.h>
2223
#endif
@@ -1520,7 +1521,12 @@ static void php_getimagesize_from_stream(php_stream *stream, char *input, zval *
15201521
break;
15211522
}
15221523

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

0 commit comments

Comments
 (0)