bzip2.decompress write filter writes past its input buffer after a data error
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ó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Đọc ext/bz2/bz2_filter.c, đặc biệt là php_bz2_decompress_filter quanh thao tác sao chép đầu vào và lệnh trả về khi có lỗi dữ liệu; so sánh hành vi đặt lại của nó với zlib.inflate, vốn theo issue đã nhận cùng bản sửa lỗi. Tái hiện lỗi bằng ví dụ .bz2 bị hỏng được cung cấp trên bản dựng ASan, sau đó xác minh rằng các lần ghi tiếp theo báo thông báo giải nén mà không ghi vượt giới hạn bộ nhớ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
After a data error, a bzip2.decompress write filter can copy later writes past the end of its 2048-byte input buffer. Copying a .bz2 with a corrupted byte near the start in a loop that doesn't check what fwrite() returns is enough:
<?php
$data = '';
for ($i = 0; $i < 20000; $i++) {
$data .= "line $i " . md5($i) . "\n";
}
$bz = bzcompress($data);
$bz[100] = 'x';
$in = fopen('php://memory', 'w+');
fwrite($in, $bz);
rewind($in);
$out = fopen('php://memory', 'w+');
stream_filter_append($out, 'bzip2.decompress', STREAM_FILTER_WRITE);
while (!feof($in)) {
fwrite($out, fread($in, 8192));
}
echo "Done\n";
On an ASan build with USE_ZEND_ALLOC=0.
Resulted in this output:
Notice: fwrite(): bzip2 decompression failed in %s on line 16
ERROR: AddressSanitizer: heap-buffer-overflow
WRITE of size 2048
#0 memcpy
#1 php_bz2_decompress_filter ext/bz2/bz2_filter.c:117
#2 _php_stream_write_filtered main/streams/streams.c:1292
#3 _php_stream_write main/streams/streams.c:1381
#4 zif_fwrite ext/standard/file.c:1035
But I expected this output instead:
Notice: fwrite(): bzip2 decompression failed in %s on line 16
(the same notice for each later fwrite() call)
Done
On a data error the filter returns before it resets its input position. bzlib has already moved that position forward, and the next write copies its input there. Without ASan and with the Zend allocator it doesn't crash, it silently overwrites the heap after the buffer. zlib.inflate had the same bug and got the same reset in 2010 (https://bugs.php.net/52944).
I'm opening a PR that resets the position the way zlib.inflate does.
PHP Version
PHP 8.4.29-dev (PHP-8.4). The same code is in 8.5, 8.6 and master.
Operating System
Ubuntu 26.04, libbz2 1.0.8
- Ngôn ngữ chính
- C
- Star
- 41.9k
- Fork
- 8.5k
- Merge trung bình
- 2 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 106
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
-
Bug Status: Needs Triage
Độ 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 1 ngày
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/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
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)Đang mởExtension: openssl Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
php/php-src#25402 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Life-Framework/Life-Framework#5378 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug status: planned ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
ChupathingyCE/chupathingyce#2126 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue simulation
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 92/100
MarcosAsh/Lattice_Fluid_Dynamics#270 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-kind
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
falcosecurity/libs#3173 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Installation fails from source: missing libintl.h on macOS, undeclared R_typeToChar() on R 4.6Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
vincentarelbundock/xtx#11 ·