srikanth-lingala / zip4j

A Java library for zip files and streams
Apache License 2.0
2k stars 307 forks source link

net.lingala.zip4j.exception.ZipException: Reached end of entry, but crc verification failed for test.txt #513

Open thePK opened 10 months ago

thePK commented 10 months ago

For the encrypted compressed zip file, is it supported to use zinInputstream to decompress it directly? Below is my test code and maven dependency, I received the following error. But the same code will work fine for an unencrypted zip package.

maven dependency:

net.lingala.zip4j zip4j 2.9.1

test code: public static void main(String[] args) { String srcPath = "E:\test1.zip"; try { ZipInputStream zis = new ZipInputStream(new FileInputStream(srcPath), "123".toCharArray()); LocalFileHeader nextEntry = zis.getNextEntry(); while (Objects.nonNull(nextEntry)) { String fileName = nextEntry.getFileName(); if (!nextEntry.isDirectory()) { log.info("entry name {}", fileName); } nextEntry = zis.getNextEntry(); } } catch (IOException e) { e.printStackTrace(); } }

Error reported: net.lingala.zip4j.exception.ZipException: Reached end of entry, but crc verification failed for test.txt

thePK commented 10 months ago

Sorry about the format before.

For the encrypted compressed zip file, is it supported to use zinInputstream to decompress it directly? Below is my test code and maven dependency, I received the following error. But the same code will work fine for an unencrypted zip package.

maven dependency:

<dependency>
            <groupId>net.lingala.zip4j</groupId>
            <artifactId>zip4j</artifactId>
            <version>2.9.1</version>
        </dependency>

test code:

public static void main(String[] args) {
        String srcPath = "E:\\test1.zip";
        try {
            ZipInputStream zis = new ZipInputStream(new FileInputStream(srcPath), "123".toCharArray());
            LocalFileHeader nextEntry = zis.getNextEntry();
            while (Objects.nonNull(nextEntry)) {
                String fileName = nextEntry.getFileName();
                if (!nextEntry.isDirectory()) {
                    log.info("entry name {}", fileName);
                }
                nextEntry = zis.getNextEntry();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

Error reported:

net.lingala.zip4j.exception.ZipException: Reached end of entry, but crc verification failed for test.txt