From commits-return-25608-apmail-commons-commits-archive=commons.apache.org@commons.apache.org Fri Mar 2 20:00:16 2012 Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 475C3926A for ; Fri, 2 Mar 2012 20:00:16 +0000 (UTC) Received: (qmail 30350 invoked by uid 500); 2 Mar 2012 20:00:16 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 30266 invoked by uid 500); 2 Mar 2012 20:00:16 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 30259 invoked by uid 99); 2 Mar 2012 20:00:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2012 20:00:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2012 20:00:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3861F2388980 for ; Fri, 2 Mar 2012 19:59:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1296420 - in /commons/proper/compress/trunk/src: changes/ main/java/org/apache/commons/compress/archivers/tar/ test/java/org/apache/commons/compress/archivers/tar/ test/resources/ Date: Fri, 02 Mar 2012 19:59:51 -0000 To: commits@commons.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120302195951.3861F2388980@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bodewig Date: Fri Mar 2 19:59:50 2012 New Revision: 1296420 URL: http://svn.apache.org/viewvc?rev=1296420&view=rev Log: workaround for tar implementations that insert a NUL byte into header fields. COMPRESS-181 Added: commons/proper/compress/trunk/src/test/resources/simple-aix-native-tar.tar (with props) Modified: commons/proper/compress/trunk/src/changes/changes.xml commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java Modified: commons/proper/compress/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1296420&r1=1296419&r2=1296420&view=diff ============================================================================== --- commons/proper/compress/trunk/src/changes/changes.xml (original) +++ commons/proper/compress/trunk/src/changes/changes.xml Fri Mar 2 19:59:50 2012 @@ -46,6 +46,10 @@ The type attribute can be add,u + + Added a workaround for a Bug some tar implementations that add + a NUL byte as first byte in numeric header fields. + Added a workaround for a Bug in WinZIP which uses backslashes as path separators in Unicode Extra Fields. Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java?rev=1296420&r1=1296419&r2=1296420&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java Fri Mar 2 19:59:50 2012 @@ -34,13 +34,18 @@ public class TarUtils { /** * Parse an octal string from a buffer. - * Leading spaces are ignored. + * + *

Leading spaces are ignored. * The buffer must contain a trailing space or NUL, - * and may contain an additional trailing space or NUL. + * and may contain an additional trailing space or NUL.

* - * The input buffer is allowed to contain all NULs, + *

The input buffer is allowed to contain all NULs, * in which case the method returns 0L - * (this allows for missing fields). + * (this allows for missing fields).

+ * + *

To work-around some tar implementations that insert a + * leading NUL this method returns 0 if it detects a leading NUL + * since Commons Compress 1.4.

* * @param buffer The buffer from which to parse. * @param offset The offset into the buffer from which to parse. @@ -57,14 +62,7 @@ public class TarUtils { throw new IllegalArgumentException("Length "+length+" must be at least 2"); } - boolean allNUL = true; - for (int i = start; i < end; i++){ - if (buffer[i] != 0){ - allNUL = false; - break; - } - } - if (allNUL) { + if (buffer[start] == 0) { return 0L; } Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java?rev=1296420&r1=1296419&r2=1296420&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java Fri Mar 2 19:59:50 2012 @@ -18,10 +18,16 @@ package org.apache.commons.compress.archivers.tar; +import java.io.File; +import java.io.FileInputStream; import java.io.StringReader; +import java.net.URI; +import java.net.URL; +import java.util.Date; import java.util.Map; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class TarArchiveInputStreamTest { @@ -40,4 +46,23 @@ public class TarArchiveInputStreamTest { assertEquals(1, headers.size()); assertEquals("line1\nline2\nand3", headers.get("comment")); } + + @Test + public void workaroundForBrokenTimeHeader() throws Exception { + URL tar = getClass().getResource("/simple-aix-native-tar.tar"); + TarArchiveInputStream in = null; + try { + in = new TarArchiveInputStream(new FileInputStream(new File(new URI(tar.toString())))); + TarArchiveEntry tae = in.getNextTarEntry(); + tae = in.getNextTarEntry(); + assertEquals("sample/link-to-txt-file.lnk", tae.getName()); + assertEquals(new Date(0), tae.getLastModifiedDate()); + assertTrue(tae.isSymbolicLink()); + } finally { + if (in != null) { + in.close(); + } + } + } + } \ No newline at end of file Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java?rev=1296420&r1=1296419&r2=1296420&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java Fri Mar 2 19:59:50 2012 @@ -72,12 +72,6 @@ public class TarUtilsTest extends TestCa fail("Expected IllegalArgumentException - should be at least 2 bytes long"); } catch (IllegalArgumentException expected) { } - buffer=new byte[]{0,0,' '}; // not all NULs - try { - TarUtils.parseOctal(buffer,0, buffer.length); - fail("Expected IllegalArgumentException - not all NULs"); - } catch (IllegalArgumentException expected) { - } buffer=new byte[]{' ',0,0,0}; // not all NULs try { TarUtils.parseOctal(buffer,0, buffer.length); Added: commons/proper/compress/trunk/src/test/resources/simple-aix-native-tar.tar URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/resources/simple-aix-native-tar.tar?rev=1296420&view=auto ============================================================================== Binary file - no diff available. Propchange: commons/proper/compress/trunk/src/test/resources/simple-aix-native-tar.tar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream