Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

ZipArchive.TestArchive swallows important environmental exceptions

Abierto
#724 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
csharp
Área
backend

Línea de trabajo

Empieza en ZipFile.TestArchive e inspecciona cómo se gestionan las excepciones de la verificación del archivo. Reproduce el comportamiento con el proyecto de .NET Framework 4.8 proporcionado bajo presión de memoria; se considera terminado cuando una OutOfMemoryException se propaga en lugar de convertirse en un resultado false.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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;
        }
    }
}
Lenguaje dominante
C#
Estrellas
3.9k
Forks
1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de icsharpcode/SharpZipLib

Todos los issues de icsharpcode/SharpZipLib

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.