If Zip file has normal file header AND a post-descriptor header AND the file is attempted to be skipped by a ZipReader, then the data is attempted to be skipped twice. #207

Open
opened 2026-01-29 22:08:22 +00:00 by claunia · 0 comments
Owner

Originally created by @KvanTTT on GitHub (Jul 7, 2017).

Originally assigned to: @adamhathcock on GitHub.

I have the following BadStateArchive.zip.

I want to ignore files that start with the dot: .DS_Store. But if I just ignore such file I get the exception
Bad state (invalid stored block lengths) in reader.MoveToNextEntry() method. I use the following code for reading:

using (Stream stream = File.OpenRead(sourceArchiveFileName))
{
    using (IReader reader = ReaderFactory.Open(stream))
    {  
        while (reader.MoveToNextEntry())
        {
           ...
        }
    }
}

If such files writing to DummyStream exception does not occur:

using (var dummyStream = new DummyStream())
{
    reader.WriteEntryTo(dummyStream);
}

where DummyStream is

public class DummyStream : Stream
{
    public override bool CanRead => true;

    public override bool CanSeek => true;

    public override bool CanWrite => true;

    public override long Length => 0;

    public override long Position { get; set; } = 0;

    public override void Flush()
    {
    }

    public override int Read(byte[] buffer, int offset, int count)
    {
        return 0;
    }

    public override long Seek(long offset, SeekOrigin origin)
    {
        return 0;
    }

    public override void SetLength(long value)
    {
    }

    public override void Write(byte[] buffer, int offset, int count)
    {
    }
}

Originally created by @KvanTTT on GitHub (Jul 7, 2017). Originally assigned to: @adamhathcock on GitHub. I have the following [BadStateArchive.zip](https://github.com/adamhathcock/sharpcompress/files/1130352/BadStateArchive.zip). I want to ignore files that start with the dot: `.DS_Store`. But if I just ignore such file I get the exception `Bad state (invalid stored block lengths)` in `reader.MoveToNextEntry()` method. I use the following code for reading: ```CSharp using (Stream stream = File.OpenRead(sourceArchiveFileName)) { using (IReader reader = ReaderFactory.Open(stream)) { while (reader.MoveToNextEntry()) { ... } } } ``` If such files writing to `DummyStream` exception does not occur: ```CSharp using (var dummyStream = new DummyStream()) { reader.WriteEntryTo(dummyStream); } ``` where `DummyStream` is ```CSharp public class DummyStream : Stream { public override bool CanRead => true; public override bool CanSeek => true; public override bool CanWrite => true; public override long Length => 0; public override long Position { get; set; } = 0; public override void Flush() { } public override int Read(byte[] buffer, int offset, int count) { return 0; } public override long Seek(long offset, SeekOrigin origin) { return 0; } public override void SetLength(long value) { } public override void Write(byte[] buffer, int offset, int count) { } } ```
claunia added the bug label 2026-01-29 22:08:22 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#207