Skip to content

Exception thrown (rarely) in TarHeader with empty array #782

@DiogoRoloOS

Description

@DiogoRoloOS

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():

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtarRelated to TAR file format

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions