AbstractReader.Skip doesn't work for UsePostDataDescriptor zip streams #115

Closed
opened 2026-01-29 22:06:49 +00:00 by claunia · 6 comments
Owner

Originally created by @AlexVallat on GitHub (Aug 12, 2016).

Originally assigned to: @adamhathcock on GitHub.

In AbstractReader.Skip() the shortcut to skip data by reading the raw stream rather than decompressing doesn't work if .CompressedSize is 0 due to a UsePostDataDescriptor formatted zip entry header.

Originally created by @AlexVallat on GitHub (Aug 12, 2016). Originally assigned to: @adamhathcock on GitHub. In `AbstractReader.Skip()` the shortcut to skip data by reading the raw stream rather than decompressing doesn't work if `.CompressedSize` is 0 due to a UsePostDataDescriptor formatted zip entry header.
claunia added the bug label 2026-01-29 22:06:49 +00:00
Author
Owner

@adamhathcock commented on GitHub (Aug 12, 2016):

It might be related to the thing you just fixed but that was me skipping data start position.

Anyway, if the descriptor doesn't put in a compressed size I don't know how I can just skip it without decompressing.

It's possible to scan the bytes for a zip header but that doesn't feel correct anyway. Already had issues with nested archives.

@adamhathcock commented on GitHub (Aug 12, 2016): It might be related to the thing you just fixed but that was me skipping data start position. Anyway, if the descriptor doesn't put in a compressed size I don't know how I can just skip it without decompressing. It's possible to scan the bytes for a zip header but that doesn't feel correct anyway. Already had issues with nested archives.
Author
Owner

@AlexVallat commented on GitHub (Aug 12, 2016):

I don't think you can skip it without decompressing, if the size isn't known. The problem is that it should not skip 0 bytes and assume it's skipped the contents, I think it has to use the fallback path of actually reading the contents (like it does for the Entry.IsSolid case).

@AlexVallat commented on GitHub (Aug 12, 2016): I don't think you can skip it without decompressing, if the size isn't known. The problem is that it should not skip 0 bytes and assume it's skipped the contents, I think it has to use the fallback path of actually reading the contents (like it does for the `Entry.IsSolid` case).
Author
Owner

@adamhathcock commented on GitHub (Aug 12, 2016):

OHH...I see. It thinks it should just skip 0 bytes. Yeah, you're right it should decompress it.

Any chance of a PR for this issue?

@adamhathcock commented on GitHub (Aug 12, 2016): OHH...I see. It thinks it should just skip 0 bytes. Yeah, you're right it should decompress it. Any chance of a PR for this issue?
Author
Owner

@AlexVallat commented on GitHub (Aug 12, 2016):

Simplest solution I can think of is to add to the ZipEntry constructor:

if (FlagUtility.HasFlag(filePart.Header.Flags, HeaderFlags.UsePostDataDescriptor))
{
    IsSolid = true;
}

but that might be abusing the IsSolid property? I only saw it set for Rars, and only consumed in the Skip() method so this would probably be OK, but it smells a bit. Could rename the property to DecompressDuringSkip or similar, or otherwise I think it's going to take some extra plumbing.

Or alternatively you could assume that if CompressedSize was 0 it should use a decompressed skip - probably harmless as if it really is empty it won't take long to decompress it!

@AlexVallat commented on GitHub (Aug 12, 2016): Simplest solution I can think of is to add to the `ZipEntry` constructor: ``` if (FlagUtility.HasFlag(filePart.Header.Flags, HeaderFlags.UsePostDataDescriptor)) { IsSolid = true; } ``` but that might be abusing the IsSolid property? I only saw it set for Rars, and only consumed in the Skip() method so this would probably be OK, but it smells a bit. Could rename the property to `DecompressDuringSkip` or similar, or otherwise I think it's going to take some extra plumbing. Or alternatively you could assume that if `CompressedSize` was 0 it should use a decompressed skip - probably harmless as if it really is empty it won't take long to decompress it!
Author
Owner

@adamhathcock commented on GitHub (Aug 12, 2016):

I guess where IsSolid is being checked should also check for the flag header and a size of zero to trigger the decompression

@adamhathcock commented on GitHub (Aug 12, 2016): I guess where IsSolid is being checked should also check for the flag header and a size of zero to trigger the decompression
Author
Owner

@AlexVallat commented on GitHub (Aug 12, 2016):

Unfortunately that's in AbstractReader, and therefore doesn't have access to the ZipEntry Header - it shouldn't, in principle, have knowledge of zip-specific flags.

@AlexVallat commented on GitHub (Aug 12, 2016): Unfortunately that's in AbstractReader, and therefore doesn't have access to the ZipEntry Header - it shouldn't, in principle, have knowledge of zip-specific flags.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#115