File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -476,8 +476,15 @@ PHP_FUNCTION(bzcompress)
476476 + .01 x length of data + 600 which is the largest size the results of the compression
477477 could possibly be, at least that's what the libbz2 docs say (thanks to jeremy@nirvani.net
478478 for pointing this out). */
479- // TODO Check source string length fits in unsigned int
480- dest_len = (unsigned int ) (source_len + (0.01 * source_len ) + 600 );
479+ size_t chunk_len = source_len + source_len / 100 + 600 ;
480+ const size_t min = MIN (ZSTR_MAX_LEN , UINT_MAX );
481+
482+ if (chunk_len < source_len || chunk_len > min ) {
483+ zend_argument_value_error (1 , "must have a length less than or equal to %zu" , min );
484+ RETURN_THROWS ();
485+ }
486+
487+ dest_len = (unsigned int ) chunk_len ;
481488
482489 /* Allocate the destination buffer */
483490 dest = zend_string_alloc (dest_len , 0 );
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Bug GH-20620 (bzcompress with large source)
3+ --EXTENSIONS--
4+ bz2
5+ --SKIPIF--
6+ <?php
7+ if (PHP_INT_SIZE != 8 ) die ('skip this test is for 64bit platforms only ' );
8+ if (getenv ('SKIP_SLOW_TESTS ' )) die ('skip slow tests excluded by request ' );
9+ ?>
10+ --INI--
11+ memory_limit=-1
12+ --FILE--
13+ <?php
14+ try {
15+ bzcompress (str_repeat ('1 ' , 4295163906 ));
16+ } catch (\ValueError $ e ) {
17+ echo $ e ->getMessage (), PHP_EOL ;
18+ }
19+ ?>
20+ --EXPECTF--
21+ bzcompress(): Argument #1 ($data) must have a length less than or equal to %d
You can’t perform that action at this time.
0 commit comments