Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZipInputStream signals end-of-input after directory entry #438

Closed
aunkrig opened this issue Jun 14, 2022 · 5 comments
Closed

ZipInputStream signals end-of-input after directory entry #438

aunkrig opened this issue Jun 14, 2022 · 5 comments
Assignees
Labels
bug Something isn't working resolved

Comments

@aunkrig
Copy link

aunkrig commented Jun 14, 2022

Steps to reproduce:

I get the following output:

Processing eureka-client-1.10.17.jar with net.lingala.zip4j.io.inputstream.ZipInputStream:
  META-INF/
Processing eureka-client-1.10.17.jar with net.lingala.zip4j.ZipFile:
  META-INF/
  META-INF/MANIFEST.MF
  META-INF/eureka-client.properties
  com/
  com/netflix/
  com/netflix/appinfo/
  com/netflix/appinfo/AmazonInfoConfig.class
  com/netflix/appinfo/PropertyBasedInstanceConfigConstants.class
  com/netflix/appinfo/HealthCheckResource$1.class
  com/netflix/appinfo/InstanceInfo$PortWrapper.class
  ...

Observations:

  • ZipInputStream.getNextEntry() returns null after the first directory entry, although there are many more entries in the archive.
  • It happens with the ZipInputStream, but not with the ZipFile.
  • If you read the contents of all direectory entries (which does not make much sense), then it does not happen.

Test program which reproduces the problem:

package zip4jtest;

import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;

import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.io.inputstream.ZipInputStream;
import net.lingala.zip4j.model.FileHeader;
import net.lingala.zip4j.model.LocalFileHeader;

public
class Main {

    private static final File ZIP_FILE = new File("eureka-client-1.10.17.jar");
    
    public static void
    main(String[] args) throws Exception {
        
        System.out.printf("Processing %s with %s:%n", ZIP_FILE, ZipInputStream.class.getName());
        try (ZipInputStream zis = new ZipInputStream(new FileInputStream(ZIP_FILE))) {
            int i = 0;
            for (;;) {
                LocalFileHeader lfh = zis.getNextEntry();
                if (lfh == null) break;

                System.out.printf("  %s%n", lfh.getFileName());

                // If you enable the following line of code, then the archive is at EOI after the *second* directory
                // entry.
//                if ("META-INF/".equals(lfh.getFileName())) zis.transferTo(OutputStream.nullOutputStream());

                // If you enable the following line of code, then the archive is listed completely.
//                if (lfh.isDirectory()) zis.transferTo(OutputStream.nullOutputStream());

                // If both of the above are disabled, then the archive is at EOI after the first directory entry
                // ("META-INF/").

                if (++i >= 10) {
                    System.out.printf("  ...%n");
                    break;
                }
            }
        }
        
        System.out.printf("Processing %s with %s:%n", ZIP_FILE, ZipFile.class.getName());
        try (ZipFile zf = new ZipFile(ZIP_FILE)) {
            int i = 0;
            for (FileHeader fh : zf.getFileHeaders()) {
                System.out.printf("  %s%n", fh.getFileName());
                ZipInputStream is = zf.getInputStream(fh);
//                is.transferTo(OutputStream.nullOutputStream());
                if (++i >= 10) {
                    System.out.printf("  ...%n");
                    break;
                }
            }
        }
    }
}
@aunkrig
Copy link
Author

aunkrig commented Jun 14, 2022

Under certain conditions, the ZipInputStream.transferTo() throws a ZipException about some CRC problem. In this case read(new byte[0]) helps, but in all other cases the problem re-appears.

@srikanth-lingala
Copy link
Owner

Issue fixed. Will include the fix in the next release

@aunkrig
Copy link
Author

aunkrig commented Jun 15, 2022

Great; that fix works for all my test cases! Thank you for your support.

@aunkrig aunkrig closed this as completed Jun 15, 2022
@srikanth-lingala
Copy link
Owner

Please leave the issue open. I will close this issue after I release the version. It makes it easier for me to keep track of the changes going into a version.

@srikanth-lingala
Copy link
Owner

Fixed in v2.11.0 released today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved
Projects
None yet
Development

No branches or pull requests

2 participants