Skip to content

"Item with the same key has already been added" extracting tar with duplicate headers #383

Closed

Description

@zarenner

SharpZipLib fails to process a tar file that contains duplicate extended headers. Other tar programs (e.g. tar, 7-zip, SharpCompress) appear to handle this fine.

Steps to reproduce

  1. Download https://registry.npmjs.org/jasmine-data-provider/-/jasmine-data-provider-2.2.0.tgz
  2. gunzip (either with sharpziplib or other software)
  3. Attempt to extract, read entries, or list contents of the tar:
using (var fs = File.OpenRead("c:\\jasmine-data-provider-2.2.0.tar"))
using (TarArchive tar = TarArchive.CreateInputTarArchive(fs))
{
    tar.ListContents();
}

Actual behavior

An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)   at ICSharpCode.SharpZipLib.Tar.TarExtendedHeaderReader.Read(Byte[] buffer, Int32 length)   at ICSharpCode.SharpZipLib.Tar.TarInputStream.GetNextEntry()   at ICSharpCode.SharpZipLib.Tar.TarArchive.ListContents()

Version of SharpZipLib

1.2.0

Obtained from (only keep the relevant lines)

  • Package installed using NuGet

Activity

  1. Numpsy commented on Sep 15, 2019

    @Numpsy
    Contributor

    I tried debugging it and got:

    image

    Looks like TarExtendedHeaderReader treats every newline as the end of a header, and goes wrong if the value of a header itself contains a newline, rather than just taking the amount of data specified by the length field?

  2. piksel commented on Sep 24, 2019

    @piksel
    Member

    Whoa, yeah, this seems to be a lot deeper than simply duplicate headers.

  3. piksel commented on Sep 24, 2019

    @piksel
    Member

    Adding the file to the issue in case it gets moved: jasmine-data-provider-2.2.0.tar.gz

  4. added
    tar
    on Sep 24, 2019
  5. zarenner commented on Sep 24, 2019

    @zarenner
    Author

    Thanks for the analysis into the actual cause @Numpsy.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtar

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions