When using ZipReader to read a streamed zip file, MoveToNextEntry skipping doesn't work properly #531

Closed
opened 2026-01-29 22:13:23 +00:00 by claunia · 4 comments
Owner

Originally created by @AlexVallat on GitHub (Jul 19, 2022).

If using ZipReader to read a streamed zip file (using PostDataDescriptor) then using MoveToNextEntry to skip an entry does not work properly. I think this is because AbstractReader.Skip always sets filePart.Skipped = true c73a8cb18f/src/SharpCompress/Readers/AbstractReader.cs (L135) even if the entry size is not known and so it has to decompress to skip.

Minimal repro:
test.zip

using (var fileStream = File.OpenRead("test.zip"))
using (var reader = SharpCompress.Readers.Zip.ZipReader.Open(fileStream))
{
    while (reader.MoveToNextEntry())
    {
        Console.WriteLine(reader.Entry.Key);
        // reader.OpenEntryStream().Dispose(); // Uncomment for workaround
    }
}

When run, after the first entry, the next MoveToNextEntry returns false even though there are further entries.
If you uncomment the reader.OpenEntryStream().Dispose(); line then this has the same effect of skipping the entry, but without setting filePart.Skipped true, and all the entries are listed.

Originally created by @AlexVallat on GitHub (Jul 19, 2022). If using ZipReader to read a streamed zip file (using PostDataDescriptor) then using MoveToNextEntry to skip an entry does not work properly. I think this is because AbstractReader.Skip always sets `filePart.Skipped = true` https://github.com/adamhathcock/sharpcompress/blob/c73a8cb18fa2bffdec01bed3fea397e3bae25acf/src/SharpCompress/Readers/AbstractReader.cs#L135 even if the entry size is not known and so it has to decompress to skip. Minimal repro: [test.zip](https://github.com/adamhathcock/sharpcompress/files/9139065/test.zip) ```csharp using (var fileStream = File.OpenRead("test.zip")) using (var reader = SharpCompress.Readers.Zip.ZipReader.Open(fileStream)) { while (reader.MoveToNextEntry()) { Console.WriteLine(reader.Entry.Key); // reader.OpenEntryStream().Dispose(); // Uncomment for workaround } } ``` When run, after the first entry, the next MoveToNextEntry returns false even though there are further entries. If you uncomment the `reader.OpenEntryStream().Dispose();` line then this has the same effect of skipping the entry, but without setting filePart.Skipped true, and all the entries are listed.
Author
Owner

@AlexVallat commented on GitHub (Jul 19, 2022):

Note, this is a regression from 0.32.0 to 0.32.1. Probably due to https://github.com/adamhathcock/sharpcompress/pull/672 ?

@AlexVallat commented on GitHub (Jul 19, 2022): Note, this is a regression from 0.32.0 to 0.32.1. Probably due to https://github.com/adamhathcock/sharpcompress/pull/672 ?
Author
Owner

@adamhathcock commented on GitHub (Jul 26, 2022):

You're right that PR broke this. Might have to revert.

Discussion here: https://github.com/adamhathcock/sharpcompress/issues/477

@adamhathcock commented on GitHub (Jul 26, 2022): You're right that PR broke this. Might have to revert. Discussion here: https://github.com/adamhathcock/sharpcompress/issues/477
Author
Owner

@Erior commented on GitHub (Aug 4, 2022):

I think this should be closed

@Erior commented on GitHub (Aug 4, 2022): I think this should be closed
Author
Owner

@adamhathcock commented on GitHub (Aug 5, 2022):

Yup. 0.32.2 fixed this I believe

@adamhathcock commented on GitHub (Aug 5, 2022): Yup. 0.32.2 fixed this I believe
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#531