You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TarInputStream.GetNextEntry hangs on corrupt archive #762
var httpClient = new HttpClient();
var stream = await httpClient.GetStreamAsync("https://files.pythonhosted.org/packages/04/b5/fea02ac9306b5d56a5019133f4edda6c9e3cfbd1b5ce663158486ba77eea/diffpy.srfit-1.3.tar.gz");
var gzipStream = new GZipInputStream(stream);
var tarStream = new TarInputStream(gzipStream, Encoding.ASCII);
while (tarStream.CanRead)
{
var entry = tarStream.GetNextEntry();
if (entry == null)
{
break;
}
}
tarStream.Close();
gzipStream.Close();
Expected behavior
Exception should be thrown if archive cannot be processed.
Actual behavior
GetNextEntry() call hangs.
Version of SharpZipLib
1.3.3
Obtained from (only keep the relevant lines)
Package installed using NuGet
Other notes
Archive is an older python package hosted on PyPi.
Inspecting archive with 7zip shows "Unexpected end of data" for many files.
Also tried fully reading http response stream into byte array and reading from memory stream, same problem.
Interesting... the archive untars correctly using gunzip + tar x, so I am not sure what the issue is.
Running it with archivediag, it looks like the end blocks are not in the expected format. I think it gets stuck because it finds blocks in the end with the specified length set as zero, and keeps reading the same blocks over and over again. That is definitely a bug if that's the case.
I added some code to just skip all null bytes between entries, and it correctly reads the archive. I still don't understand why there is these numbers of null bytes in the file, especially since it doesn't align with the block size (512 bytes):
dotnet run -- -t ~/Downloads/diffpy.srfit-1.3.tar | grep Skipped
It hangs somewhere in ExtractContents(). The same file can be extracted using other extractors, so likely not corrupted (at least not beyond all help). The tar was creating using tar (GNU tar) 1.32.
Extracting using the code in this gist works on the same file:
@mikaeleiman This might be due to #789 if there are no end blocks at the end of the archive. In fact, this issue should be revisited with the new tar fixes...
I looked into our code, and it seems that SharpZipLib 1.3.3 handles the file, but 1.4.0 does not. Not sure why we bumped to 1.4.0, but I suspect it was for the dotnet6 support. Seems like 1.3.3 is working fine for our purposes, though.
@mikaeleiman Yeah, then it probably is #788. It's fixed in master and should be released with 1.4.1 pretty soon.
The example file you provided extracts using master as well:
Activity
piksel commentedon Jul 23, 2022
Interesting... the archive untars correctly using
gunzip+tar x, so I am not sure what the issue is.Running it with archivediag, it looks like the end blocks are not in the expected format. I think it gets stuck because it finds blocks in the end with the specified length set as zero, and keeps reading the same blocks over and over again. That is definitely a bug if that's the case.
https://pub.p1k.se/sharpziplib/archivediag/diffpy.srfit-1.3.tar.html
piksel commentedon Jul 23, 2022
I added some code to just skip all null bytes between entries, and it correctly reads the archive. I still don't understand why there is these numbers of null bytes in the file, especially since it doesn't align with the block size (512 bytes):
dotnet run -- -t ~/Downloads/diffpy.srfit-1.3.tar | grep Skippedmikaeleiman commentedon Nov 4, 2022
I'm seeing (likely) the same thing in 1.4.0 running in dotnet6. This is the code we're using to extract a .tar.gz:
It hangs somewhere in ExtractContents(). The same file can be extracted using other extractors, so likely not corrupted (at least not beyond all help). The tar was creating using tar (GNU tar) 1.32.
Extracting using the code in this gist works on the same file:
https://gist.github.com/mikaeleiman/f9510716621b2a6343252df35c4259a1
piksel commentedon Nov 4, 2022
@mikaeleiman This might be due to #789 if there are no end blocks at the end of the archive. In fact, this issue should be revisited with the new tar fixes...
piksel commentedon Nov 4, 2022
Indeed. The file in the original issue unpacks perfectly fine in
master.mikaeleiman commentedon Nov 4, 2022
Example file:
example-762.tar.gz
I looked into our code, and it seems that SharpZipLib 1.3.3 handles the file, but 1.4.0 does not. Not sure why we bumped to 1.4.0, but I suspect it was for the dotnet6 support. Seems like 1.3.3 is working fine for our purposes, though.
piksel commentedon Nov 4, 2022
@mikaeleiman Yeah, then it probably is #788. It's fixed in
masterand should be released with 1.4.1 pretty soon.The example file you provided extracts using
masteras well: