Skip to content

Commit 8846e93

Browse files
committed
Merge branch 'PHP-8.4'
2 parents 02d58fa + dc93f28 commit 8846e93

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

ext/standard/tests/file/gh18212.phpt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-18212: fseek with SEEK_CUR and negative offset leads to negative file stream position.
3+
--FILE--
4+
<?php
5+
$fp = fopen('php://input', 'r+');
6+
var_dump(fseek($fp, -1, SEEK_SET));
7+
var_dump(fseek($fp, -32, SEEK_CUR));
8+
fclose($fp);
9+
?>
10+
--EXPECT--
11+
int(-1)
12+
int(-1)
13+

ext/standard/tests/file/stream_rfc2397_007.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int(2)
118118
bool(false)
119119
===S:-10,C===
120120
int(-1)
121-
bool(false)
121+
int(2)
122122
bool(false)
123123
===S:3,S===
124124
int(0)

main/streams/streams.c

+4
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,10 @@ PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence)
13901390
}
13911391
whence = SEEK_SET;
13921392
break;
1393+
case SEEK_SET:
1394+
if (offset < 0) {
1395+
return -1;
1396+
}
13931397
}
13941398
ret = stream->ops->seek(stream, offset, whence, &stream->position);
13951399

0 commit comments

Comments
 (0)