tobiasschulz / tar-cs

Automatically exported from code.google.com/p/tar-cs
Other
0 stars 0 forks source link

FormatException is thrown in UpdateHeaderFromBytes() due to converting non-trimmed strings to ints #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Created a tar archive of a directory with some files in it using 7-zip 9.20.
2. Tried to read it using the TarReader class, but a FormatException is thrown 
when reader.MoveNext(true) is called; more specifically, the expception is 
thrown in one of the calls to Convert.ToInt64 in the 
TarHeader.UpdateHeaderFromBytes method.

What is the expected output? What do you see instead?
FormatException is thrown while parsing the header of a valid tar file - the 
expected behaviour is to read the file without problems.

What version of the product are you using? On what operating system?
rev58 from SVN

Please provide any additional information below.
The problem the same as issue 6, whitespace can be present in the size, unix 
timestamp and checksum fields. Adding ".Trim()" to the string that will be 
converted by Convert.ToInt32/ToInt64 calls in the UpdateHeaderFromBytes() 
method solves the issue.

Original issue reported on code.google.com by n...@coherent-labs.com on 21 Mar 2013 at 8:47

GoogleCodeExporter commented 9 years ago
Same problem here. Doesn't matter if reader.MoveNext is called with true or 
false. Using source from 20140118.
Best regards

Original comment by Michal.A...@gmail.com on 28 Jan 2014 at 9:11

GoogleCodeExporter commented 9 years ago
Trimming fixes this issue.
Change line
 SizeInBytes = Convert.ToInt64(Encoding.ASCII.GetString(buffer, 124, 11), 8);
to
 SizeInBytes = Convert.ToInt64(Encoding.ASCII.GetString(buffer, 124, 11).Trim(), 8);
and it works like a charm :)
Not sure if it works with other tar archives (not made with 7-zip 9.20) but I 
don't see a reason why it shouldn't.
All the best :)

Original comment by Michal.A...@gmail.com on 28 Jan 2014 at 9:39

GoogleCodeExporter commented 9 years ago
I'm having the same issue.  I'm getting an exception at the Mode line

public virtual bool UpdateHeaderFromBytes()
{
     FileName = Encoding.ASCII.GetString(buffer, 0, 100);
     // thanks to Shasha Alperocivh. Trimming nulls.
     Mode = Convert.ToInt32(Encoding.ASCII.GetString(buffer, 100, 7).Trim(), 8);

The SizeinByte line is below this one.

Original comment by ronm3...@hotmail.com on 11 Sep 2014 at 9:50