Failed seek on php://memory and SQLite blob streams sets the stream position to -1
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Start by running the two PHP reproducers for php://memory and SQLite3 blob streams, then inspect php_stream_seek() in main/streams/streams.c and the stream implementations named in the report. Done means failed seeks preserve a usable position, ftell() returns the expected offset, subsequent SEEK_CUR operations work, and the debug assertion and release overflow no longer occur.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
When a seek fails on a php://memory stream, or on a blob stream from SQLite3::openBlob() or Pdo\Sqlite::openBlob(), the stream's position is set to -1. Meanwhile the stream's own read/write offset is moved: php://memory resets it to 0, and the blob streams clamp it to 0 or to the blob size.
After that:
- ftell() returns false, although the stream is still usable.
- Debug builds abort on the next fseek(..., SEEK_CUR) with Assertion 'stream->position >= 0' failed in php_stream_seek().
- Release builds hit a signed integer overflow in the SEEK_CUR overflow guard, where ZEND_LONG_MAX - stream->position is computed with position -1. The requested offset becomes PHP_INT_MAX:
- php://memory moves to PHP_INT_MAX and reads return "".
- The blob stream fails the seek again and stays at -1.
Plain files and php://temp behave correctly: a failed seek returns -1 and leaves the position unchanged.
Reproducer 1: php://memory
<?php
$stream = fopen('php://memory', 'r+');
fwrite($stream, 'hello world');
fseek($stream, 6);
var_dump(fseek($stream, -7, SEEK_CUR)); // fails: before start of stream
var_dump(ftell($stream));
var_dump(fseek($stream, 1, SEEK_CUR));
var_dump(ftell($stream));
var_dump(fread($stream, 4));
Actual output:
int(-1)
bool(false)
int(0)
int(9223372036854775807)
string(0) ""
Actual output (debug build):
int(-1)
bool(false)
php: main/streams/streams.c:1393: php_stream_seek: Assertion `stream->position >= 0' failed.
Aborted (core dumped)
Expected output:
int(-1)
int(6)
int(0)
int(7)
string(4) "orld"
Reproducer 2: SQLite3 blob (Pdo\Sqlite::openBlob() is affected the same way)
<?php
$db = new SQLite3(':memory:');
$db->exec('CREATE TABLE test (id INTEGER PRIMARY KEY, data BLOB)');
$db->exec("INSERT INTO test (id, data) VALUES (1, 'hello world')");
$stream = $db->openBlob('test', 'data', 1);
var_dump(fseek($stream, 12)); // fails: beyond end of blob
var_dump(ftell($stream));
var_dump(fseek($stream, 6, SEEK_CUR));
var_dump(ftell($stream));
var_dump(fread($stream, 5));
Actual output:
int(-1)
bool(false)
int(-1)
bool(false)
string(0) ""
(Debug builds abort with the same assertion as reproducer 1.)
Expected output:
int(-1)
int(0)
int(0)
int(6)
string(5) "world"
Related: #21433 #20964 #20927
PHP Version
PHP 8.4.27-dev (cli) (built: Sep 25 2026 10:06:46) (NTS)
PHP 8.5.12-dev (cli) (built: Sep 25 2026 10:12:00) (NTS)
PHP 8.6.0-dev (cli) (built: Sep 25 2026 10:17:03) (NTS)
Operating System
Ubuntu 24.04
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.2k
- Merge trung bình
- 3 ngày 10 phút
- Pull request đã merge (30 ngày)
- 142
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của php/php-src
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
php/php-src#23958 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Status: Needs Triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Flaky hrtime.phpt testĐang mởBug Category: Tests Status: Verified
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug SAPI: fpm Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
php/php-src#21740 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Add c++23 mapping to nvccĐang mởfeature request
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
FujiNetWIFI/fujinet-firmware#1730 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
[openssl] update to 3.6.5Đang mởcategory:port-update
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 2 ngày