Skip to content

Commit c701508

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-15980: Signed integer overflow in main/streams/streams.c
2 parents 5bcbe8a + 6a04c79 commit c701508

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ PHP NEWS
2323
- Streams:
2424
. Fixed bugs GH-15908 and GH-15026 (leak / assertion failure in streams.c).
2525
(nielsdos)
26+
. Fixed bug GH-15980 (Signed integer overflow in main/streams/streams.c).
27+
(cmb)
2628

2729
- TSRM:
2830
. Prevent closing of unrelated handles. (cmb)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
GH-15980 (Signed integer overflow in main/streams/streams.c)
3+
--FILE--
4+
<?php
5+
$s = fopen(__FILE__, "r");
6+
fseek($s, 1);
7+
fseek($s, PHP_INT_MAX, SEEK_CUR);
8+
var_dump(ftell($s) > 1);
9+
?>
10+
--EXPECT--
11+
bool(true)

main/streams/streams.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,13 @@ PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence)
13821382

13831383
switch(whence) {
13841384
case SEEK_CUR:
1385-
offset = stream->position + offset;
1386-
whence = SEEK_SET;
1385+
ZEND_ASSERT(stream->position >= 0);
1386+
if (UNEXPECTED(offset > ZEND_LONG_MAX - stream->position)) {
1387+
offset = ZEND_LONG_MAX;
1388+
} else {
1389+
offset = stream->position + offset;
1390+
}
1391+
whence = SEEK_SET;
13871392
break;
13881393
}
13891394
ret = stream->ops->seek(stream, offset, whence, &stream->position);

0 commit comments

Comments
 (0)