Skip to content

Enumerating ZipArchive.Entries collection throws NullReferenceException #431

Open

Description

@Metalnem

The following program throws NullReferenceException (assuming that the args[0] contains the path to the attached archive):

using System.Linq;
using SharpCompress.Archives.Zip;

namespace SharpCompress.Run
{
  public class Program
  {
    public static void Main(string[] args)
    {
      using (var zip = ZipArchive.Open(args[0]))
      {
        zip.Entries.ToList();
      }
    }
  }
}

The stack trace looks like this:

An unhandled exception of type 'System.NullReferenceException' occurred in SharpCompress.dll: 'Object reference not set to an instance of an object.'
   at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader(UInt32 headerBytes, BinaryReader reader, Boolean zip64)
   at SharpCompress.Common.Zip.SeekableZipHeaderFactory.<ReadSeekableHeader>d__3.MoveNext()
   at SharpCompress.Archives.Zip.ZipArchive.<LoadEntries>d__16.MoveNext()
   at SharpCompress.LazyReadOnlyCollection`1.LazyLoader.MoveNext()
   at SharpCompress.Utility.ForEach[T](IEnumerable`1 items, Action`1 action)
   at SharpCompress.LazyReadOnlyCollection`1.EnsureFullyLoaded()
   at SharpCompress.LazyReadOnlyCollection`1.get_Count()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at SharpCompress.Run.Program.Main(String[] args) in

Found via SharpFuzz.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions