question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception thrown (rarely) in TarHeader with empty array

See original GitHub issue

I 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

  1. Boot a ubuntu-20.04 container (freshly booted?)
  2. Run the function
  3. 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:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pikselcommented, Oct 5, 2022

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.

0reactions
DiogoRoloOScommented, Oct 6, 2022

That makes sense. Thank you for the explanation.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found