False tar file detection
See original GitHub issueTL;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:
- Created 5 years ago
- Reactions:4
- Comments:10 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Read the source in is_tar.c in libmagic which calculates the checksum of the block. So easy enough
Should port the
is_tar
detection from https://github.com/threatstack/libmagic/blob/master/src/is_tar.c