Skip to content

Commit b1e0176

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
2 parents 58628e0 + e4473ab commit b1e0176

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: ext/spl/spl_directory.c

+6
Original file line numberDiff line numberDiff line change
@@ -2684,6 +2684,12 @@ PHP_METHOD(SplFileObject, ftruncate)
26842684

26852685
CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);
26862686

2687+
if (size < 0) {
2688+
zend_argument_value_error(1, "must be greater than or equal to 0");
2689+
RETURN_THROWS();
2690+
}
2691+
2692+
26872693
if (!php_stream_truncate_supported(intern->u.file.stream)) {
26882694
zend_throw_exception_ex(spl_ce_LogicException, 0, "Can't truncate file %s", ZSTR_VAL(intern->file_name));
26892695
RETURN_THROWS();

Diff for: ext/spl/tests/gh17463.phpt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-17463 segfault on SplFileObject::ftruncate() with negative value.
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 than or equal to 0

0 commit comments

Comments
 (0)