Skip to content

Commit cb52378

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: streams: _php_stream_seek() assertion triggered on negative offset.
2 parents 072c36c + 497318f commit cb52378

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-21700 (_php_stream_seek assertion on SEEK_CUR with resolved negative offset)
3+
--CREDITS--
4+
YuanchengJiang
5+
--FILE--
6+
<?php
7+
class wrapper {
8+
public int $pos = 0;
9+
public $context;
10+
function stream_open($path, $mode, $options, &$opened_path): bool { return true; }
11+
function stream_seek($offset, $whence): bool { $this->pos = $offset; return true; }
12+
function stream_tell(): int { return $this->pos; }
13+
}
14+
stream_wrapper_register("gh21700", "wrapper");
15+
$fp = fopen("gh21700://", "rb");
16+
var_dump(fseek($fp, -1, SEEK_CUR));
17+
var_dump(fseek($fp, 0, SEEK_CUR));
18+
fclose($fp);
19+
?>
20+
--EXPECT--
21+
int(-1)
22+
int(0)

‎main/streams/streams.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,8 @@ PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence)
14701470
offset = stream->position + offset;
14711471
}
14721472
whence = SEEK_SET;
1473-
break;
1473+
/* fall through to reject a possible negative offset */
1474+
ZEND_FALLTHROUGH;
14741475
case SEEK_SET:
14751476
if (offset < 0) {
14761477
return -1;

0 commit comments

Comments
 (0)