[php-src] PR #21914: Fix GH-21700: undefined behavior in _php_stream_seek with user stream returning negative position
| From: | lacatoire | Date: | Thu, 30 Apr 2026 09:52:36 +0000 |
| Subject: | [php-src] PR #21914: Fix GH-21700: undefined behavior in _php_stream_seek with user stream returning negative position | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35953@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21914
Author: lacatoire
Fixes GH-21700.
When a user stream's
stream_tell() returns a negative offset after a
stream_seek() reported success, _php_stream_seek would store that value
into stream->position and then trip ZEND_ASSERT(stream->position >=
0) on the next SEEK_CUR (or any subsequent SEEK_CUR-based op).
Two changes:
- After the SEEK_CUR → SEEK_SET conversion, fall through to the existing offset <
0 rejection so a SEEK_CUR whose absolute target is negative is refused before invoking the
user seek hook.
- After stream->ops->seek returns success, validate
stream->position is non-negative. If a user stream lied (e.g.
stream_tell() returns -42), restore the prior position and return -1, matching POSIX
fseek()'s contract that the file-position indicator is unchanged on failure.
Includes a regression phpt covering both paths.