File tree 3 files changed +28
-6
lines changed
3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -1885,8 +1885,8 @@ PHP_FUNCTION(fgetcsv)
1885
1885
1886
1886
if (len_is_null || len == 0 ) {
1887
1887
len = -1 ;
1888
- } else if (len < 0 ) {
1889
- zend_argument_value_error (2 , "must be a greater than or equal to 0" );
1888
+ } else if (len < 0 || len > ( ZEND_LONG_MAX - 1 ) ) {
1889
+ zend_argument_value_error (2 , "must be between 0 and " ZEND_LONG_FMT , ( ZEND_LONG_MAX - 1 ) );
1890
1890
RETURN_THROWS ();
1891
1891
}
1892
1892
Original file line number Diff line number Diff line change @@ -48,11 +48,11 @@ try {
48
48
echo $ e ->getMessage () . \PHP_EOL ;
49
49
}
50
50
?>
51
- --EXPECT --
51
+ --EXPECTF --
52
52
fgetcsv() 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
56
56
fgetcsv() with delimiter as empty string
57
57
fgetcsv(): Argument #3 ($separator) must be a single character
58
58
fgetcsv() 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