You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/05/30 13:54:15 UTC
(commons-compress) branch master updated (a1aa91a83 -> 07988ea07)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
from a1aa91a83 Javadoc
new 472376413 Javadoc
new 7caadbf8c Inline local variable initialization
new e56aa4fb7 Javadoc
new 07988ea07 [COMPRESS-699] ArchiveStreamFactory.detect(inputStream) ArchiveException for TAR regression
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/changes/changes.xml | 1 +
.../archivers/tar/TarArchiveInputStream.java | 10 ++
.../compress/archivers/tar/TarConstants.java | 14 ++-
.../commons/compress/utils/ArchiveUtils.java | 119 ++++++++++-----------
.../commons/compress/DetectArchiverTest.java | 2 +-
.../tar/Compress699Test.java} | 33 +++---
.../icure_medical_device_dart_sdk-1.2.10.tar | Bin 0 -> 936448 bytes
7 files changed, 97 insertions(+), 82 deletions(-)
copy src/test/java/org/apache/commons/compress/{compressors/bzip2/BZip2NSelectorsOverflowTest.java => archivers/tar/Compress699Test.java} (54%)
create mode 100644 src/test/resources/org/apache/commons/compress/COMPRESS-699/icure_medical_device_dart_sdk-1.2.10.tar
(commons-compress) 01/04: Javadoc
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 4723764136b94fbd354af0cce98b950999129c7c
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri May 30 08:52:38 2025 -0400
Javadoc
---
.../commons/compress/archivers/tar/TarConstants.java | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
index b2195dda9..8bdfd3332 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
@@ -28,10 +28,14 @@
// CheckStyle:InterfaceIsTypeCheck OFF (bc)
public interface TarConstants {
- /** Default record size */
+ /**
+ * Default record size.
+ */
int DEFAULT_RCDSIZE = 512;
- /** Default block size */
+ /**
+ * Default block size.
+ */
int DEFAULT_BLKSIZE = DEFAULT_RCDSIZE * 20;
/**
@@ -98,13 +102,17 @@ public interface TarConstants {
/** Offset of start of magic field within header record */
int MAGIC_OFFSET = 257;
+
/**
* The length of the magic field in a header buffer.
*/
int MAGICLEN = 6;
- /** Offset of start of magic field within header record */
+ /**
+ * Offset of start of magic field within header record.
+ */
int VERSION_OFFSET = 263;
+
/**
* Previously this was regarded as part of "magic" field, but it is separate.
*/
(commons-compress) 03/04: Javadoc
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit e56aa4fb7435a7db730bd7a4ee37fb4db5a77afa
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri May 30 09:02:46 2025 -0400
Javadoc
---
.../commons/compress/utils/ArchiveUtils.java | 116 ++++++++++-----------
1 file changed, 58 insertions(+), 58 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java b/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java
index 1080bc518..88e2ff5e9 100644
--- a/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java
+++ b/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java
@@ -33,11 +33,11 @@ public class ArchiveUtils {
private static final int MAX_SANITIZED_NAME_LENGTH = 255;
/**
- * Returns true if the first N bytes of an array are all zero
+ * Returns true if the first N bytes of an array are all zero.
*
- * @param a The array to check
- * @param size The number of characters to check (not the size of the array)
- * @return true if the first N bytes are zero
+ * @param a The array to check.
+ * @param size The number of characters to check (not the size of the array).
+ * @return true if the first N bytes are zero.
*/
public static boolean isArrayZero(final byte[] a, final int size) {
for (int i = 0; i < size; i++) {
@@ -49,11 +49,11 @@ public static boolean isArrayZero(final byte[] a, final int size) {
}
/**
- * Compare byte buffers
+ * Compare byte buffers.
*
- * @param buffer1 the first buffer
- * @param buffer2 the second buffer
- * @return {@code true} if buffer1 and buffer2 have same contents
+ * @param buffer1 the first buffer.
+ * @param buffer2 the second buffer.
+ * @return {@code true} if buffer1 and buffer2 have same contents.
* @deprecated Use {@link Arrays#equals(byte[], byte[])}.
*/
@Deprecated
@@ -62,43 +62,43 @@ public static boolean isEqual(final byte[] buffer1, final byte[] buffer2) {
}
/**
- * Compare byte buffers, optionally ignoring trailing nulls
+ * Compare byte buffers, optionally ignoring trailing nulls.
*
- * @param buffer1 the first buffer
- * @param buffer2 the second buffer
- * @param ignoreTrailingNulls whether to ignore trailing nulls
- * @return {@code true} if buffer1 and buffer2 have same contents
+ * @param buffer1 the first buffer.
+ * @param buffer2 the second buffer.
+ * @param ignoreTrailingNulls whether to ignore trailing nulls.
+ * @return {@code true} if buffer1 and buffer2 have same contents.
*/
public static boolean isEqual(final byte[] buffer1, final byte[] buffer2, final boolean ignoreTrailingNulls) {
return isEqual(buffer1, 0, buffer1.length, buffer2, 0, buffer2.length, ignoreTrailingNulls);
}
/**
- * Compare byte buffers
+ * Compare byte buffers.
*
- * @param buffer1 the first buffer
- * @param offset1 the first offset
- * @param length1 the first length
- * @param buffer2 the second buffer
- * @param offset2 the second offset
- * @param length2 the second length
- * @return {@code true} if buffer1 and buffer2 have same contents
+ * @param buffer1 the first buffer.
+ * @param offset1 the first offset.
+ * @param length1 the first length.
+ * @param buffer2 the second buffer.
+ * @param offset2 the second offset.
+ * @param length2 the second length.
+ * @return {@code true} if buffer1 and buffer2 have same contents.
*/
public static boolean isEqual(final byte[] buffer1, final int offset1, final int length1, final byte[] buffer2, final int offset2, final int length2) {
return isEqual(buffer1, offset1, length1, buffer2, offset2, length2, false);
}
/**
- * Compare byte buffers, optionally ignoring trailing nulls
+ * Compare byte buffers, optionally ignoring trailing nulls.
*
- * @param buffer1 first buffer
- * @param offset1 first offset
- * @param length1 first length
- * @param buffer2 second buffer
- * @param offset2 second offset
- * @param length2 second length
- * @param ignoreTrailingNulls whether to ignore trailing nulls
- * @return {@code true} if buffer1 and buffer2 have same contents, having regard to trailing nulls
+ * @param buffer1 first buffer.
+ * @param offset1 first offset.
+ * @param length1 first length.
+ * @param buffer2 second buffer.
+ * @param offset2 second offset.
+ * @param length2 second length.
+ * @param ignoreTrailingNulls whether to ignore trailing nulls.
+ * @return {@code true} if buffer1 and buffer2 have same contents, having regard to trailing nulls.
*/
public static boolean isEqual(final byte[] buffer1, final int offset1, final int length1, final byte[] buffer2, final int offset2, final int length2,
final boolean ignoreTrailingNulls) {
@@ -131,15 +131,15 @@ public static boolean isEqual(final byte[] buffer1, final int offset1, final int
}
/**
- * Compare byte buffers, ignoring trailing nulls
+ * Compare byte buffers, ignoring trailing nulls.
*
- * @param buffer1 the first buffer
- * @param offset1 the first offset
- * @param length1 the first length
- * @param buffer2 the second buffer
- * @param offset2 the second offset
- * @param length2 the second length
- * @return {@code true} if buffer1 and buffer2 have same contents, having regard to trailing nulls
+ * @param buffer1 the first buffer.
+ * @param offset1 the first offset.
+ * @param length1 the first length.
+ * @param buffer2 the second buffer.
+ * @param offset2 the second offset.
+ * @param length2 the second length.
+ * @return {@code true} if buffer1 and buffer2 have same contents, having regard to trailing nulls.
*/
public static boolean isEqualWithNull(final byte[] buffer1, final int offset1, final int length1, final byte[] buffer2, final int offset2,
final int length2) {
@@ -149,9 +149,9 @@ public static boolean isEqualWithNull(final byte[] buffer1, final int offset1, f
/**
* Check if buffer contents matches ASCII String.
*
- * @param expected the expected string
- * @param buffer the buffer
- * @return {@code true} if buffer is the same as the expected string
+ * @param expected the expected string.
+ * @param buffer the buffer.
+ * @return {@code true} if buffer is the same as the expected string.
*/
public static boolean matchAsciiBuffer(final String expected, final byte[] buffer) {
return matchAsciiBuffer(expected, buffer, 0, buffer.length);
@@ -160,11 +160,11 @@ public static boolean matchAsciiBuffer(final String expected, final byte[] buffe
/**
* Check if buffer contents matches ASCII String.
*
- * @param expected expected string
- * @param buffer the buffer
- * @param offset offset to read from
- * @param length length of the buffer
- * @return {@code true} if buffer is the same as the expected string
+ * @param expected expected string.
+ * @param buffer the buffer.
+ * @param offset offset to read from.
+ * @param length length of the buffer.
+ * @return {@code true} if buffer is the same as the expected string.
*/
public static boolean matchAsciiBuffer(final String expected, final byte[] buffer, final int offset, final int length) {
final byte[] buffer1 = expected.getBytes(US_ASCII);
@@ -180,8 +180,8 @@ public static boolean matchAsciiBuffer(final String expected, final byte[] buffe
* been read from a corrupted input.
* </p>
*
- * @param s the string to sanitize
- * @return a sanitized version of the argument
+ * @param s the string to sanitize.
+ * @return a sanitized version of the argument.
* @since 1.12
*/
public static String sanitize(final String s) {
@@ -207,8 +207,8 @@ public static String sanitize(final String s) {
/**
* Convert a string to ASCII bytes. Used for comparing "magic" strings which need to be independent of the default Locale.
*
- * @param inputString string to convert
- * @return the bytes
+ * @param inputString string to convert.
+ * @return the bytes.
*/
public static byte[] toAsciiBytes(final String inputString) {
return inputString.getBytes(US_ASCII);
@@ -217,8 +217,8 @@ public static byte[] toAsciiBytes(final String inputString) {
/**
* Convert an input byte array to a String using the ASCII character set.
*
- * @param inputBytes bytes to convert
- * @return the bytes, interpreted as an ASCII string
+ * @param inputBytes bytes to convert.
+ * @return the bytes, interpreted as an ASCII string.
*/
public static String toAsciiString(final byte[] inputBytes) {
return new String(inputBytes, US_ASCII);
@@ -227,10 +227,10 @@ public static String toAsciiString(final byte[] inputBytes) {
/**
* Convert an input byte array to a String using the ASCII character set.
*
- * @param inputBytes input byte array
- * @param offset offset within array
- * @param length length of array
- * @return the bytes, interpreted as an ASCII string
+ * @param inputBytes input byte array.
+ * @param offset offset within array.
+ * @param length length of array.
+ * @return the bytes, interpreted as an ASCII string.
*/
public static String toAsciiString(final byte[] inputBytes, final int offset, final int length) {
return new String(inputBytes, offset, length, US_ASCII);
@@ -246,8 +246,8 @@ public static String toAsciiString(final byte[] inputBytes, final int offset, fi
* d 100 testfiles
* </pre>
*
- * @param entry the entry
- * @return the representation of the entry
+ * @param entry the entry.
+ * @return the representation of the entry.
*/
public static String toString(final ArchiveEntry entry) {
final StringBuilder sb = new StringBuilder();
(commons-compress) 04/04: [COMPRESS-699] ArchiveStreamFactory.detect(inputStream) ArchiveException for TAR regression
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 07988ea07f1eb7e008c0086a3ed80165366f6637
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri May 30 09:54:08 2025 -0400
[COMPRESS-699] ArchiveStreamFactory.detect(inputStream) ArchiveException
for TAR regression
---
src/changes/changes.xml | 1 +
.../archivers/tar/TarArchiveInputStream.java | 10 +++++
.../commons/compress/DetectArchiverTest.java | 2 +-
.../compress/archivers/tar/Compress699Test.java | 44 +++++++++++++++++++++
.../icure_medical_device_dart_sdk-1.2.10.tar | Bin 0 -> 936448 bytes
5 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 47a4904f1..27b152a5c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -96,6 +96,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">ArArchiveInputStream.getBSDLongName(String) now throws its EOFException with a message.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">ZipEncodingHelper.getZipEncoding(*) can throw NullPointerException and IllegalArgumentException on bad input instead of returning a value using the default Charset.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Javadoc improvements throughout.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory" issue= "COMPRESS-699">ArchiveStreamFactory.detect(inputStream) ArchiveException for TAR regression.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index 7761c6362..c24c6106c 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -50,6 +50,11 @@
*/
public class TarArchiveInputStream extends ArchiveInputStream<TarArchiveEntry> {
+ /**
+ * IBM AIX <a href=""https://www.ibm.com/docs/sv/aix/7.2.0?topic=files-tarh-file">tar.h</a>: "This field is terminated with a space only."
+ */
+ private static final String VERSION_AIX = "0 ";
+
private static final int SMALL_BUFFER_SIZE = 256;
/**
@@ -72,6 +77,11 @@ public static boolean matches(final byte[] signature, final int length) {
&& ArchiveUtils.matchAsciiBuffer(TarConstants.VERSION_POSIX, signature, versionOffset, versionLen)) {
return true;
}
+ // IBM AIX tar.h https://www.ibm.com/docs/sv/aix/7.2.0?topic=files-tarh-file : "This field is terminated with a space only."
+ if (ArchiveUtils.matchAsciiBuffer(TarConstants.MAGIC_POSIX, signature, magicOffset, magicLen)
+ && ArchiveUtils.matchAsciiBuffer(VERSION_AIX, signature, versionOffset, versionLen)) {
+ return true;
+ }
if (ArchiveUtils.matchAsciiBuffer(TarConstants.MAGIC_GNU, signature, magicOffset, magicLen)
&& (ArchiveUtils.matchAsciiBuffer(TarConstants.VERSION_GNU_SPACE, signature, versionOffset, versionLen)
|| ArchiveUtils.matchAsciiBuffer(TarConstants.VERSION_GNU_ZERO, signature, versionOffset, versionLen))) {
diff --git a/src/test/java/org/apache/commons/compress/DetectArchiverTest.java b/src/test/java/org/apache/commons/compress/DetectArchiverTest.java
index 71c3dfff7..f6c96a000 100644
--- a/src/test/java/org/apache/commons/compress/DetectArchiverTest.java
+++ b/src/test/java/org/apache/commons/compress/DetectArchiverTest.java
@@ -177,7 +177,7 @@ public void testEmptyZipArchive() throws Exception {
* Tests COMPRESS-644.
*/
@Test
- public void testIgnoreZeroByteEntryInTarDetect() {
+ public void testIcoFile() {
assertThrows(ArchiveException.class, () -> {
try (InputStream in = createBufferedInputStream("org/apache/commons/compress/COMPRESS-644/ARW05UP.ICO")) {
assertNull(ArchiveStreamFactory.detect(in));
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/Compress699Test.java b/src/test/java/org/apache/commons/compress/archivers/tar/Compress699Test.java
new file mode 100644
index 000000000..30dcd32a9
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/Compress699Test.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * https://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.
+ */
+
+package org.apache.commons.compress.archivers.tar;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.BufferedInputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
+import org.junit.Test;
+
+/**
+ * Tests https://issues.apache.org/jira/browse/COMPRESS-699
+ */
+public class Compress699Test {
+
+ @Test
+ public void testTarArchive() throws Exception {
+ final Path fileToTest = Paths.get("src/test/resources/org/apache/commons/compress/COMPRESS-699/icure_medical_device_dart_sdk-1.2.10.tar");
+ try (BufferedInputStream fileInputStream = new BufferedInputStream(Files.newInputStream(fileToTest))) {
+ assertEquals("tar", ArchiveStreamFactory.detect(fileInputStream));
+ }
+ }
+}
diff --git a/src/test/resources/org/apache/commons/compress/COMPRESS-699/icure_medical_device_dart_sdk-1.2.10.tar b/src/test/resources/org/apache/commons/compress/COMPRESS-699/icure_medical_device_dart_sdk-1.2.10.tar
new file mode 100644
index 000000000..6f5bdf789
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/COMPRESS-699/icure_medical_device_dart_sdk-1.2.10.tar differ
(commons-compress) 02/04: Inline local variable initialization
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 7caadbf8c05a14dd550a658bbb7586d17bb1c467
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri May 30 09:00:49 2025 -0400
Inline local variable initialization
---
src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java b/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java
index ca4a7cd75..1080bc518 100644
--- a/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java
+++ b/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java
@@ -167,8 +167,7 @@ public static boolean matchAsciiBuffer(final String expected, final byte[] buffe
* @return {@code true} if buffer is the same as the expected string
*/
public static boolean matchAsciiBuffer(final String expected, final byte[] buffer, final int offset, final int length) {
- final byte[] buffer1;
- buffer1 = expected.getBytes(US_ASCII);
+ final byte[] buffer1 = expected.getBytes(US_ASCII);
return isEqual(buffer1, 0, buffer1.length, buffer, offset, length, false);
}