Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions ext/spl/tests/gh17463.phpt
Original file line number Diff line number Diff line change
@@ -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