Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

ZipArchive.TestArchive swallows important environmental exceptions

Đang mở
#724 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu từ ZipFile.TestArchive và kiểm tra cách các ngoại lệ phát sinh từ việc xác minh kho lưu trữ được xử lý. Tái hiện hành vi bằng dự án .NET Framework 4.8 được cung cấp trong điều kiện áp lực bộ nhớ; hoàn thành khi một OutOfMemoryException được truyền lên thay vì bị chuyển thành kết quả false.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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;
        }
    }
}
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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của icsharpcode/SharpZipLib

Tất cả issue của icsharpcode/SharpZipLib

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.