TestArchive doesn't handle invalid offsets correctly
还没有人认领这个 Issue。
评估
调研方向
从 src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs 中 TestArchive 循环附近以及 issue 所引用的 entry.Offset 处理开始。跟踪无效偏移量如何到达 System.IO,然后添加回归测试覆盖,表明 TestArchive 会报告无效条目,并在 TestStrategy.FindAllErrors 下继续测试其他条目。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- C#
- 星标
- 3.9k
- 派生
- 1k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
icsharpcode/SharpZipLib 的其他 Issue
-
*no response* bug
难度 1/5 1 小时以内 新手友好度 78/100
icsharpcode/SharpZipLib#905 · 1 条评论 ·
-
bug bzip2
难度 4/5 3-5 天 新手友好度 45/100
icsharpcode/SharpZipLib#904 ·
-
enhancement zip
难度 2/5 1-2 天 新手友好度 55/100
icsharpcode/SharpZipLib#903 ·
-
*no response* bug
难度 4/5 3-5 天 新手友好度 32/100
icsharpcode/SharpZipLib#901 · 1 条评论 ·
-
*no response* bug
难度 4/5 3-5 天 新手友好度 35/100
icsharpcode/SharpZipLib#894 · 1 条评论 ·
查看 icsharpcode/SharpZipLib 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
nightscout/nocturne#1425 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
RayWangQvQ/BiliBiliToolPro#1137 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 70/100