diff --git a/NEWS b/NEWS index 79536c0ce210..4fbc7e89eb11 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,9 @@ PHP NEWS - BCMath: . Added NUL-byte validation to BCMath functions. (jorgsowa) +- BZ2: + . Reject oversized input in bzdecompress(). (arshidkv12) + - Date: . Update timelib to 2022.16. (Derick) diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c index c505005ab00a..512632fe8a22 100644 --- a/ext/bz2/bz2.c +++ b/ext/bz2/bz2.c @@ -519,11 +519,15 @@ PHP_FUNCTION(bzdecompress) bzs.bzalloc = NULL; bzs.bzfree = NULL; + if (source_len > UINT_MAX) { + zend_argument_value_error(1, "must have a length less than or equal to %u", UINT_MAX); + RETURN_THROWS(); + } + if (BZ2_bzDecompressInit(&bzs, 0, (int)small) != BZ_OK) { RETURN_FALSE; } - // TODO Check source string length fits in unsigned int bzs.next_in = source; bzs.avail_in = source_len; diff --git a/ext/bz2/tests/bzdecompress_input_too_large.phpt b/ext/bz2/tests/bzdecompress_input_too_large.phpt new file mode 100644 index 000000000000..88c93d366c54 --- /dev/null +++ b/ext/bz2/tests/bzdecompress_input_too_large.phpt @@ -0,0 +1,24 @@ +--TEST-- +bzdecompress() rejects input larger than 4294967296 +--EXTENSIONS-- +bz2 +--INI-- +memory_limit=8G +--SKIPIF-- + +--FILE-- +getMessage(), "\n"; +} +?> +--EXPECT-- +bzdecompress(): Argument #1 ($data) must have a length less than or equal to 4294967295