TestArchive doesn't handle invalid offsets correctly
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Bắt đầu trong src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs, xung quanh vòng lặp TestArchive và phần xử lý entry.Offset được đề cập trong issue. Theo dõi cách các offset không hợp lệ đến được System.IO, sau đó thêm kiểm thử hồi quy cho thấy TestArchive báo cáo entry không hợp lệ và tiếp tục kiểm thử các entry bổ sung trong TestStrategy.FindAllErrors.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
Entry header offsets are not checked for validity before trying to seek to them in the stream. Invalid offsets (i.e. <0) cause InvalidArgumentExceptions to be thrown from inside System.IO code, which are not caught in the existing ZipException handlers. They bubble up and cause the entire archive to fail validation with a cryptic "The parameter is incorrect - {filename}" message.
Reproduction Code
using ICSharpCode.SharpZipLib.Zip;
namespace TestArchive
{
internal class Program
{
static void Main(string[] args)
{
string zipPath = @"C:\temp\test.zip";
using var stream = System.IO.File.OpenRead(zipPath);
using var zip = new ZipFile(stream);
bool isValid = zip.TestArchive(false, TestStrategy.FindAllErrors, ZipTestResultHandler);
if (!isValid)
{
throw new ArgumentException("Zip file is invalid!");
}
}
static void ZipTestResultHandler(TestStatus status, string message)
{
if (status.Entry != null && !status.EntryValid && !string.IsNullOrEmpty(message))
{
Console.WriteLine(status.Entry.ZipFileIndex + ": " + status.Entry.Name);
Console.WriteLine(message);
}
}
}
}
Steps to reproduce
- Get a zip file with an entry whose Offset is negative (this is generally an invalid state and I don't know how to create one like this)
- Call TestArchive() and pass in a ZipTestResultHandler to get the test results
Expected behavior
I expect each individual entry with an invalid offset/header to be reported on (assuming TestStrategy.FindAllErrors is specified)
Operating System
Windows
Framework Version
Other
Tags
ZIP
Additional context
entry.Offset not being checked for > 0: https://github.com/icsharpcode/SharpZipLib/blob/master/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs#L1184
Where the InvalidArgumentException from deep in System.IO gets caught outside the while loop (additional entries are not tested): https://github.com/icsharpcode/SharpZipLib/blob/master/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs#L1144
- Ngôn ngữ chính
- C#
- Star
- 3.9k
- Fork
- 1k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
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 icsharpcode/SharpZipLib
-
*no response* bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
icsharpcode/SharpZipLib#905 · 1 bình luận ·
-
bug bzip2
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
icsharpcode/SharpZipLib#904 ·
-
SetLevel in ZipFile Đang mởenhancement zip
Độ khó 2/5 1-2 ngày Mức phù hợp với người mới 55/100
icsharpcode/SharpZipLib#903 ·
-
*no response* bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 32/100
icsharpcode/SharpZipLib#901 · 1 bình luận ·
-
*no response* bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
icsharpcode/SharpZipLib#894 · 1 bình luận ·
Tất cả issue của icsharpcode/SharpZipLib
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
nightscout/nocturne#1425 ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
cake-build/cake#5024 ·
-
Gå gjennom ESLint-suppressions Đang mởFrontend status/draft TechnicalDebt
Độ khó 2/5 1-2 ngày Mức phù hợp với người mới 75/100
Altinn/altinn-auth#4143 ·