Skip to content

Commit e68bac5

Browse files
committed
Fix unsigned wrap in bzdecompress() output realloc at source_len UINT_MAX
The input guard rejects only source_len > UINT_MAX, so source_len == UINT_MAX is permitted and assigned to bzs.avail_out (unsigned int). The per-iteration realloc then computed bzs.avail_out+1 in unsigned int arithmetic, which wraps to 0 at UINT_MAX, allocating no headroom while bz2 still believes avail_out bytes are available at next_out: the next decompress round writes past the buffer. Compute the term as (size_t)bzs.avail_out + 1 so the increment is done in size_t and cannot wrap, matching the (size_t) casts already used on the same call.
1 parent 0fff3cc commit e68bac5

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

ext/bz2/bz2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ PHP_FUNCTION(bzdecompress)
544544
/* no reason to continue if we're going to drop it anyway */
545545
break;
546546
}
547-
dest = zend_string_safe_realloc(dest, 1, bzs.avail_out+1, (size_t) size, 0);
547+
dest = zend_string_safe_realloc(dest, 1, (size_t) bzs.avail_out + 1, (size_t) size, 0);
548548
bzs.next_out = ZSTR_VAL(dest) + size;
549549
}
550550

0 commit comments

Comments
 (0)