You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ju...@apache.org on 2012/08/05 21:51:15 UTC
svn commit: r1369655 - in /commons/proper/compress/trunk/src:
main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
test/resources/COMPRESS-197.tar
Author: jukka
Date: Sun Aug 5 19:51:15 2012
New Revision: 1369655
URL: http://svn.apache.org/viewvc?rev=1369655&view=rev
Log:
COMPRESS-197: Tar file for Android backup cannot be read
Allow more than one or two NUL or space characters at the end of a field
Added:
commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar
Modified:
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
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=1369655&r1=1369654&r2=1369655&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 Sun Aug 5 19:51:15 2012
@@ -130,10 +130,11 @@ public class TarUtils {
throw new IllegalArgumentException(
exceptionMessage(buffer, offset, length, end-1, trailer));
}
- // May have additional NUL or space
- trailer = buffer[end-1];
- if (trailer == 0 || trailer == ' '){
+ // May have additional NULs or spaces
+ trailer = buffer[end - 1];
+ while (start < end - 1 && (trailer == 0 || trailer == ' ')) {
end--;
+ trailer = buffer[end - 1];
}
for ( ;start < end; start++) {
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=1369655&r1=1369654&r2=1369655&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 Sun Aug 5 19:51:15 2012
@@ -20,10 +20,12 @@ package org.apache.commons.compress.arch
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Calendar;
@@ -120,4 +122,24 @@ public class TarArchiveInputStreamTest {
}
}
-}
\ No newline at end of file
+ @Test
+ public void testCompress197() throws Exception {
+ TarArchiveInputStream tar = getTestStream("/COMPRESS-197.tar");
+ try {
+ TarArchiveEntry entry = tar.getNextTarEntry();
+ while (entry != null) {
+ entry = tar.getNextTarEntry();
+ }
+ } catch (IOException e) {
+ fail("COMPRESS-197: " + e.getMessage());
+ } finally {
+ tar.close();
+ }
+ }
+
+ private TarArchiveInputStream getTestStream(String name) {
+ return new TarArchiveInputStream(
+ TarArchiveInputStreamTest.class.getResourceAsStream(name));
+ }
+
+}
Added: commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar?rev=1369655&view=auto
==============================================================================
Files commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar (added) and commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar Sun Aug 5 19:51:15 2012 differ
Re: svn commit: r1369655 - in /commons/proper/compress/trunk/src:
main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
test/resources/COMPRESS-197.tar
Posted by sebb <se...@gmail.com>.
On 5 August 2012 20:51, <ju...@apache.org> wrote:
> Author: jukka
> Date: Sun Aug 5 19:51:15 2012
> New Revision: 1369655
>
> URL: http://svn.apache.org/viewvc?rev=1369655&view=rev
> Log:
> COMPRESS-197: Tar file for Android backup cannot be read
>
> Allow more than one or two NUL or space characters at the end of a field
>
> Added:
> commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar
> Modified:
> 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
>
> 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=1369655&r1=1369654&r2=1369655&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 Sun Aug 5 19:51:15 2012
> @@ -130,10 +130,11 @@ public class TarUtils {
> throw new IllegalArgumentException(
> exceptionMessage(buffer, offset, length, end-1, trailer));
> }
> - // May have additional NUL or space
> - trailer = buffer[end-1];
> - if (trailer == 0 || trailer == ' '){
> + // May have additional NULs or spaces
The Javadoc also needs adjusting please.
> + trailer = buffer[end - 1];
> + while (start < end - 1 && (trailer == 0 || trailer == ' ')) {
> end--;
> + trailer = buffer[end - 1];
> }
>
> for ( ;start < end; start++) {
>
> 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=1369655&r1=1369654&r2=1369655&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 Sun Aug 5 19:51:15 2012
> @@ -20,10 +20,12 @@ package org.apache.commons.compress.arch
>
> import static org.junit.Assert.assertEquals;
> import static org.junit.Assert.assertTrue;
> +import static org.junit.Assert.fail;
>
> import java.io.ByteArrayInputStream;
> import java.io.File;
> import java.io.FileInputStream;
> +import java.io.IOException;
> import java.net.URI;
> import java.net.URL;
> import java.util.Calendar;
> @@ -120,4 +122,24 @@ public class TarArchiveInputStreamTest {
> }
> }
>
> -}
> \ No newline at end of file
> + @Test
> + public void testCompress197() throws Exception {
> + TarArchiveInputStream tar = getTestStream("/COMPRESS-197.tar");
> + try {
> + TarArchiveEntry entry = tar.getNextTarEntry();
> + while (entry != null) {
> + entry = tar.getNextTarEntry();
> + }
> + } catch (IOException e) {
> + fail("COMPRESS-197: " + e.getMessage());
> + } finally {
> + tar.close();
> + }
> + }
> +
> + private TarArchiveInputStream getTestStream(String name) {
> + return new TarArchiveInputStream(
> + TarArchiveInputStreamTest.class.getResourceAsStream(name));
> + }
> +
> +}
>
> Added: commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar
> URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar?rev=1369655&view=auto
> ==============================================================================
> Files commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar (added) and commons/proper/compress/trunk/src/test/resources/COMPRESS-197.tar Sun Aug 5 19:51:15 2012 differ
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org