1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-12151: str_getcsv ending with escape zero segfualt

Closes GH-12152
This commit is contained in:
Jakub Zelenka
2023-09-07 16:10:14 +01:00
parent 5ed58386d1
commit 64ebadcac5
3 changed files with 24 additions and 0 deletions

4
NEWS
View File

@@ -32,6 +32,10 @@ PHP NEWS
. Fixed bug GH-11972 (RecursiveCallbackFilterIterator regression in 8.1.18).
(nielsdos)
- Standard:
. Fixed bug GH-12151 (str_getcsv ending with escape zero segfualt).
(Jakub Zelenka)
31 Aug 2023, PHP 8.3.0RC1
- Core:

View File

@@ -2023,6 +2023,9 @@ PHPAPI HashTable *php_fgetcsv(php_stream *stream, char delimiter, char enclosure
if (bptr > limit) {
/* if the line ends with enclosure, we need to go back by
* one character so the \0 character is not copied. */
if (hunk_begin == bptr) {
--hunk_begin;
}
--bptr;
}
goto quit_loop_2;
@@ -2038,6 +2041,9 @@ PHPAPI HashTable *php_fgetcsv(php_stream *stream, char delimiter, char enclosure
if (bptr > limit) {
/* if the line ends with enclosure, we need to go back by
* one character so the \0 character is not copied. */
if (hunk_begin == bptr) {
--hunk_begin;
}
--bptr;
}
goto quit_loop_2;

View File

@@ -0,0 +1,14 @@
--TEST--
GH-12151 (str_getcsv ending with escape zero segfualt)
--FILE--
<?php
var_export(str_getcsv("y","","y","\000"));
var_export(str_getcsv("\0yy","y","y","\0"));
?>
--EXPECT--
array (
0 => '' . "\0" . '',
)array (
0 => '' . "\0" . '',
1 => '' . "\0" . '',
)