From 597b31afb473a40e8252de5b5def1876bab198d3 Mon Sep 17 00:00:00 2001 From: Srikanth Reddy Lingala Date: Sun, 15 Jan 2023 11:19:55 -0500 Subject: [PATCH] #485 Check for MAC even when DataDescritor exists --- .../zip4j/io/inputstream/AesCipherInputStream.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/java/net/lingala/zip4j/io/inputstream/AesCipherInputStream.java b/src/main/java/net/lingala/zip4j/io/inputstream/AesCipherInputStream.java index 25d55cf3..a58179f9 100644 --- a/src/main/java/net/lingala/zip4j/io/inputstream/AesCipherInputStream.java +++ b/src/main/java/net/lingala/zip4j/io/inputstream/AesCipherInputStream.java @@ -4,9 +4,7 @@ import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.model.AESExtraDataRecord; import net.lingala.zip4j.model.LocalFileHeader; -import net.lingala.zip4j.model.enums.CompressionMethod; import net.lingala.zip4j.util.InternalZipConstants; -import net.lingala.zip4j.util.Zip4jUtil; import java.io.IOException; import java.io.InputStream; @@ -124,16 +122,6 @@ protected void endOfEntryReached(InputStream inputStream) throws IOException { } private void verifyContent(byte[] storedMac) throws IOException { - if (getLocalFileHeader().isDataDescriptorExists() - && CompressionMethod.DEFLATE.equals(Zip4jUtil.getCompressionMethod(getLocalFileHeader()))) { - // Skip content verification in case of Deflate compression and if data descriptor exists. - // In this case, we do not know the exact size of compressed data before hand and it is possible that we read - // and pass more than required data into inflater, thereby corrupting the aes mac bytes. - // See usage of PushBackInputStream in the project for how this push back of data is done - // Unfortunately, in this case we cannot perform a content verification and have to skip - return; - } - byte[] calculatedMac = getDecrypter().getCalculatedAuthenticationBytes(); byte[] first10BytesOfCalculatedMac = new byte[AES_AUTH_LENGTH]; System.arraycopy(calculatedMac, 0, first10BytesOfCalculatedMac, 0, InternalZipConstants.AES_AUTH_LENGTH);