Skip to content

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

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

Closed
zarenner opened this issue Sep 4, 2019 · 4 comments · Fixed by #675
Closed
Labels
bug tar Related to TAR file format

Comments

@zarenner
Copy link

zarenner commented Sep 4, 2019

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
@Numpsy
Copy link
Contributor

Numpsy commented Sep 15, 2019

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?

@piksel
Copy link
Member

piksel commented Sep 24, 2019

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

@piksel
Copy link
Member

piksel commented Sep 24, 2019

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

@piksel piksel added bug tar Related to TAR file format labels Sep 24, 2019
@zarenner
Copy link
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
Labels
bug tar Related to TAR file format
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants