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.

False tar file detection

See original GitHub issue

TL;DR: TarArchive.IsTarFile() says a file is a tar file when it actually isn’t.

I tried extracting a .gz file (not .tar.gz) using the ReaderFactory.Open() method and the extraction resulted in very strange file names, which lead me to investigate, and I discovered that the decompressed gz file is detected as a valid tar file.

Steps to reproduce:

var bytes = new List<byte>(System.Text.Encoding.ASCII.GetBytes("hello world"));

while (bytes.Count < 512)
    bytes.Add(0);

var stream = new MemoryStream(bytes.ToArray());
bool result = SharpCompress.Archives.Tar.TarArchive.IsTarFile(stream); // returns true

This behaviour occured with multiple (similar) files. The code above generates a simplified version of one of the files I tried to decompress. It behaves the same even if I read the file from disk.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
adamhathcockcommented, Jun 8, 2018

Read the source in is_tar.c in libmagic which calculates the checksum of the block. So easy enough

0reactions
adamhathcockcommented, Feb 5, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Test tar file integrity in bash
I have a bash script that creates a '.tar' file. Once the file is created, I would like to test its integrity and...
Read more >
GNU tar 1.34.90: 10.1 Reliability
An tar-format archive contains a checksum that most likely will detect errors in the metadata, but it will not detect errors in the...
Read more >
How to check whether a file is in tar format?
I want to implement a check of a tar file. I am not interested only to check the file extension, but I need...
Read more >
How can I check if .tar (not tar.gz) file is corrupt or not, in ...
You can use 7zip to easily test whether an archive is corrupted or not. If 7zip, which is distributed via the p7zip package...
Read more >
Vulnerability in tarfile module
The vulnerability allows an arbitrary file to be written to an arbitrary folder on the hard drive, and in some cases it also...
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