Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ PHP NEWS
IntlCalendar::equals(), ::before(), ::after(), and ::isEquivalentTo().
(Weilin Du)

- Streams:
. Fixed bug GH-20921 (UBSan: Negation of PHP_INT_MIN triggers runtime error
in streams/memory.c via SplTempFileObject::fseek). (wadakatu)

- Zlib:
. Fixed memory leak if deflate initialization fails and there is a dict.
(ndossche)
Expand Down
12 changes: 12 additions & 0 deletions ext/standard/tests/streams/gh20921.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
GH-20921: SplTempFileObject::fseek with PHP_INT_MIN must not trigger UB
--FILE--
<?php
$f = new SplTempFileObject();
$f->fwrite("abcdef");

var_dump($f->fseek(PHP_INT_MIN, SEEK_END));

?>
--EXPECT--
int(-1)
2 changes: 1 addition & 1 deletion main/streams/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whe
stream->eof = 0;
stream->fatal_error = 0;
return 0;
} else if (ZSTR_LEN(ms->data) < (size_t)(-offset)) {
} else if (ZSTR_LEN(ms->data) < -(size_t)offset) {
ms->fpos = 0;
*newoffs = -1;
return -1;
Expand Down
Loading