Skip to content

Commit a429d4e

Browse files
committed
Add comment explaining
1 parent b0f28b6 commit a429d4e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ext/standard/string.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,6 +2138,12 @@ static zend_string *php_chunk_split(const char *src, size_t srclen, const char *
21382138
chunks = srclen / chunklen;
21392139
restlen = srclen - chunks * chunklen; /* srclen % chunklen */
21402140

2141+
/*
2142+
* chunks+1 cannot overflow as ZEND_LONG_MAX, which is smaller than SIZE_MAX (due to signedness).
2143+
* This holds if sizeof(zend_long) == sizeof(size_t) which is not true on x32.
2144+
* As such an overflow fatal error is emitted, see chunk_split_variation(1|2)_32bit.phpt
2145+
* srclen + 1 can't overflow, because the maximum string length is smaller than SIZE_MAX due to the string header.
2146+
*/
21412147
dest = zend_string_safe_alloc(chunks+1, endlen, srclen+1, 0);
21422148

21432149
for (p = src, q = ZSTR_VAL(dest); p < (src + srclen - chunklen + 1); ) {

0 commit comments

Comments
 (0)