[Git][java-team/zip4j][master] 3 commits: New upstream version 2.5.2
Andrius Merkys
gitlab at salsa.debian.org
Fri May 1 05:25:40 BST 2020
Andrius Merkys pushed to branch master at Debian Java Maintainers / zip4j
Commits:
53aa8af5 by Andrius Merkys at 2020-04-30T23:46:49-04:00
New upstream version 2.5.2
- - - - -
8775d3ec by Andrius Merkys at 2020-04-30T23:46:52-04:00
Update upstream source from tag 'upstream/2.5.2'
Update to upstream version '2.5.2'
with Debian dir 86a564c73ad5635e7ad57de57b2997fcd1443604
- - - - -
33de820a by Andrius Merkys at 2020-04-30T23:47:26-04:00
Packaging new upstream version.
- - - - -
12 changed files:
- README.md
- debian/changelog
- pom.xml
- src/main/java/net/lingala/zip4j/headers/HeaderReader.java
- src/main/java/net/lingala/zip4j/headers/HeaderUtil.java
- src/main/java/net/lingala/zip4j/model/EndOfCentralDirectoryRecord.java
- src/test/java/net/lingala/zip4j/ExtractZipFileIT.java
- src/test/java/net/lingala/zip4j/headers/HeaderReaderIT.java
- src/test/java/net/lingala/zip4j/headers/HeaderUtilTest.java
- src/test/java/net/lingala/zip4j/headers/HeaderWriterIT.java
- + src/test/resources/test-archives/end_of_cen_dir_not_at_expected_position.zip
- + src/test/resources/test-archives/zip_with_corrupt_comment_length.zip
Changes:
=====================================
README.md
=====================================
@@ -1,5 +1,6 @@
[![Build Status](https://travis-ci.org/srikanth-lingala/zip4j.svg?branch=master)](https://travis-ci.org/srikanth-lingala/zip4j)
+[![Android Build Status](https://circleci.com/gh/srikanth-lingala/zip4j-android-test.svg?style=svg)](https://circleci.com/gh/srikanth-lingala/zip4j-android-test)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.lingala.zip4j/zip4j/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.lingala.zip4j/zip4j)
[![Known Vulnerabilities](https://snyk.io//test/github/srikanth-lingala/zip4j/badge.svg?targetFile=pom.xml)](https://snyk.io//test/github/srikanth-lingala/zip4j?targetFile=pom.xml)
@@ -61,7 +62,7 @@ once again, and makes me support Zip4j as much as I can..
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
- <version>2.5.0</version>
+ <version>2.5.2</version>
</dependency>
~~~~
@@ -581,6 +582,10 @@ example: no more explicitly closing the streams all over the code). If you still
I am pretty sure that there are things to be improved), please let me know by opening an issue here or writing to me
(My email id is in point #2 above).
+6. **What are the licensing conditions for older releases of zip4j?**
+
+ All releases of zip4j, from version 1.0, are licensed under Apache License 2.0
+
[1]: https://stackoverflow.com/questions/9324933/what-is-a-good-java-library-to-zip-unzip-files
[2]: https://stackoverflow.com/questions/5362364/java-library-to-work-with-zip-files
=====================================
debian/changelog
=====================================
@@ -1,3 +1,9 @@
+zip4j (2.5.2-1) unstable; urgency=medium
+
+ * New upstream version 2.5.2
+
+ -- Andrius Merkys <merkys at debian.org> Thu, 30 Apr 2020 23:47:10 -0400
+
zip4j (2.5.0-1) unstable; urgency=medium
* New upstream version 2.5.0
=====================================
pom.xml
=====================================
@@ -6,7 +6,7 @@
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
- <version>2.5.1-SNAPSHOT</version>
+ <version>2.5.3-SNAPSHOT</version>
<name>Zip4j</name>
<description>Zip4j - A Java library for zip files and streams</description>
=====================================
src/main/java/net/lingala/zip4j/headers/HeaderReader.java
=====================================
@@ -47,6 +47,7 @@ import java.util.List;
import static net.lingala.zip4j.headers.HeaderUtil.decodeStringWithCharset;
import static net.lingala.zip4j.util.BitUtils.isBitSet;
+import static net.lingala.zip4j.util.InternalZipConstants.BUFF_SIZE;
import static net.lingala.zip4j.util.InternalZipConstants.ENDHDR;
import static net.lingala.zip4j.util.InternalZipConstants.ZIP_64_NUMBER_OF_ENTRIES_LIMIT;
import static net.lingala.zip4j.util.InternalZipConstants.ZIP_64_SIZE_LIMIT;
@@ -83,7 +84,8 @@ public class HeaderReader {
}
// If file is Zip64 format, Zip64 headers have to be read before reading central directory
- zipModel.setZip64EndOfCentralDirectoryLocator(readZip64EndOfCentralDirectoryLocator(zip4jRaf, rawIO));
+ zipModel.setZip64EndOfCentralDirectoryLocator(readZip64EndOfCentralDirectoryLocator(zip4jRaf, rawIO,
+ zipModel.getEndOfCentralDirectoryRecord().getOffsetOfEndOfCentralDirectory()));
if (zipModel.isZip64Format()) {
zipModel.setZip64EndOfCentralDirectoryRecord(readZip64EndCentralDirRec(zip4jRaf, rawIO));
@@ -102,23 +104,17 @@ public class HeaderReader {
private EndOfCentralDirectoryRecord readEndOfCentralDirectoryRecord(RandomAccessFile zip4jRaf, RawIO rawIO, Charset charset)
throws IOException {
- long zipFileLengthWithoutEndHeader = zip4jRaf.length() - ENDHDR;
- long pos = zipFileLengthWithoutEndHeader;
- EndOfCentralDirectoryRecord endOfCentralDirectoryRecord = new EndOfCentralDirectoryRecord();
-
- int counter = 0;
- int headerSignature;
- do {
- seekInCurrentPart(zip4jRaf, pos--);
- counter++;
- } while (((headerSignature = rawIO.readIntLittleEndian(zip4jRaf))
- != HeaderSignature.END_OF_CENTRAL_DIRECTORY.getValue()) && counter <= zipFileLengthWithoutEndHeader);
+ long offsetEndOfCentralDirectory = zip4jRaf.length() - ENDHDR;
+ seekInCurrentPart(zip4jRaf, offsetEndOfCentralDirectory);
+ int headerSignature = rawIO.readIntLittleEndian(zip4jRaf);
if (headerSignature != HeaderSignature.END_OF_CENTRAL_DIRECTORY.getValue()) {
- throw new ZipException("Zip headers not found. Probably not a zip file");
+ offsetEndOfCentralDirectory = determineOffsetOfEndOfCentralDirectory(zip4jRaf);
+ zip4jRaf.seek(offsetEndOfCentralDirectory + 4); // 4 to ignore reading signature again
}
+ EndOfCentralDirectoryRecord endOfCentralDirectoryRecord = new EndOfCentralDirectoryRecord();
endOfCentralDirectoryRecord.setSignature(HeaderSignature.END_OF_CENTRAL_DIRECTORY);
endOfCentralDirectoryRecord.setNumberOfThisDisk(rawIO.readShortLittleEndian(zip4jRaf));
endOfCentralDirectoryRecord.setNumberOfThisDiskStartOfCentralDir(rawIO.readShortLittleEndian(zip4jRaf));
@@ -126,19 +122,13 @@ public class HeaderReader {
rawIO.readShortLittleEndian(zip4jRaf));
endOfCentralDirectoryRecord.setTotalNumberOfEntriesInCentralDirectory(rawIO.readShortLittleEndian(zip4jRaf));
endOfCentralDirectoryRecord.setSizeOfCentralDirectory(rawIO.readIntLittleEndian(zip4jRaf));
+ endOfCentralDirectoryRecord.setOffsetOfEndOfCentralDirectory(offsetEndOfCentralDirectory);
zip4jRaf.readFully(intBuff);
endOfCentralDirectoryRecord.setOffsetOfStartOfCentralDirectory(rawIO.readLongLittleEndian(intBuff, 0));
int commentLength = rawIO.readShortLittleEndian(zip4jRaf);
-
- if (commentLength > 0) {
- byte[] commentBuf = new byte[commentLength];
- zip4jRaf.readFully(commentBuf);
- endOfCentralDirectoryRecord.setComment(new String(commentBuf, charset));
- } else {
- endOfCentralDirectoryRecord.setComment(null);
- }
+ endOfCentralDirectoryRecord.setComment(readZipComment(zip4jRaf, commentLength, charset));
zipModel.setSplitArchive(endOfCentralDirectoryRecord.getNumberOfThisDisk() > 0);
return endOfCentralDirectoryRecord;
@@ -352,10 +342,11 @@ public class HeaderReader {
}
private Zip64EndOfCentralDirectoryLocator readZip64EndOfCentralDirectoryLocator(RandomAccessFile zip4jRaf,
- RawIO rawIO) throws IOException {
+ RawIO rawIO, long offsetEndOfCentralDirectoryRecord) throws IOException {
+
Zip64EndOfCentralDirectoryLocator zip64EndOfCentralDirectoryLocator = new Zip64EndOfCentralDirectoryLocator();
- setFilePointerToReadZip64EndCentralDirLoc(zip4jRaf, rawIO);
+ setFilePointerToReadZip64EndCentralDirLoc(zip4jRaf, offsetEndOfCentralDirectoryRecord);
int signature = rawIO.readIntLittleEndian(zip4jRaf);
if (signature == HeaderSignature.ZIP64_END_CENTRAL_DIRECTORY_LOCATOR.getValue()) {
@@ -525,22 +516,16 @@ public class HeaderReader {
return null;
}
- private void setFilePointerToReadZip64EndCentralDirLoc(RandomAccessFile zip4jRaf, RawIO rawIO) throws IOException {
- long pos = zip4jRaf.length() - ENDHDR;
-
- do {
- seekInCurrentPart(zip4jRaf, pos--);
- } while (rawIO.readIntLittleEndian(zip4jRaf) != HeaderSignature.END_OF_CENTRAL_DIRECTORY.getValue());
-
+ private void setFilePointerToReadZip64EndCentralDirLoc(RandomAccessFile zip4jRaf,
+ long offsetEndOfCentralDirectoryRecord) throws IOException {
// Now the file pointer is at the end of signature of Central Dir Rec
// Seek back with the following values
- // 4 -> end of central dir signature
// 4 -> total number of disks
// 8 -> relative offset of the zip64 end of central directory record
// 4 -> number of the disk with the start of the zip64 end of central directory
// 4 -> zip64 end of central dir locator signature
// Refer to Appnote for more information
- seekInCurrentPart(zip4jRaf, zip4jRaf.getFilePointer() - 4 - 4 - 8 - 4 - 4);
+ seekInCurrentPart(zip4jRaf, offsetEndOfCentralDirectoryRecord - 4 - 8 - 4 - 4);
}
public LocalFileHeader readLocalFileHeader(InputStream inputStream, Charset charset) throws IOException {
@@ -732,6 +717,32 @@ public class HeaderReader {
return zipModel.getEndOfCentralDirectoryRecord().getTotalNumberOfEntriesInCentralDirectory();
}
+ private long determineOffsetOfEndOfCentralDirectory(RandomAccessFile randomAccessFile) throws IOException {
+ byte[] buff = new byte[BUFF_SIZE];
+ long currentFilePointer = randomAccessFile.getFilePointer();
+
+ do {
+ int toRead = currentFilePointer > BUFF_SIZE ? BUFF_SIZE : (int) currentFilePointer;
+ // read 4 bytes again to make sure that the header is not spilled over
+ long seekPosition = currentFilePointer - toRead + 4;
+ if (seekPosition == 4) {
+ seekPosition = 0;
+ }
+
+ seekInCurrentPart(randomAccessFile, seekPosition);
+ randomAccessFile.read(buff, 0, toRead);
+ currentFilePointer = seekPosition;
+
+ for (int i = 0; i < toRead - 3; i++) {
+ if (rawIO.readIntLittleEndian(buff, i) == HeaderSignature.END_OF_CENTRAL_DIRECTORY.getValue()) {
+ return currentFilePointer + i;
+ }
+ }
+ } while (currentFilePointer > 0);
+
+ throw new ZipException("Zip headers not found. Probably not a zip file");
+ }
+
private void seekInCurrentPart(RandomAccessFile randomAccessFile, long pos) throws IOException {
if (randomAccessFile instanceof NumberedSplitRandomAccessFile) {
((NumberedSplitRandomAccessFile) randomAccessFile).seekInCurrentPart(pos);
@@ -739,4 +750,19 @@ public class HeaderReader {
randomAccessFile.seek(pos);
}
}
+
+ private String readZipComment(RandomAccessFile raf, int commentLength, Charset charset) {
+ if (commentLength <= 0) {
+ return null;
+ }
+
+ try {
+ byte[] commentBuf = new byte[commentLength];
+ raf.readFully(commentBuf);
+ return new String(commentBuf, charset);
+ } catch (IOException e) {
+ // Ignore any exception and set comment to null if comment cannot be read
+ return null;
+ }
+ }
}
=====================================
src/main/java/net/lingala/zip4j/headers/HeaderUtil.java
=====================================
@@ -64,19 +64,19 @@ public class HeaderUtil {
}
public static String decodeStringWithCharset(byte[] data, boolean isUtf8Encoded, Charset charset) {
- if(charset != null) {
- return new String(data, charset);
+ if (InternalZipConstants.CHARSET_UTF_8.equals(charset) && !isUtf8Encoded) {
+ try {
+ return new String(data, ZIP_STANDARD_CHARSET);
+ } catch (UnsupportedEncodingException e) {
+ return new String(data);
+ }
}
- if (isUtf8Encoded) {
- return new String(data, InternalZipConstants.CHARSET_UTF_8);
+ if(charset != null) {
+ return new String(data, charset);
}
- try {
- return new String(data, ZIP_STANDARD_CHARSET);
- } catch (UnsupportedEncodingException e) {
- return new String(data);
- }
+ return new String(data, InternalZipConstants.CHARSET_UTF_8);
}
=====================================
src/main/java/net/lingala/zip4j/model/EndOfCentralDirectoryRecord.java
=====================================
@@ -26,6 +26,7 @@ public class EndOfCentralDirectoryRecord extends ZipHeader {
private int totalNumberOfEntriesInCentralDirectory;
private int sizeOfCentralDirectory;
private long offsetOfStartOfCentralDirectory;
+ private long offsetOfEndOfCentralDirectory;
private String comment = "";
public EndOfCentralDirectoryRecord() {
@@ -81,6 +82,14 @@ public class EndOfCentralDirectoryRecord extends ZipHeader {
this.offsetOfStartOfCentralDirectory = offSetOfStartOfCentralDir;
}
+ public long getOffsetOfEndOfCentralDirectory() {
+ return offsetOfEndOfCentralDirectory;
+ }
+
+ public void setOffsetOfEndOfCentralDirectory(long offsetOfEndOfCentralDirectory) {
+ this.offsetOfEndOfCentralDirectory = offsetOfEndOfCentralDirectory;
+ }
+
public String getComment() {
return comment;
}
=====================================
src/test/java/net/lingala/zip4j/ExtractZipFileIT.java
=====================================
@@ -416,6 +416,50 @@ public class ExtractZipFileIT extends AbstractIT {
verifyZipFileByExtractingAllFiles(firstSplitFile, PASSWORD, outputFolder, 4);
}
+ @Test
+ public void testExtractDifferentPasswordsInSameZip() throws IOException {
+ ZipFile zipFile = new ZipFile(generatedZipFile);
+ addFileToZip(zipFile, "sample.pdf", EncryptionMethod.AES, "password1");
+ addFileToZip(zipFile, "sample_text1.txt", EncryptionMethod.AES, "password2");
+ addFileToZip(zipFile, "file_PDF_1MB.pdf", null, null);
+
+ zipFile.setPassword("password1".toCharArray());
+ zipFile.extractFile("sample.pdf", outputFolder.getPath());
+
+ zipFile.setPassword("password2".toCharArray());
+ zipFile.extractFile("sample_text1.txt", outputFolder.getPath());
+
+ zipFile.setPassword(null);
+ zipFile.extractFile("file_PDF_1MB.pdf", outputFolder.getPath());
+ }
+
+ @Test
+ public void testExtractZipFileWithCommentLengthGreaterThanZipFileLength() throws IOException {
+ verifyZipFileByExtractingAllFiles(getTestArchiveFromResources("zip_with_corrupt_comment_length.zip"), outputFolder, 1);
+ }
+
+ @Test
+ public void testExtractZipFileWithEndOfCentralDirectoryNotAtExpectedPosition() throws IOException {
+ ZipFile zipFile = new ZipFile(getTestArchiveFromResources("end_of_cen_dir_not_at_expected_position.zip"));
+ zipFile.extractAll(outputFolder.getPath());
+ List<File> outputFiles = FileUtils.getFilesInDirectoryRecursive(outputFolder, true, true);
+
+ assertThat(outputFiles).hasSize(24);
+ assertThat(zipFile.getFileHeaders()).hasSize(19);
+ }
+
+ private void addFileToZip(ZipFile zipFile, String fileName, EncryptionMethod encryptionMethod, String password) throws ZipException {
+ ZipParameters zipParameters = new ZipParameters();
+ zipParameters.setEncryptFiles(encryptionMethod != null);
+ zipParameters.setEncryptionMethod(encryptionMethod);
+
+ if (password != null) {
+ zipFile.setPassword(password.toCharArray());
+ }
+
+ zipFile.addFile(getTestFileFromResources(fileName), zipParameters);
+ }
+
private void testExtractNestedZipFileWithEncrpytion(EncryptionMethod innerZipEncryption,
EncryptionMethod outerZipEncryption) throws IOException {
File innerZipFile = temporaryFolder.newFile("inner.zip");
=====================================
src/test/java/net/lingala/zip4j/headers/HeaderReaderIT.java
=====================================
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@@ -39,7 +40,7 @@ public class HeaderReaderIT extends AbstractIT {
private HeaderWriter headerWriter = new HeaderWriter();
@Test
- public void testReadAllHeadersWith10Entries() throws IOException, ZipException {
+ public void testReadAllHeadersWith10Entries() throws IOException {
int numberOfEntries = 10;
ZipModel actualZipModel = generateZipHeadersFile(numberOfEntries, EncryptionMethod.NONE);
@@ -51,7 +52,7 @@ public class HeaderReaderIT extends AbstractIT {
}
@Test
- public void testReadAllHeadersWithEndOfCentralDirectoryComment() throws IOException, ZipException {
+ public void testReadAllHeadersWithEndOfCentralDirectoryComment() throws IOException {
ZipModel actualZipModel = generateZipModel(1);
actualZipModel.getEndOfCentralDirectoryRecord().setComment(END_OF_CENTRAL_DIR_COMMENT);
File headersFile = writeZipHeaders(actualZipModel);
@@ -98,7 +99,7 @@ public class HeaderReaderIT extends AbstractIT {
}
@Test
- public void testReadAllWithoutFileHeaderSignatureThrowsException() throws IOException, ZipException {
+ public void testReadAllWithoutFileHeaderSignatureThrowsException() throws IOException {
ZipModel actualZipModel = generateZipModel(2);
actualZipModel.getCentralDirectory().getFileHeaders().get(1).setSignature(HeaderSignature.DIGITAL_SIGNATURE);
File headersFile = writeZipHeaders(actualZipModel);
@@ -114,7 +115,7 @@ public class HeaderReaderIT extends AbstractIT {
}
@Test
- public void testReadAllWithFileNameContainsWindowsDriveExcludesIt() throws IOException, ZipException {
+ public void testReadAllWithFileNameContainsWindowsDriveExcludesIt() throws IOException {
String fileName = "C:\\test.txt";
ZipModel actualZipModel = generateZipModel(1);
actualZipModel.getCentralDirectory().getFileHeaders().get(0).setFileName(fileName);
@@ -130,7 +131,7 @@ public class HeaderReaderIT extends AbstractIT {
}
@Test
- public void testReadAllWithoutFileNameWritesNull() throws IOException, ZipException {
+ public void testReadAllWithoutFileNameWritesNull() throws IOException {
ZipModel actualZipModel = generateZipModel(1);
actualZipModel.getCentralDirectory().getFileHeaders().get(0).setFileName(null);
File headersFile = writeZipHeaders(actualZipModel);
@@ -145,24 +146,24 @@ public class HeaderReaderIT extends AbstractIT {
}
@Test
- public void testReadAllWithJapaneseCharacters() throws IOException, ZipException {
+ public void testReadAllWithJapaneseCharacters() throws IOException {
testWithoutUtf8FileName("公ゃ的年社", "育ざどろめ", true, false);
}
@Test
public void testReadAllWithoutUtf8FlagDecodesWithoutCharsetFlagForJapaneseCharactersDoesNotMatch()
- throws IOException, ZipException {
- testWithoutUtf8FileName("公ゃ的年社", "育ざどろめ", false, true);
+ throws IOException {
+ testWithoutUtf8FileName("公ゃ的年社", "育ざどろめ", false, true, InternalZipConstants.CHARSET_UTF_8);
}
@Test
public void testReadAllWithoutUtf8FlagDecodesWithoutCharsetFlagForEnglishCharactersMatches()
- throws IOException, ZipException {
+ throws IOException {
testWithoutUtf8FileName("SOME_TEXT", "SOME_COMMENT", true, true);
}
@Test
- public void testReadAllWithAesEncryption() throws ZipException, IOException {
+ public void testReadAllWithAesEncryption() throws IOException {
ZipModel actualZipModel = generateZipHeadersFile(3, EncryptionMethod.AES);
try(RandomAccessFile randomAccessFile = new RandomAccessFile(actualZipModel.getZipFile(),
@@ -176,7 +177,7 @@ public class HeaderReaderIT extends AbstractIT {
}
@Test
- public void testReadAllWithStandardZipEncryption() throws ZipException, IOException {
+ public void testReadAllWithStandardZipEncryption() throws IOException {
ZipModel actualZipModel = generateZipHeadersFile(3, EncryptionMethod.ZIP_STANDARD);
try(RandomAccessFile randomAccessFile = new RandomAccessFile(actualZipModel.getZipFile(),
@@ -191,7 +192,7 @@ public class HeaderReaderIT extends AbstractIT {
}
@Test
- public void testReadAllZip64Format() throws IOException, ZipException {
+ public void testReadAllZip64Format() throws IOException {
ZipModel actualZipModel = generateZipModel(1);
long entrySize = InternalZipConstants.ZIP_64_SIZE_LIMIT + 1;
actualZipModel.getCentralDirectory().getFileHeaders().get(0).setUncompressedSize(entrySize);
@@ -212,7 +213,7 @@ public class HeaderReaderIT extends AbstractIT {
}
@Test
- public void testReadLocalFileHeader() throws ZipException, IOException {
+ public void testReadLocalFileHeader() throws IOException {
long entrySize = InternalZipConstants.ZIP_64_SIZE_LIMIT + 1;
File headerFile = generateAndWriteLocalFileHeader(entrySize, EncryptionMethod.NONE);
@@ -225,7 +226,7 @@ public class HeaderReaderIT extends AbstractIT {
}
@Test
- public void testReadLocalFileHeaderWithAesEncryption() throws ZipException, IOException {
+ public void testReadLocalFileHeaderWithAesEncryption() throws IOException {
long entrySize = InternalZipConstants.ZIP_64_SIZE_LIMIT - 1001 ;
File headerFile = generateAndWriteLocalFileHeader(entrySize, EncryptionMethod.AES);
@@ -246,7 +247,12 @@ public class HeaderReaderIT extends AbstractIT {
}
private void testWithoutUtf8FileName(String fileName, String entryComment, boolean shouldFileNamesMatch,
- boolean unsetUtf8Flag) throws IOException, ZipException {
+ boolean unsetUtf8Flag) throws IOException {
+ testWithoutUtf8FileName(fileName, entryComment, shouldFileNamesMatch, unsetUtf8Flag, null);
+ }
+
+ private void testWithoutUtf8FileName(String fileName, String entryComment, boolean shouldFileNamesMatch,
+ boolean unsetUtf8Flag, Charset charsetToUseForReading) throws IOException {
ZipModel actualZipModel = generateZipModel(3);
FileHeader secondFileHeader = actualZipModel.getCentralDirectory().getFileHeaders().get(1);
@@ -264,7 +270,7 @@ public class HeaderReaderIT extends AbstractIT {
try(RandomAccessFile randomAccessFile = new RandomAccessFile(actualZipModel.getZipFile(),
RandomAccessFileMode.READ.getValue())) {
- ZipModel readZipModel = headerReader.readAllHeaders(randomAccessFile, null);
+ ZipModel readZipModel = headerReader.readAllHeaders(randomAccessFile, charsetToUseForReading);
FileHeader fileHeader = readZipModel.getCentralDirectory().getFileHeaders().get(1);
if (shouldFileNamesMatch) {
assertThat(fileHeader.getFileName()).isEqualTo(fileName);
@@ -326,7 +332,7 @@ public class HeaderReaderIT extends AbstractIT {
}
private ZipModel generateZipHeadersFile(int numberOfEntries, EncryptionMethod encryptionMethod)
- throws IOException, ZipException {
+ throws IOException {
ZipModel zipModel = generateZipModel(numberOfEntries, encryptionMethod);
File headersFile = writeZipHeaders(zipModel);
zipModel.setZipFile(headersFile);
@@ -377,7 +383,7 @@ public class HeaderReaderIT extends AbstractIT {
}
private File generateAndWriteLocalFileHeader(long entrySize, EncryptionMethod encryptionMethod)
- throws ZipException, IOException {
+ throws IOException {
LocalFileHeader localFileHeader = generateLocalFileHeader(entrySize, encryptionMethod);
if (encryptionMethod != null && encryptionMethod != EncryptionMethod.NONE) {
@@ -395,7 +401,7 @@ public class HeaderReaderIT extends AbstractIT {
return headerFile;
}
- private File writeZipHeaders(ZipModel zipModel) throws IOException, ZipException {
+ private File writeZipHeaders(ZipModel zipModel) throws IOException {
File headersFile = temporaryFolder.newFile();
try(SplitOutputStream splitOutputStream = new SplitOutputStream(headersFile)) {
headerWriter.finalizeZipFile(zipModel, splitOutputStream, InternalZipConstants.CHARSET_UTF_8);
=====================================
src/test/java/net/lingala/zip4j/headers/HeaderUtilTest.java
=====================================
@@ -224,11 +224,11 @@ public class HeaderUtilTest {
}
@Test
- public void testDecodeStringWithCharsetWithoutUtf8ForUtf8String() {
+ public void testDecodeStringWithCharsetWithUtf8ForUtf8String() {
String utf8StringToEncode = "asdäüöö";
byte[] utf8EncodedBytes = utf8StringToEncode.getBytes(InternalZipConstants.CHARSET_UTF_8);
- assertThat(HeaderUtil.decodeStringWithCharset(utf8EncodedBytes, false, null)).isNotEqualTo(utf8StringToEncode);
+ assertThat(HeaderUtil.decodeStringWithCharset(utf8EncodedBytes, false, InternalZipConstants.CHARSET_UTF_8)).isNotEqualTo(utf8StringToEncode);
}
=====================================
src/test/java/net/lingala/zip4j/headers/HeaderWriterIT.java
=====================================
@@ -109,9 +109,15 @@ public class HeaderWriterIT extends AbstractIT {
}
@Test
- public void testWriteLocalFileHeaderJapaneseCharactersInFileNameWithoutUtf8ShouldMatch()
+ public void testWriteLocalFileHeaderJapaneseCharactersInFileNameWithoutUtf8ShouldNotMatch()
throws IOException {
- testWriteLocalFileHeaderWithFileName("公ゃ的年社", false, true);
+ testWriteLocalFileHeaderWithFileName("公ゃ的年社", false, false);
+ }
+
+ @Test
+ public void testWriteLocalFileHeaderJapaneseCharactersInFileNameWithUtf8ShouldMatch()
+ throws IOException {
+ testWriteLocalFileHeaderWithFileName("公ゃ的年社", true, true);
}
@Test
@@ -129,7 +135,7 @@ public class HeaderWriterIT extends AbstractIT {
@Test
public void testWriteLocalFileHeaderJapaneseCharactersInFileNameWithUTF8CharsetWithoutUtf8ShouldMatch()
throws IOException {
- testWriteLocalFileHeaderWithFileNameAndCharset("公ゃ的年社", false, true, InternalZipConstants.CHARSET_UTF_8);
+ testWriteLocalFileHeaderWithFileNameAndCharset("公ゃ的年社", true, true, InternalZipConstants.CHARSET_UTF_8);
}
@Test
=====================================
src/test/resources/test-archives/end_of_cen_dir_not_at_expected_position.zip
=====================================
Binary files /dev/null and b/src/test/resources/test-archives/end_of_cen_dir_not_at_expected_position.zip differ
=====================================
src/test/resources/test-archives/zip_with_corrupt_comment_length.zip
=====================================
Binary files /dev/null and b/src/test/resources/test-archives/zip_with_corrupt_comment_length.zip differ
View it on GitLab: https://salsa.debian.org/java-team/zip4j/-/compare/e1bdb2158a2b2566df0550af8a90a57826394d8d...33de820a5d1b8319e40187c39e02fc04e2426f01
--
View it on GitLab: https://salsa.debian.org/java-team/zip4j/-/compare/e1bdb2158a2b2566df0550af8a90a57826394d8d...33de820a5d1b8319e40187c39e02fc04e2426f01
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20200501/7fb2341c/attachment.html>
More information about the pkg-java-commits
mailing list