[php-src] PR #21433: Fix GH-20964, GH-20927: fseek() stream seek with PHP_INT_MIN causes undefined behavior
| From: | iliaal | Date: | Fri, 13 Mar 2026 21:55:46 +0000 |
| Subject: | [php-src] PR #21433: Fix GH-20964, GH-20927: fseek() stream seek with PHP_INT_MIN causes undefined behavior | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35195@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21433
Author: iliaal
## Summary
Stream seek functions in memory, pdo_sqlite, and sqlite3 compute the absolute value of a negative
offset using
(size_t)(-offset). When offset == ZEND_LONG_MIN, the signed
negation overflows -- undefined behavior caught by UBSAN.
The fix swaps the cast order: -(size_t)offset casts to unsigned first (well-defined),
then negates (well-defined unsigned arithmetic). Same result for all values, no behavioral change.
### Files changed
- main/streams/memory.c -- php://memory and php://temp stream seek
- ext/pdo_sqlite/pdo_sqlite.c -- PDO SQLite blob stream seek
- ext/sqlite3/sqlite3.c -- SQLite3 blob stream seek
### Existing PRs
- PR #20965 for GH-20964 uses the same cast-order fix but only covers memory streams
- PR #20928 for GH-20927 uses the same cast-order fix but only covers pdo_sqlite
This patch covers all three affected files.
Fixes #20964
Fixes #20927