Skip to content

Commit

Permalink
Ignoring bad extra field entry error for permission extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
toomasr committed Mar 4, 2022
1 parent be22f0e commit 4c49082
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
ZT Zip Changelog
********************************************

1.15 (4th Mar 2022)
* Changed to ignore bad extra field entry error for permission extraction

1.14 (10th Feb 2020)
* Added removeEntries that copies to OutputStream
* Added createEmpty
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/org/zeroturnaround/zip/ZipUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1179,9 +1179,19 @@ public void process(InputStream in, ZipEntry zipEntry) throws IOException {
FileUtils.copy(in, file);
}

ZTFilePermissions permissions = ZipEntryUtil.getZTFilePermissions(zipEntry);
if (permissions != null) {
ZTFilePermissionsUtil.getDefaultStategy().setPermissions(file, permissions);
try {
ZTFilePermissions permissions = ZipEntryUtil.getZTFilePermissions(zipEntry);
if (permissions != null) {
ZTFilePermissionsUtil.getDefaultStategy().setPermissions(file, permissions);
}
}
catch (ZipException e) {
/*
* We are not bubbling this exception because there is a case where yes
* the file has problems with permissions and there is a block length that
* does not match but the other tooling like zip, jar and other just unpacks
* the files and does not use the permission information.
* */
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/org/zeroturnaround/zip/BrokenJarTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.zeroturnaround.zip;

/**
* Copyright (C) 2012 ZeroTurnaround LLC <support@zeroturnaround.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.File;
import java.nio.file.Files;

import junit.framework.TestCase;

public class BrokenJarTest extends TestCase {
private static final File file = new File("src/test/resources/scalactic_2.13-3.2.5.jar");

public void testZipFileWithBrokenPermissions() throws Exception {
File tmpDir = Files.createTempDirectory("zt-zip-tests").toFile();
ZipUtil.unpack(file, tmpDir);
}
}
Binary file added src/test/resources/scalactic_2.13-3.2.5.jar
Binary file not shown.

0 comments on commit 4c49082

Please sign in to comment.