Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.IO.Compression.ZipArchive hangs on a corrupt/invalid zip stream from Azure Storage #36355

Open
AbhishekTripathi opened this issue May 13, 2020 · 9 comments

Comments

@AbhishekTripathi
Copy link

AbhishekTripathi commented May 13, 2020

I have found that the ZipArchive goes in an infinite loop when a zip stream is provided from Azure Storage. Below is a code snippet which is easy to reproduce by using any arbitrary file and renaming to zip or using a corrupt zip itself. Using System.IO.Compression v4.3.0. Note that when the files exist on local disk, the behavior is as expected and I get proper exception.

var badBlobPath = @"https://<storage>.blob.core.windows.net/<container>/somefile.zip";
var blobStream = new Microsoft.Azure.Storage.Blob.CloudBlockBlob(new Uri(badBlobPath));
var stream = blobStream.OpenRead();
//below line goes in infinite loop.
var zipArchive = new ZipArchive(stream, ZipArchiveMode.Read, false);
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.IO.Compression untriaged New issue has not been triaged by the area owner labels May 13, 2020
@carlossanlop
Copy link
Member

@AbhishekTripathi thanks for reporting. Do you have the callstack where the loop happens?

@carlossanlop carlossanlop removed the untriaged New issue has not been triaged by the area owner label May 29, 2020
@AbhishekTripathi
Copy link
Author

I may have to debug the nuget source but the function never returns. Seems it gets stuck in infinite loop.

@carlossanlop carlossanlop added this to the Future milestone Jul 8, 2020
@graviteja94
Copy link

Any update on the fix/alternative workaround for this issue?

@danmoseley
Copy link
Member

Can you share callstack @graviteja94 ?

@graviteja94
Copy link

Hi @danmoseley
Could you see the attached screenshot?
image
upon executing the using statement, for a corrupted zip it never goes to the next line and the call stack is also empty
image

basically my code keeps running indefinitely without throwing any exception.

I'm not sure if I provided the information you requested, can you point me out on how to collect the call stack?

@danmoseley
Copy link
Member

Hi @graviteja94 I meant, break in at the point of the hang and get a stack. but if the hang is just looping in your code, of course that's not useful.

I'll let the area owners for compression speak to the issue as it's not my area

@jzirkelbach
Copy link

I'm currently attempting to read a corrupt zip file. When manually testing the archive file by 7-Zip, it's identified with an Unexpected end of data and has a Data error for only one of its many files. When attempting to access this zip file via ZipArchive, I'm observing an infinite loop at the following location:
https://github.com/dotnet/runtime/blob/main/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipHelper.cs#L119-L139
with callstack

>	System.IO.Compression.dll!System.IO.Compression.ZipHelper.SeekBackwardsToSignature(System.IO.Stream stream, uint signatureToFind) Line 89	C#
 	System.IO.Compression.dll!System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory() Line 390	C#
 	System.IO.Compression.dll!System.IO.Compression.ZipArchive.Init(System.IO.Stream stream, System.IO.Compression.ZipArchiveMode mode, bool leaveOpen) Line 340	C#
 	System.IO.Compression.dll!System.IO.Compression.ZipArchive.ZipArchive(System.IO.Stream stream, System.IO.Compression.ZipArchiveMode mode) Line 100	C#

image

I hope this helps.

@danmoseley
Copy link
Member

@jzirkelbach thanks, that does help. Any interest in investigating ?

@jzirkelbach
Copy link

@danmoseley, I'm getting more involved with compression work, but I don't have the availability to reliably commit time. I'll continue to watch this issue and contribute when and where I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants