This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push:
new 46a7712c7 Sort members
46a7712c7 is described below
commit 46a7712c730ad8dc212da9ea0f6baa73d341cae3
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Jul 17 17:02:42 2026 -0700
Sort members
---
.../compress/archivers/tar/PaxHeaderOomTest.java | 76 +++++++++++-----------
.../zip/X0015_X0016_CertificateIdTest.java | 12 ++--
2 files changed, 44 insertions(+), 44 deletions(-)
diff --git
a/src/test/java/org/apache/commons/compress/archivers/tar/PaxHeaderOomTest.java
b/src/test/java/org/apache/commons/compress/archivers/tar/PaxHeaderOomTest.java
index bb0a43c98..52830ff7f 100644
---
a/src/test/java/org/apache/commons/compress/archivers/tar/PaxHeaderOomTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/tar/PaxHeaderOomTest.java
@@ -49,6 +49,33 @@ private static byte[] buildTarGzWithPaxValue(final long
valueSize) throws IOExce
return buf.toByteArray();
}
+ private static int pad(final long len) {
+ final int rem = (int) (len % BLOCK);
+ return rem == 0 ? 0 : BLOCK - rem;
+ }
+
+ private static byte[] tarHeader(final String name, final long size, final
byte type) {
+ final byte[] h = new byte[BLOCK];
+ System.arraycopy(name.getBytes(StandardCharsets.UTF_8), 0, h, 0,
Math.min(name.length(), 100));
+ System.arraycopy("0000644\0".getBytes(), 0, h, 100, 8);
+ System.arraycopy("0000000\0".getBytes(), 0, h, 108, 8);
+ System.arraycopy("0000000\0".getBytes(), 0, h, 116, 8);
+ System.arraycopy(String.format("%011o", size).getBytes(), 0, h, 124,
11);
+ h[135] = 0;
+ System.arraycopy("00000000000\0".getBytes(), 0, h, 136, 12);
+ h[156] = type;
+ System.arraycopy("ustar\0".getBytes(), 0, h, 257, 6);
+ h[263] = '0';
+ h[264] = '0';
+ Arrays.fill(h, 148, 156, (byte) ' ');
+ long chk = 0;
+ for (final byte b : h) {
+ chk += b & 0xFF;
+ }
+ System.arraycopy(String.format("%06o\0 ", chk).getBytes(), 0, h, 148,
8);
+ return h;
+ }
+
private static void writeTar(final OutputStream out, final long valueSize)
throws IOException {
final String keyword = "test.data";
final long fixedPart = 1L + keyword.length() + 1 + 1;
@@ -80,44 +107,6 @@ private static void writeTar(final OutputStream out, final
long valueSize) throw
out.write(new byte[BLOCK * 2]);
}
- private static byte[] tarHeader(final String name, final long size, final
byte type) {
- final byte[] h = new byte[BLOCK];
- System.arraycopy(name.getBytes(StandardCharsets.UTF_8), 0, h, 0,
Math.min(name.length(), 100));
- System.arraycopy("0000644\0".getBytes(), 0, h, 100, 8);
- System.arraycopy("0000000\0".getBytes(), 0, h, 108, 8);
- System.arraycopy("0000000\0".getBytes(), 0, h, 116, 8);
- System.arraycopy(String.format("%011o", size).getBytes(), 0, h, 124,
11);
- h[135] = 0;
- System.arraycopy("00000000000\0".getBytes(), 0, h, 136, 12);
- h[156] = type;
- System.arraycopy("ustar\0".getBytes(), 0, h, 257, 6);
- h[263] = '0';
- h[264] = '0';
- Arrays.fill(h, 148, 156, (byte) ' ');
- long chk = 0;
- for (final byte b : h) {
- chk += b & 0xFF;
- }
- System.arraycopy(String.format("%06o\0 ", chk).getBytes(), 0, h, 148,
8);
- return h;
- }
-
- private static int pad(final long len) {
- final int rem = (int) (len % BLOCK);
- return rem == 0 ? 0 : BLOCK - rem;
- }
-
- @Test
- void testDefaultLimitRejectsOversizedPaxHeader() throws Exception {
- final byte[] tgz = buildTarGzWithPaxValue(20L * 1024 * 1024);
- try (TarArchiveInputStream tis = new TarArchiveInputStream(
- new GZIPInputStream(new ByteArrayInputStream(tgz)))) {
- tis.getNextEntry();
- fail("Should have thrown MemoryLimitException");
- } catch (final MemoryLimitException ignored) {
- }
- }
-
@Test
void testCustomLimitAllowsHeader() throws Exception {
final byte[] tgz = buildTarGzWithPaxValue(1024);
@@ -142,4 +131,15 @@ void testDefaultLimitAllowsNormalHeader() throws Exception
{
assertEquals("entry.txt", entry.getName());
}
}
+
+ @Test
+ void testDefaultLimitRejectsOversizedPaxHeader() throws Exception {
+ final byte[] tgz = buildTarGzWithPaxValue(20L * 1024 * 1024);
+ try (TarArchiveInputStream tis = new TarArchiveInputStream(
+ new GZIPInputStream(new ByteArrayInputStream(tgz)))) {
+ tis.getNextEntry();
+ fail("Should have thrown MemoryLimitException");
+ } catch (final MemoryLimitException ignored) {
+ }
+ }
}
diff --git
a/src/test/java/org/apache/commons/compress/archivers/zip/X0015_X0016_CertificateIdTest.java
b/src/test/java/org/apache/commons/compress/archivers/zip/X0015_X0016_CertificateIdTest.java
index c04e97d64..c822d88a4 100644
---
a/src/test/java/org/apache/commons/compress/archivers/zip/X0015_X0016_CertificateIdTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/zip/X0015_X0016_CertificateIdTest.java
@@ -41,6 +41,12 @@ void testX0015ReadsFourByteRecordCountAndHashAlg() throws
ZipException {
assertEquals(HashAlgorithm.SHA256, field.getHashAlgorithm());
}
+ @Test
+ void testX0015RejectsTruncatedHashAlg() {
+ final X0015_CertificateIdForFile field = new
X0015_CertificateIdForFile();
+ assertThrows(ZipException.class, () ->
field.parseFromCentralDirectoryData(CENTRAL_DATA, 0, 5));
+ }
+
@Test
void testX0016ReadsFourByteRecordCountAndHashAlg() throws ZipException {
final X0016_CertificateIdForCentralDirectory field = new
X0016_CertificateIdForCentralDirectory();
@@ -49,12 +55,6 @@ void testX0016ReadsFourByteRecordCountAndHashAlg() throws
ZipException {
assertEquals(HashAlgorithm.SHA256, field.getHashAlgorithm());
}
- @Test
- void testX0015RejectsTruncatedHashAlg() {
- final X0015_CertificateIdForFile field = new
X0015_CertificateIdForFile();
- assertThrows(ZipException.class, () ->
field.parseFromCentralDirectoryData(CENTRAL_DATA, 0, 5));
- }
-
@Test
void testX0016RejectsTruncatedHashAlg() {
final X0016_CertificateIdForCentralDirectory field = new
X0016_CertificateIdForCentralDirectory();