Merge branch 'PHP-8.4'

This commit is contained in:
David Carlier 2025-01-14 18:33:00 +00:00
commit a4e25839d3
No known key found for this signature in database
GPG key ID: 2FB76A8CE6CD2B41
2 changed files with 22 additions and 0 deletions

View file

@ -2686,6 +2686,12 @@ PHP_METHOD(SplFileObject, ftruncate)
CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);
if (size < 0) {
zend_argument_value_error(1, "must be greater than or equal to 0");
RETURN_THROWS();
}
if (!php_stream_truncate_supported(intern->u.file.stream)) {
zend_throw_exception_ex(spl_ce_LogicException, 0, "Can't truncate file %s", ZSTR_VAL(intern->file_name));
RETURN_THROWS();

View file

@ -0,0 +1,16 @@
--TEST--
GH-17463 segfault on SplFileObject::ftruncate() with negative value.
--CREDITS--
YuanchengJiang
--FILE--
<?php
$cls = new SplTempFileObject();
try {
$cls->ftruncate(-1);
} catch (\ValueError $e) {
echo $e->getMessage();
}
?>
--EXPECT--
SplFileObject::ftruncate(): Argument #1 ($size) must be greater than or equal to 0