mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-12 21:22:26 +00:00
SharpCompressStream.StackSeek fails to update buffer content when rewinding
#722
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @IDXGI on GitHub (Nov 19, 2025).
I discovered this issue while investigating #1021.
Observation
It appears that
SharpCompressStreamuses a buffering design where it loads chunks of 65,536 bytes from the underlying stream. This buffer acts like a sliding window that moves forward as the reading position advances.The Issue
In
TarFactory.TryOpenReader(), the code calls:I noticed that
StackSeekonly updatesSharpCompressStream._bufferPositionandSharpCompressStream._internalPosition:_internalPosition: The global position within the entire stream._bufferPosition: The offset within the current 64KB buffer.The Logic Flaw
When
_internalPositionis modified (specifically when seeking backward/rewinding), the internal buffer logic does not check if the new position is actually within the currently loaded buffer window. It assumes the data is there. If the buffer isn't reloaded or "slid" to match the new_internalPosition, the stream returns incorrect data.For example, if you attempt to seek back to read the first 6 bytes of the stream, but the buffer is currently holding data from the end of the stream,
Read()will return data from the wrong offset.Impact on #1021
This is the root cause of the "Stream Corruption" reported in #1021:
_internalPositionto0to try a different TAR parsing logic, the buffer content was not refreshed.This issue seems to be isolated to
SharpCompressStreamand is not directly related to the Tar implementation. It likely went unnoticed until now because format identification usually happens within the first 65,536 bytes, so the buffer window rarely needs to move and then reset in this manner.@Morilli commented on GitHub (Nov 20, 2025):
Should have been resolved by #1017.
@IDXGI commented on GitHub (Nov 22, 2025):
Thanks @Morilli, I'll trust that #1017 fixes the buffer update logic. Closing this issue.