ZipArchive.TestArchive swallows important environmental exceptions
还没有人认领这个 Issue。
评估
调研方向
从 ZipFile.TestArchive 开始,检查如何处理存档验证引发的异常。使用提供的 .NET Framework 4.8 项目在内存压力下重现该行为;当 OutOfMemoryException 得以传播,而不是被转换为 false 结果时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Steps to reproduce
Call ZipFile.TestArchive when the application is under severe memory pressure.
Expected behavior
An OutOfMemoryException is thrown by the runtime and leaks out of SharpZipLib.
Actual behavior
SharpZipLib swallows the OutOfMemoryException and TestArchive returns false, leading people to believe that there is a problem with the ZIP file, rather than the runtime.
Version of SharpZipLib
v1.3.3.
Obtained from (only keep the relevant lines)
Package installed using NuGet
Repro case:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net48</TargetFramework>
<RootNamespace>TestZipFile</RootNamespace>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
<Platform>x86</Platform>
<PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib" Version="1.3.3" />
</ItemGroup>
</Project>
using ICSharpCode.SharpZipLib.Zip;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace TestZipFile
{
public static class Program
{
public static int Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine($"Usage: test-zip.exe <path to zip file>");
return -1;
}
Console.WriteLine($"Process architecture: {RuntimeInformation.ProcessArchitecture}");
using var fs = File.OpenRead(args[0]);
using var zip = new ZipFile(fs);
var list = new List<byte[]>(capacity: 20);
var increment = 1_000_000_000;
Console.WriteLine("Reserving memory...");
while (true)
{
try
{
var data = new byte[increment];
list.Add(data);
}
catch (OutOfMemoryException)
{
if (increment > 10_000)
{
increment = increment / 10;
}
else
{
break;
}
}
}
Console.WriteLine($"Reserved {list.Sum(static x => x.Length)} bytes.");
AppDomain.CurrentDomain.FirstChanceException += (sender, e) =>
{
if (e.Exception is OutOfMemoryException)
{
list.Clear();
GC.Collect();
}
};
Console.WriteLine($"Verifying zip...");
Console.WriteLine("---");
Console.WriteLine();
var result = zip.TestArchive(testData: true, TestStrategy.FindAllErrors, static (status, message) => { });
GC.KeepAlive(list);
Console.WriteLine("---");
Console.WriteLine($"Result: {(result ? "PASS" : "FAIL")}");
return result ? 0 : -2;
}
}
}
- 主要语言
- 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
难度 1/5 1 小时以内 新手友好度 90/100
-
Type: enhancement
难度 2/5 1-3 小时 新手友好度 65/100
apache/arrow-adbc#4809 ·
-
type/automation type/tech-debt
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 65/100
microsoft/vscode-azurefunctions#5197 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 85/100
microsoft/microsoft-ui-reactor#1274 ·