Commit 225fa9e
committed
Fix GH-21700: assertion failure in _php_stream_seek with user stream returning negative position
When a user stream's stream_tell() returns a negative offset after a
stream_seek() reported success, _php_stream_seek would store that value
into stream->position and then trip ZEND_ASSERT(stream->position >= 0)
on the next SEEK_CUR.
Three changes:
- After the SEEK_CUR -> SEEK_SET conversion, fall through to the
existing 'offset < 0' rejection so a SEEK_CUR whose absolute target
would be negative is refused before invoking the user seek hook.
- After stream->ops->seek returns success, validate stream->position is
non-negative. If a user stream lied (e.g. stream_tell() returns -42),
restore the prior position and return -1, matching POSIX fseek()'s
contract that the file-position indicator is unchanged on failure.
- In php_stream_open_wrapper_ex's append-mode position fixup, ignore a
negative newpos returned by stream->ops->seek (defense in depth for
the only other direct caller of the seek hook in this layer).
Includes phpt regression tests covering both _php_stream_seek paths and
the append-mode open path.1 parent 1462499 commit 225fa9e
4 files changed
Lines changed: 94 additions & 5 deletions
File tree
- ext/standard/tests/streams
- main/streams
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
| 199 | + | |
198 | 200 | | |
199 | 201 | | |
200 | 202 | | |
| |||
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1466 | 1466 | | |
1467 | 1467 | | |
1468 | 1468 | | |
1469 | | - | |
1470 | | - | |
| 1469 | + | |
| 1470 | + | |
1471 | 1471 | | |
1472 | 1472 | | |
1473 | 1473 | | |
1474 | 1474 | | |
| 1475 | + | |
1475 | 1476 | | |
| 1477 | + | |
1476 | 1478 | | |
1477 | 1479 | | |
1478 | 1480 | | |
1479 | 1481 | | |
1480 | | - | |
1481 | | - | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
1482 | 1494 | | |
1483 | 1495 | | |
1484 | 1496 | | |
| |||
2392 | 2404 | | |
2393 | 2405 | | |
2394 | 2406 | | |
2395 | | - | |
| 2407 | + | |
2396 | 2408 | | |
2397 | 2409 | | |
2398 | 2410 | | |
| |||
0 commit comments