Do not read position when tar archive stream is unseekable#70178
Do not read position when tar archive stream is unseekable#70178carlossanlop merged 6 commits intodotnet:mainfrom carlossanlop:UnseekableBug
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsFixes: #70172 The position was being read at the very last moment of creating the archive, to set the archive size one byte after the empty records. This causes an exception to be thrown when compressing directly into a gzip stream, which is unseekable (position cannot be accessed).
|
| Assert.Null(reader.GetNextEntry()); | ||
| } | ||
|
|
||
| [Fact] |
There was a problem hiding this comment.
We have a test that verifies the behavior of the TarEntry.DataStream when reading an unseekable stream:
But that test wasn't creating an archive using TarWriter against an unseekable stream, hence why this bug wasn't caught before. That's why I'm also adding this extra test to write to a generic unseekable stream.
src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs
Outdated
Show resolved
Hide resolved
| public class CompressedTar_Tests : TarTestsBase | ||
| { | ||
| [Fact] | ||
| public void TarGz_TarWriter_TarReader() |
There was a problem hiding this comment.
are these tests related to the fix?
There was a problem hiding this comment.
Yes. This test passes a GZipStream (an unseekable stream) to the TarWriter. TarWriter will finish adding the entries, then will add the two empty records, and then it would've called that incorrect SetLength call (which I just removed completely since it's not needed).
Fixes: #70172
The position was being read at the very last moment of creating the archive, to set the archive size one byte after the empty records. This causes an exception to be thrown when compressing directly into a gzip stream, which is unseekable (position cannot be accessed).
cc @rainersigwald