sudipta1411 / jtar

Automatically exported from code.google.com/p/jtar
0 stars 0 forks source link

Unhandled exception in TarIInputStream.getNextEntry() #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. While((entry = tis.getNextEntry()) != null)
2. Use the attached corrupt tar file

What is the expected output? What do you see instead?
I would like either null to be returned or an exception to be thrown (later 
probably best).  Instead, getNextEntry never returns and the java process runs 
until manually killed.

What version of the product are you using? On what operating system?
1.0.4.  Linux x86_64 (Problem reproducible on Suse 10, Suse 11, Fedora 16)

Please provide any additional information below.
See attached file.

Original issue reported on code.google.com by markus.d...@gmail.com on 10 Apr 2012 at 1:25

Attachments:

GoogleCodeExporter commented 9 years ago
I have fixed it for now:

    protected void closeCurrentEntry() throws IOException {
        if (currentEntry != null) {
            if (currentEntry.getSize() > currentFileSize) {
                // Not fully read, skip rest of the bytes
                long bs = 0;
                while (bs < currentEntry.getSize() - currentFileSize) {
                    long res = skip( currentEntry.getSize() - currentFileSize - bs );
                    if (res == 0 && currentEntry.getSize() - currentFileSize > 0)
                    {
                        // I suspect file corruption
                        throw new IOException( "Possible tar file corruption" );
                    }
                    bs += res;
                }

            }

            currentEntry = null;
            currentFileSize = 0L;
            skipPad();
        }

    }

That new if statement probably needs to be checked properly but I think it 
works.
The read (inside skip(long n)) returns a -1 that is broken out of the while 
loop.  So the return value for skip is zero.  If skip is returning zero, yet 
there is apparently more to read then I think there is a problem with the tar 
file.

Original comment by markus.d...@gmail.com on 10 Apr 2012 at 2:15

GoogleCodeExporter commented 9 years ago

Original comment by xeus....@gmail.com on 1 May 2012 at 3:06

GoogleCodeExporter commented 9 years ago

Original comment by xeus....@gmail.com on 1 May 2012 at 9:13

GoogleCodeExporter commented 9 years ago
v1.1

Original comment by xeus....@gmail.com on 1 May 2012 at 9:14