Skip to content

Commit 8509970

Browse files
committed
Fix signed integer overflow in SplObjectStorage unserialization
If count is ZEND_LONG_MIN the count-- loop underflows. This is ultimately harmless, but results in a ubsan warning. Fix this by adding a sanity check that the count isn't negative, because that doesn't make sense...
1 parent 697945a commit 8509970

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ext/spl/spl_observer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,9 @@ SPL_METHOD(SplObjectStorage, unserialize)
787787

788788
--p; /* for ';' */
789789
count = Z_LVAL_P(pcount);
790+
if (count < 0) {
791+
goto outexcept;
792+
}
790793

791794
ZVAL_UNDEF(&entry);
792795
ZVAL_UNDEF(&inf);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
OSS-Fuzz: Unserializing SplObjectStorage with negative number of elements
3+
--FILE--
4+
<?php
5+
6+
$str = 'C:16:"SplObjectStorage":25:{x:i:-9223372036854775808;}';
7+
try {
8+
var_dump(unserialize($str));
9+
} catch (Exception $e) {
10+
echo $e->getMessage(), "\n";
11+
}
12+
13+
?>
14+
--EXPECT--
15+
Error at offset 24 of 25 bytes

0 commit comments

Comments
 (0)