Skip to content

Commit 57029ce

Browse files
committed
Fix buffer-overflow in php_fgetcsv() with \0 delimiter and enclosure
Fixes oss-fuzz #57392 Closes GH-10923
1 parent c2f3a60 commit 57029ce

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ PHP NEWS
6565
. Fixed bug GH-10885 (stream_socket_server context leaks). (ilutov)
6666
. Fixed bug GH-10052 (Browscap crashes PHP 8.1.12 on request shutdown
6767
(apache2)). (nielsdos)
68+
. Fixed oss-fuzz #57392 (Buffer-overflow in php_fgetcsv() with \0 delimiter
69+
and enclosure). (ilutov)
6870

6971
16 Mar 2023, PHP 8.1.17
7072

ext/standard/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int
20882088
while ((*tmp != delimiter) && isspace((int)*(unsigned char *)tmp)) {
20892089
tmp++;
20902090
}
2091-
if (*tmp == enclosure) {
2091+
if (*tmp == enclosure && tmp < limit) {
20922092
bptr = tmp;
20932093
}
20942094
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
oss-fuzz #57392: Buffer-overflow in php_fgetcsv() with \0 delimiter and enclosure
3+
--FILE--
4+
<?php
5+
var_dump(str_getcsv(
6+
"aaaaaaaaaaaa\0 ",
7+
"\0",
8+
"\0",
9+
));
10+
?>
11+
--EXPECT--
12+
array(2) {
13+
[0]=>
14+
string(12) "aaaaaaaaaaaa"
15+
[1]=>
16+
string(2) " "
17+
}

0 commit comments

Comments
 (0)