mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix GH-17463: SplTempFileObject::ftruncate() segfault on negative length.
close GH-465
This commit is contained in:
parent
a6a290d541
commit
e4473abefc
3 changed files with 26 additions and 0 deletions
4
NEWS
4
NEWS
|
@ -40,6 +40,10 @@ PHP NEWS
|
|||
. Fixed bug GH-17330 (SNMP::setSecurity segfault on closed session).
|
||||
(David Carlier)
|
||||
|
||||
- SPL:
|
||||
. Fixed bug GH-17463 (crash on SplTempFileObject::ftruncate with negative
|
||||
value). (David Carlier)
|
||||
|
||||
- Zip:
|
||||
. Fixed bug GH-17139 (Fix zip_entry_name() crash on invalid entry).
|
||||
(nielsdos)
|
||||
|
|
|
@ -2708,6 +2708,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();
|
||||
|
|
16
ext/spl/tests/gh17463.phpt
Normal file
16
ext/spl/tests/gh17463.phpt
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue