File tree Expand file tree Collapse file tree 4 files changed +29
-6
lines changed Expand file tree Collapse file tree 4 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ PHP NEWS
8989- Standard:
9090 . Fix passing non-finite timeout values in stream functions. (nielsdos)
9191 . Fixed GH-14780 p(f)sockopen timeout overflow. (David Carlier)
92+ . Fixed GH-15653 overflow on fgetcsv length parameter. (David Carlier)
9293
9394- Streams:
9495 . Fixed bug GH-15028 (Memory leak in ext/phar/stream.c). (nielsdos)
Original file line number Diff line number Diff line change @@ -1895,8 +1895,8 @@ PHP_FUNCTION(fgetcsv)
18951895
18961896 if (len_is_null || len == 0 ) {
18971897 len = -1 ;
1898- } else if (len < 0 ) {
1899- zend_argument_value_error (2 , "must be a greater than or equal to 0" );
1898+ } else if (len < 0 || len > ( ZEND_LONG_MAX - 1 ) ) {
1899+ zend_argument_value_error (2 , "must be between 0 and " ZEND_LONG_FMT , ( ZEND_LONG_MAX - 1 ) );
19001900 RETURN_THROWS ();
19011901 }
19021902
Original file line number Diff line number Diff line change @@ -48,11 +48,11 @@ try {
4848 echo $ e ->getMessage () . \PHP_EOL ;
4949}
5050?>
51- --EXPECT --
51+ --EXPECTF --
5252fgetcsv() with negative length
53- fgetcsv(): Argument #2 ($length) must be a greater than or equal to 0
54- fgetcsv(): Argument #2 ($length) must be a greater than or equal to 0
55- fgetcsv(): Argument #2 ($length) must be a greater than or equal to 0
53+ fgetcsv(): Argument #2 ($length) must be between 0 and %d
54+ fgetcsv(): Argument #2 ($length) must be between 0 and %d
55+ fgetcsv(): Argument #2 ($length) must be between 0 and %d
5656fgetcsv() with delimiter as empty string
5757fgetcsv(): Argument #3 ($separator) must be a single character
5858fgetcsv() with enclosure as empty string
Original file line number Diff line number Diff line change 1+ --TEST--
2+ GH-15653 (fgetcsv overflow on length argument)
3+ --FILE--
4+ <?php
5+ $ filename = __DIR__ . "/gh15653.tmp " ;
6+ touch ($ filename );
7+ $ fp = fopen ($ filename , "r " );
8+
9+ try {
10+ fgetcsv ($ fp , PHP_INT_MAX );
11+ } catch (\ValueError $ e ) {
12+ echo $ e ->getMessage () . PHP_EOL ;
13+ }
14+
15+ fgetcsv ($ fp , PHP_INT_MAX -1 );
16+ --CLEAN --
17+ <?php
18+ @unlink (__DIR__ . "/gh15653.tmp " );
19+ ?>
20+ --EXPECTF--
21+ fgetcsv(): Argument #2 ($length) must be between 0 and %d
22+ %A
You can’t perform that action at this time.
0 commit comments