New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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. #269

Closed
KvanTTT opened this Issue Jul 7, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@KvanTTT

KvanTTT commented Jul 7, 2017

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)
    {
    }
}
@adamhathcock

This comment has been minimized.

Show comment
Hide comment
@adamhathcock

adamhathcock Jul 7, 2017

Owner

It's probably because you're returning 0 on Read which means the stream is empty. I don't think decompression likes trying to operation on a zero byte stream.

Owner

adamhathcock commented Jul 7, 2017

It's probably because you're returning 0 on Read which means the stream is empty. I don't think decompression likes trying to operation on a zero byte stream.

@KvanTTT

This comment has been minimized.

Show comment
Hide comment
@KvanTTT

KvanTTT Jul 8, 2017

But I should not use WriteEntryTo method for getting rid of exception.

KvanTTT commented Jul 8, 2017

But I should not use WriteEntryTo method for getting rid of exception.

@adamhathcock

This comment has been minimized.

Show comment
Hide comment
@adamhathcock

adamhathcock Jul 8, 2017

Owner

I don’t know offhand but I may just have a try/catch that’s hiding that exception in that extension.

Owner

adamhathcock commented Jul 8, 2017

I don’t know offhand but I may just have a try/catch that’s hiding that exception in that extension.

@KvanTTT

This comment has been minimized.

Show comment
Hide comment
@KvanTTT

KvanTTT Jul 8, 2017

I tried to wrap a reader.MoveToNextEntry() to try/catch block. But in this case, not all files being processed. Although they should.

KvanTTT commented Jul 8, 2017

I tried to wrap a reader.MoveToNextEntry() to try/catch block. But in this case, not all files being processed. Although they should.

@adamhathcock

This comment has been minimized.

Show comment
Hide comment
@adamhathcock

adamhathcock Jul 8, 2017

Owner

Sorry. I finally understand what you're trying to: just skip a .DS_Store file but it isn't working. I've reproduced it.

The dummy stream stuff you mentioned doesn't have anything to do with it.

Owner

adamhathcock commented Jul 8, 2017

Sorry. I finally understand what you're trying to: just skip a .DS_Store file but it isn't working. I've reproduced it.

The dummy stream stuff you mentioned doesn't have anything to do with it.

@adamhathcock adamhathcock changed the title from "Bad state (invalid stored block lengths)" exception if reader entity not writing to somewhere to 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. Jul 8, 2017

@adamhathcock adamhathcock self-assigned this Jul 8, 2017

@adamhathcock adamhathcock added the bug label Jul 8, 2017

@adamhathcock adamhathcock added this to the 0.18 milestone Jul 10, 2017

@adamhathcock adamhathcock closed this in #272 Jul 17, 2017

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