Skip to content

Commit 4c8ca72

Browse files
committed
Fix GH-17463: SplTempFileObject::ftruncate() segfault on negative length.
1 parent a6a290d commit 4c8ca72

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ext/spl/spl_directory.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,6 +2706,11 @@ PHP_METHOD(SplFileObject, ftruncate)
27062706
RETURN_THROWS();
27072707
}
27082708

2709+
if (size < 0) {
2710+
zend_argument_value_error(1, "must be greater or equal to 0");
2711+
RETURN_THROWS();
2712+
}
2713+
27092714
CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);
27102715

27112716
if (!php_stream_truncate_supported(intern->u.file.stream)) {

ext/spl/tests/gh17463.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-15918 (Assertion failure in ext/spl/spl_fixedarray.c)
3+
--CREDITS--
4+
YuanchengJiang
5+
--FILE--
6+
<?php
7+
$cls = new SplTempFileObject();
8+
9+
try {
10+
$cls->ftruncate(-1);
11+
} catch (\ValueError $e) {
12+
echo $e->getMessage();
13+
}
14+
?>
15+
--EXPECT--
16+
SplFileObject::ftruncate(): Argument #1 ($size) must be greater or equal to 0

0 commit comments

Comments
 (0)