Exception thrown (rarely) in TarHeader with empty array
See original GitHub issueI have a unit test that goes though some SharpZipLib methods. Every once in a while it fails in a VM which the following error:
ModTime cannot be before Jan 1st 1970 (Parameter 'value')
at ICSharpCode.SharpZipLib.Tar.TarHeader.set_ModTime(DateTime value)
at ICSharpCode.SharpZipLib.Tar.TarHeader.ParseBuffer(Byte[] header, Encoding nameEncoding)
at ICSharpCode.SharpZipLib.Tar.TarInputStream.GetNextEntryAsync(CancellationToken ct, Boolean isAsync)
at ICSharpCode.SharpZipLib.Tar.TarInputStream.GetNextEntry()
The code that is throwing that exception is the below one and is ALWAYS called with input Array.Empty<byte>():
public static byte[] Dummy(this byte[] data) {
using var inStream = new MemoryStream(data);
using var outStream = new MemoryStream();
using var gzipStream = new GZipInputStream(inStream);
using var tarInputStream = new TarInputStream(gzipStream, Encoding.UTF8);
while (tarInputStream.GetNextEntry() is { } tarEntry) {
}
return outStream.ToArray();
}
The “fun” part is that this NEVER happens in my local machine. Only in the CICD pipeline, once in a while. The CICD pipeline is a newly booted ubuntu-20.04 container on Azure Devops.
Steps to reproduce
- Boot a ubuntu-20.04 container (freshly booted?)
- Run the function
- Repeat until it happens
Expected behavior
A dummy empty tar.gz archive should be enumerated
Actual behavior
An exception is (rarely) thrown.
Version of SharpZipLib
1.4.0
Obtained from (only keep the relevant lines)
- Package installed using NuGet
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
java - How to catch an empty array [0] (Exception)
Of course, you should first check that the array is empty, and only after that set min to 0-th element.
Read more >getting exception "index 0 beyond bounds for empty array"?
You have an array without any objects in it and you're attempting to access the first object. If you show us code we...
Read more >SharpZipLib - bytemeta
Exception thrown (rarely) in TarHeader with empty array. Sardelka9515. Sardelka9515 OPEN · Updated 8 months ago · Support seeking for non-compressed zip ...
Read more >git-dot-aspx/lib/SharpZipLib/ICSharpCode.SharpZipLib.xml ...
... Get/set a value indicating wether empty directories should be created. ... </summary> <remarks>NOTE: Not all exceptions thrown will be ...
Read more >Thread: [PATCH] Empty arrays cause SQLExceptions when ...
I have fixed a minor bug in empty arrays as described below ... not an empty array + * otherwise there will be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s definitively caused by the re-use of a shared array pool array. The array is not zeroed, so when reading from an empty source it will treat the “garbage” data in the array as input.
That makes sense. Thank you for the explanation.