Files
Ilia Alshanetsky 5ce795bec1 Fix GH-20964: fseek() on php://memory with PHP_INT_MIN causes undefined behavior (#21433)
Negate after casting to unsigned instead of before, avoiding signed
integer overflow when offset is ZEND_LONG_MIN. The same pattern existed
in the pdo_sqlite and sqlite3 stream seek handlers.

Closes GH-20964
Closes GH-20927
2026-06-20 19:01:46 -04:00

23 lines
425 B
PHP

--TEST--
GH-20964 (fseek() on php://memory with PHP_INT_MIN causes undefined behavior)
--FILE--
<?php
$stream = fopen('php://memory', 'r+');
fwrite($stream, 'hello');
rewind($stream);
var_dump(fseek($stream, PHP_INT_MIN, SEEK_END));
var_dump(ftell($stream));
rewind($stream);
var_dump(fseek($stream, PHP_INT_MIN, SEEK_CUR));
var_dump(ftell($stream));
fclose($stream);
?>
--EXPECT--
int(-1)
bool(false)
int(-1)
bool(false)