Unable to detect wrong TAR archives

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to detect wrong TAR archives

cristi-2
Hello all

I am using the Apache Jakarta Commons Compress library to
untar .tar files. All works fine until I try to untar a
file with the .tar extension but whose contents is not a
well formed TAR file.

The problem is that nobody warns me about such an event and
the program executes as nothing unusual has happend. Is there
any way to see if a file with is a well formed TAR file ?

regards
cristi



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Unable to detect wrong TAR archives

rafiq-2
Hi Cristi,

> I am using the Apache Jakarta Commons Compress library to
> untar .tar files. All works fine until I try to untar a
> file with the .tar extension but whose contents is not a
> well formed TAR file.

Have you considered writing a wrapper around Compress which contains your
input stream and checks the first record in the tar using getNextEntry()
for a non-null entry, otherwise throwing an exception.

Cheers,

Raf



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Unable to detect wrong TAR archives

cristi-2
[hidden email] wrote:

> Hi Cristi,
>
>
>>I am using the Apache Jakarta Commons Compress library to
>>untar .tar files. All works fine until I try to untar a
>>file with the .tar extension but whose contents is not a
>>well formed TAR file.
>
>
> Have you considered writing a wrapper around Compress which contains your
> input stream and checks the first record in the tar using getNextEntry()
> for a non-null entry, otherwise throwing an exception.
>

---- BEGIN CODE ----

tis = new TarInputStream(new FileInputStream(archFile));
TarEntry te = null;
while ((te = tis.getNextEntry()) != null)
{
      /* SOME PROCESSING HERE */
}

---- END CODE ----

Within the piece of code above, no exception is thrown if "archFile" is
not a well formed TAR file. The "te" variable gets a non null value
after the call to getNextEntry(), so how can I see if the tar file is
a bad one ?

Thx again
cristi

> Cheers,
>
> Raf

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]