Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ext/standard/tests/streams/gh21700.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GH-21700 (_php_stream_seek assertion on SEEK_CUR with resolved negative offset)
--CREDITS--
YuanchengJiang
--FILE--
<?php
class wrapper {
public int $pos = 0;
public $context;
function stream_open($path, $mode, $options, &$opened_path): bool { return true; }
function stream_seek($offset, $whence): bool { $this->pos = $offset; return true; }
function stream_tell(): int { return $this->pos; }
}
stream_wrapper_register("gh21700", "wrapper");
$fp = fopen("gh21700://", "rb");
var_dump(fseek($fp, -1, SEEK_CUR));
var_dump(fseek($fp, 0, SEEK_CUR));
fclose($fp);
?>
--EXPECT--
int(-1)
int(0)
3 changes: 2 additions & 1 deletion main/streams/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,8 @@ PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence)
offset = stream->position + offset;
}
whence = SEEK_SET;
break;
/* fall through to reject a possible negative offset */
ZEND_FALLTHROUGH;
case SEEK_SET:
if (offset < 0) {
return -1;
Expand Down
Loading