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 05513fb69296fa541cdb4e0cb98fc458e5f03b66 Author: Gary Gregory <[email protected]> AuthorDate: Sun Dec 21 17:44:00 2025 -0500 Sort members --- .../archivers/ar/ArArchiveInputStream.java | 8 +- .../harmony/pack200/NewAttributeBands.java | 16 +- .../harmony/unpack200/NewAttributeBands.java | 16 +- .../commons/compress/LegacyConstructorsTest.java | 176 ++++++++++----------- .../compress/archivers/tar/TarUtilsTest.java | 52 +++--- .../internal/AttributeLayoutParserTest.java | 16 +- 6 files changed, 142 insertions(+), 142 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java index d8b74e639..4433332d4 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java @@ -206,6 +206,10 @@ private long asLong(final byte[] byteArray, final int offset, final int len) thr return ParsingUtils.parseLongValue(ArchiveUtils.toAsciiString(byteArray, offset, len).trim()); } + private int checkEntryNameLength(final int nameLength) throws ArchiveException, MemoryLimitException { + return ArchiveUtils.checkEntryNameLength(nameLength, getMaxEntryNameLength(), "AR"); + } + /** * Checks and skips the trailer of the current entry. * @@ -287,10 +291,6 @@ private String getExtendedName(final int offset) throws IOException { throw new ArchiveException("Failed to read GNU long file name at offset " + offset); } - private int checkEntryNameLength(final int nameLength) throws ArchiveException, MemoryLimitException { - return ArchiveUtils.checkEntryNameLength(nameLength, getMaxEntryNameLength(), "AR"); - } - /** * Returns the next AR entry in this stream. * diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java b/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java index 382396d99..e9066cf92 100644 --- a/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java +++ b/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java @@ -454,6 +454,14 @@ public class Replication extends LayoutElement { private final List<LayoutElement> layoutElements; + private Replication(final String tag, final List<LayoutElement> contents) throws Pack200Exception { + this.countElement = new Integral(tag); + this.layoutElements = contents; + if (layoutElements.isEmpty()) { + throw new Pack200Exception("Corrupted Pack200 archive: Replication body is empty"); + } + } + /** * Constructs a new Replication layout element. * @@ -466,14 +474,6 @@ public Replication(final String tag, final String contents) throws Pack200Except this(tag, AttributeLayoutUtils.readBody(contents, attributeLayoutFactory)); } - private Replication(final String tag, final List<LayoutElement> contents) throws Pack200Exception { - this.countElement = new Integral(tag); - this.layoutElements = contents; - if (layoutElements.isEmpty()) { - throw new Pack200Exception("Corrupted Pack200 archive: Replication body is empty"); - } - } - @Override public void addAttributeToBand(final NewAttribute attribute, final InputStream inputStream) { countElement.addAttributeToBand(attribute, inputStream); diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/NewAttributeBands.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/NewAttributeBands.java index bf41e72a3..455c203b0 100644 --- a/src/main/java/org/apache/commons/compress/harmony/unpack200/NewAttributeBands.java +++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/NewAttributeBands.java @@ -455,6 +455,14 @@ public class Replication extends LayoutElement { private final List<LayoutElement> layoutElements; + private Replication(final String tag, final List<LayoutElement> layoutElements) throws Pack200Exception { + this.countElement = new Integral(tag); + this.layoutElements = layoutElements; + if (layoutElements.isEmpty()) { + throw new Pack200Exception("Corrupted Pack200 archive: Replication body is empty"); + } + } + /** * Constructs a new Replication layout element. * @@ -467,14 +475,6 @@ public Replication(final String tag, final String contents) throws Pack200Except this(tag, AttributeLayoutUtils.readBody(contents, attributeLayoutFactory)); } - private Replication(final String tag, final List<LayoutElement> layoutElements) throws Pack200Exception { - this.countElement = new Integral(tag); - this.layoutElements = layoutElements; - if (layoutElements.isEmpty()) { - throw new Pack200Exception("Corrupted Pack200 archive: Replication body is empty"); - } - } - @Override public void addToAttribute(final int index, final NewAttribute attribute) { // Add the count value diff --git a/src/test/java/org/apache/commons/compress/LegacyConstructorsTest.java b/src/test/java/org/apache/commons/compress/LegacyConstructorsTest.java index 40c11a81b..20bce46e8 100644 --- a/src/test/java/org/apache/commons/compress/LegacyConstructorsTest.java +++ b/src/test/java/org/apache/commons/compress/LegacyConstructorsTest.java @@ -73,6 +73,51 @@ static Stream<Arguments> testCpioConstructors() throws IOException { Arguments.of(new CpioArchiveInputStream(inputStream, "UTF-8"), inputStream, "UTF-8", 512)); } + static Stream<Arguments> testSevenZFileContructors() throws IOException { + final Path path = getPath("bla.7z"); + final String defaultName = "unknown archive"; + final String otherName = path.toAbsolutePath().toString(); + final String customName = "customName"; + final int defaultMemoryLimit = SevenZFileOptions.DEFAULT.getMaxMemoryLimitInKb(); + final boolean defaultUseDefaultNameForUnnamedEntries = SevenZFileOptions.DEFAULT.getUseDefaultNameForUnnamedEntries(); + final boolean defaultTryToRecoverBrokenArchives = SevenZFileOptions.DEFAULT.getTryToRecoverBrokenArchives(); + final SevenZFileOptions otherOptions = + SevenZFileOptions.builder().withMaxMemoryLimitInKb(42).withTryToRecoverBrokenArchives(true).withUseDefaultNameForUnnamedEntries(true).build(); + final char[] otherPassword = "password".toCharArray(); + final byte[] otherPasswordBytes = "password".getBytes(StandardCharsets.UTF_16LE); + return Stream.of( + // From File + Arguments.of(new SevenZFile(path.toFile()), otherName, defaultMemoryLimit, defaultUseDefaultNameForUnnamedEntries, + defaultTryToRecoverBrokenArchives, null), + Arguments.of(new SevenZFile(path.toFile(), otherPasswordBytes), otherName, defaultMemoryLimit, defaultUseDefaultNameForUnnamedEntries, + defaultTryToRecoverBrokenArchives, otherPasswordBytes), + Arguments.of(new SevenZFile(path.toFile(), otherPassword), otherName, defaultMemoryLimit, defaultUseDefaultNameForUnnamedEntries, + defaultTryToRecoverBrokenArchives, otherPasswordBytes), + Arguments.of(new SevenZFile(path.toFile(), otherPassword, otherOptions), otherName, 42, true, true, otherPasswordBytes), + Arguments.of(new SevenZFile(path.toFile(), otherOptions), otherName, 42, true, true, null), + // From SeekableByteChannel + Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ)), defaultName, defaultMemoryLimit, + defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, null), + Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), otherPasswordBytes), defaultName, defaultMemoryLimit, + defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, otherPasswordBytes), + Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), otherPassword), defaultName, defaultMemoryLimit, + defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, otherPasswordBytes), + Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), otherPassword, otherOptions), defaultName, 42, true, true, + otherPasswordBytes), + Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), otherOptions), defaultName, 42, true, true, null), + // From SeekableByteChannel with custom name + Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), customName), customName, defaultMemoryLimit, + defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, null), + Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), customName, otherPasswordBytes), customName, + defaultMemoryLimit, defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, otherPasswordBytes), + Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), customName, otherPassword), customName, defaultMemoryLimit, + defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, otherPasswordBytes), + Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), customName, otherPassword, otherOptions), customName, 42, + true, true, otherPasswordBytes), + Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), customName, otherOptions), customName, 42, true, + true, null)); + } + static Stream<Arguments> testTarConstructors() throws IOException { final InputStream inputStream = mock(InputStream.class); final String defaultEncoding = Charset.defaultCharset().name(); @@ -87,6 +132,26 @@ static Stream<Arguments> testTarConstructors() throws IOException { Arguments.of(new TarArchiveInputStream(inputStream, otherEncoding), inputStream, 10240, 512, otherEncoding, false)); } + static Stream<Arguments> testTarFileConstructors() throws IOException { + final Path path = getPath("bla.tar"); + final File file = getFile("bla.tar"); + final SeekableByteChannel channel = mock(SeekableByteChannel.class); + final String defaultEncoding = Charset.defaultCharset().name(); + final String otherEncoding = "UTF-8".equals(defaultEncoding) ? "US-ASCII" : "UTF-8"; + return Stream.of( + Arguments.of(new TarFile(IOUtils.EMPTY_BYTE_ARRAY), defaultEncoding, false), + Arguments.of(new TarFile(IOUtils.EMPTY_BYTE_ARRAY, true), defaultEncoding, true), + Arguments.of(new TarFile(IOUtils.EMPTY_BYTE_ARRAY, otherEncoding), otherEncoding, false), + Arguments.of(new TarFile(file), defaultEncoding, false), + Arguments.of(new TarFile(file, true), defaultEncoding, true), + Arguments.of(new TarFile(file, otherEncoding), otherEncoding, false), + Arguments.of(new TarFile(path), defaultEncoding, false), + Arguments.of(new TarFile(path, true), defaultEncoding, true), + Arguments.of(new TarFile(path, otherEncoding), otherEncoding, false), + Arguments.of(new TarFile(channel), defaultEncoding, false), + Arguments.of(new TarFile(channel, 1024, 1024, otherEncoding, true), otherEncoding, true)); + } + static Stream<Arguments> testZipConstructors() throws IOException { final InputStream inputStream = mock(InputStream.class); return Stream.of( @@ -96,6 +161,29 @@ static Stream<Arguments> testZipConstructors() throws IOException { Arguments.of(new ZipArchiveInputStream(inputStream, "US-ASCII", false, true, true), inputStream, "US-ASCII", false, true, true)); } + static Stream<Arguments> testZipFileConstructors() throws IOException { + final Path path = getPath("bla.zip"); + final String defaultEncoding = StandardCharsets.UTF_8.name(); + final String otherEncoding = "UTF-8".equals(defaultEncoding) ? "US-ASCII" : "UTF-8"; + return Stream.of( + Arguments.of(new ZipFile(path.toFile()), defaultEncoding, true), + Arguments.of(new ZipFile(path.toFile(), otherEncoding), otherEncoding, true), + Arguments.of(new ZipFile(path.toFile(), otherEncoding, false), otherEncoding, false), + Arguments.of(new ZipFile(path.toFile(), otherEncoding, false, true), otherEncoding, false), + Arguments.of(new ZipFile(path), defaultEncoding, true), + Arguments.of(new ZipFile(path, otherEncoding), otherEncoding, true), + Arguments.of(new ZipFile(path, otherEncoding, false), otherEncoding, false), + Arguments.of(new ZipFile(path, otherEncoding, false, true), otherEncoding, false), + Arguments.of(new ZipFile(Files.newByteChannel(path, StandardOpenOption.READ)), defaultEncoding, true), + Arguments.of(new ZipFile(Files.newByteChannel(path, StandardOpenOption.READ), otherEncoding), otherEncoding, true), + Arguments.of(new ZipFile(Files.newByteChannel(path, StandardOpenOption.READ), null, otherEncoding, false), + otherEncoding, false), + Arguments.of(new ZipFile(Files.newByteChannel(path, StandardOpenOption.READ), null, otherEncoding, false, true), + otherEncoding, false), + Arguments.of(new ZipFile(path.toAbsolutePath().toString()), defaultEncoding, true), + Arguments.of(new ZipFile(path.toAbsolutePath().toString(), otherEncoding), otherEncoding, true)); + } + @Test void testArjConstructor() throws Exception { try (InputStream inputStream = Files.newInputStream(getPath("bla.arj")); @@ -132,51 +220,6 @@ void testJarConstructor() throws Exception { } } - static Stream<Arguments> testSevenZFileContructors() throws IOException { - final Path path = getPath("bla.7z"); - final String defaultName = "unknown archive"; - final String otherName = path.toAbsolutePath().toString(); - final String customName = "customName"; - final int defaultMemoryLimit = SevenZFileOptions.DEFAULT.getMaxMemoryLimitInKb(); - final boolean defaultUseDefaultNameForUnnamedEntries = SevenZFileOptions.DEFAULT.getUseDefaultNameForUnnamedEntries(); - final boolean defaultTryToRecoverBrokenArchives = SevenZFileOptions.DEFAULT.getTryToRecoverBrokenArchives(); - final SevenZFileOptions otherOptions = - SevenZFileOptions.builder().withMaxMemoryLimitInKb(42).withTryToRecoverBrokenArchives(true).withUseDefaultNameForUnnamedEntries(true).build(); - final char[] otherPassword = "password".toCharArray(); - final byte[] otherPasswordBytes = "password".getBytes(StandardCharsets.UTF_16LE); - return Stream.of( - // From File - Arguments.of(new SevenZFile(path.toFile()), otherName, defaultMemoryLimit, defaultUseDefaultNameForUnnamedEntries, - defaultTryToRecoverBrokenArchives, null), - Arguments.of(new SevenZFile(path.toFile(), otherPasswordBytes), otherName, defaultMemoryLimit, defaultUseDefaultNameForUnnamedEntries, - defaultTryToRecoverBrokenArchives, otherPasswordBytes), - Arguments.of(new SevenZFile(path.toFile(), otherPassword), otherName, defaultMemoryLimit, defaultUseDefaultNameForUnnamedEntries, - defaultTryToRecoverBrokenArchives, otherPasswordBytes), - Arguments.of(new SevenZFile(path.toFile(), otherPassword, otherOptions), otherName, 42, true, true, otherPasswordBytes), - Arguments.of(new SevenZFile(path.toFile(), otherOptions), otherName, 42, true, true, null), - // From SeekableByteChannel - Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ)), defaultName, defaultMemoryLimit, - defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, null), - Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), otherPasswordBytes), defaultName, defaultMemoryLimit, - defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, otherPasswordBytes), - Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), otherPassword), defaultName, defaultMemoryLimit, - defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, otherPasswordBytes), - Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), otherPassword, otherOptions), defaultName, 42, true, true, - otherPasswordBytes), - Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), otherOptions), defaultName, 42, true, true, null), - // From SeekableByteChannel with custom name - Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), customName), customName, defaultMemoryLimit, - defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, null), - Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), customName, otherPasswordBytes), customName, - defaultMemoryLimit, defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, otherPasswordBytes), - Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), customName, otherPassword), customName, defaultMemoryLimit, - defaultUseDefaultNameForUnnamedEntries, defaultTryToRecoverBrokenArchives, otherPasswordBytes), - Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), customName, otherPassword, otherOptions), customName, 42, - true, true, otherPasswordBytes), - Arguments.of(new SevenZFile(Files.newByteChannel(path, StandardOpenOption.READ), customName, otherOptions), customName, 42, true, - true, null)); - } - @ParameterizedTest @MethodSource void testSevenZFileContructors(final SevenZFile archiveFile, final String expectedName, final int expectedMemoryLimit, @@ -201,26 +244,6 @@ void testTarConstructors(final TarArchiveInputStream archiveStream, final InputS assertEquals(expectedLenient, readField(archiveStream, "lenient", true)); } - static Stream<Arguments> testTarFileConstructors() throws IOException { - final Path path = getPath("bla.tar"); - final File file = getFile("bla.tar"); - final SeekableByteChannel channel = mock(SeekableByteChannel.class); - final String defaultEncoding = Charset.defaultCharset().name(); - final String otherEncoding = "UTF-8".equals(defaultEncoding) ? "US-ASCII" : "UTF-8"; - return Stream.of( - Arguments.of(new TarFile(IOUtils.EMPTY_BYTE_ARRAY), defaultEncoding, false), - Arguments.of(new TarFile(IOUtils.EMPTY_BYTE_ARRAY, true), defaultEncoding, true), - Arguments.of(new TarFile(IOUtils.EMPTY_BYTE_ARRAY, otherEncoding), otherEncoding, false), - Arguments.of(new TarFile(file), defaultEncoding, false), - Arguments.of(new TarFile(file, true), defaultEncoding, true), - Arguments.of(new TarFile(file, otherEncoding), otherEncoding, false), - Arguments.of(new TarFile(path), defaultEncoding, false), - Arguments.of(new TarFile(path, true), defaultEncoding, true), - Arguments.of(new TarFile(path, otherEncoding), otherEncoding, false), - Arguments.of(new TarFile(channel), defaultEncoding, false), - Arguments.of(new TarFile(channel, 1024, 1024, otherEncoding, true), otherEncoding, true)); - } - @ParameterizedTest @MethodSource void testTarFileConstructors(final TarFile tarFile, final String expectedEncoding, final boolean expectedLenient) throws Exception { @@ -243,29 +266,6 @@ void testZipConstructors(final ZipArchiveInputStream archiveStream, final InputS assertEquals(expectedSkipSplitSignature, readDeclaredField(archiveStream, "skipSplitSignature", true)); } - static Stream<Arguments> testZipFileConstructors() throws IOException { - final Path path = getPath("bla.zip"); - final String defaultEncoding = StandardCharsets.UTF_8.name(); - final String otherEncoding = "UTF-8".equals(defaultEncoding) ? "US-ASCII" : "UTF-8"; - return Stream.of( - Arguments.of(new ZipFile(path.toFile()), defaultEncoding, true), - Arguments.of(new ZipFile(path.toFile(), otherEncoding), otherEncoding, true), - Arguments.of(new ZipFile(path.toFile(), otherEncoding, false), otherEncoding, false), - Arguments.of(new ZipFile(path.toFile(), otherEncoding, false, true), otherEncoding, false), - Arguments.of(new ZipFile(path), defaultEncoding, true), - Arguments.of(new ZipFile(path, otherEncoding), otherEncoding, true), - Arguments.of(new ZipFile(path, otherEncoding, false), otherEncoding, false), - Arguments.of(new ZipFile(path, otherEncoding, false, true), otherEncoding, false), - Arguments.of(new ZipFile(Files.newByteChannel(path, StandardOpenOption.READ)), defaultEncoding, true), - Arguments.of(new ZipFile(Files.newByteChannel(path, StandardOpenOption.READ), otherEncoding), otherEncoding, true), - Arguments.of(new ZipFile(Files.newByteChannel(path, StandardOpenOption.READ), null, otherEncoding, false), - otherEncoding, false), - Arguments.of(new ZipFile(Files.newByteChannel(path, StandardOpenOption.READ), null, otherEncoding, false, true), - otherEncoding, false), - Arguments.of(new ZipFile(path.toAbsolutePath().toString()), defaultEncoding, true), - Arguments.of(new ZipFile(path.toAbsolutePath().toString(), otherEncoding), otherEncoding, true)); - } - @ParameterizedTest @MethodSource void testZipFileConstructors(final ZipFile zipFile, final String expectedEncoding, final boolean expectedUseUnicodeExtraFields) throws Exception { diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java index 4369d66be..df5aceba4 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java @@ -104,6 +104,11 @@ private static byte[] paddedUtf8Bytes(final String s) { return Arrays.copyOf(bytes, ((bytes.length + blockSize - 1) / blockSize) * blockSize); } + private static Map<String, String> parsePaxHeaders(final byte[] data, final List<TarArchiveStructSparse> sparseHeaders, + final Map<String, String> globalPaxHeaders) throws IOException { + return TarUtils.parsePaxHeaders(new ByteArrayInputStream(data), globalPaxHeaders, data.length, Short.MAX_VALUE, sparseHeaders); + } + static Stream<Arguments> testReadLongNameHandlesLimits() { final String empty = ""; final String ntfsLongName = createNtfsLongNameByUtf16Units(32767); @@ -117,6 +122,27 @@ static Stream<Arguments> testReadLongNameHandlesLimits() { Arguments.of("POSIX (padded)", posixLongName, paddedUtf8Bytes(posixLongName))); } + static Stream<Arguments> testReadPaxHeaderInvalidCases() { + return Stream.of( + Arguments.of( + "Negative numbytes in PAX 00 sparse header", + "23 GNU.sparse.offset=0\n26 GNU.sparse.numbytes=-1\n"), + Arguments.of( + "Negative offset in PAX 00 sparse header", + "24 GNU.sparse.offset=-1\n26 GNU.sparse.numbytes=10\n"), + Arguments.of( + "Non-numeric numbytes in PAX 00 sparse header", + "23 GNU.sparse.offset=0\n26 GNU.sparse.numbytes=1a\n"), + Arguments.of( + "Non-numeric offset in PAX 00 sparse header", + "23 GNU.sparse.offset=a\n26 GNU.sparse.numbytes=10\n"), + Arguments.of( + "Numbytes in PAX 00 sparse header without offset", + "26 GNU.sparse.numbytes=10\n" + ), + Arguments.of("Missing trailing newline in PAX header", "30 atime=1321711775.9720594634")); + } + private static byte[] utf8Bytes(final String s) { return s.getBytes(UTF_8); } @@ -149,11 +175,6 @@ private void checkRoundTripOctalOrBinary(final long value, final int bufsize) { assertEquals(value, parseValue); } - private static Map<String, String> parsePaxHeaders(final byte[] data, final List<TarArchiveStructSparse> sparseHeaders, - final Map<String, String> globalPaxHeaders) throws IOException { - return TarUtils.parsePaxHeaders(new ByteArrayInputStream(data), globalPaxHeaders, data.length, Short.MAX_VALUE, sparseHeaders); - } - @Test void testName() { byte[] buff = new byte[20]; @@ -483,27 +504,6 @@ void testReadPax00SparseHeaderMakesNumbytesOptional() throws Exception { assertEquals(0, sparseHeaders.get(1).getNumbytes()); } - static Stream<Arguments> testReadPaxHeaderInvalidCases() { - return Stream.of( - Arguments.of( - "Negative numbytes in PAX 00 sparse header", - "23 GNU.sparse.offset=0\n26 GNU.sparse.numbytes=-1\n"), - Arguments.of( - "Negative offset in PAX 00 sparse header", - "24 GNU.sparse.offset=-1\n26 GNU.sparse.numbytes=10\n"), - Arguments.of( - "Non-numeric numbytes in PAX 00 sparse header", - "23 GNU.sparse.offset=0\n26 GNU.sparse.numbytes=1a\n"), - Arguments.of( - "Non-numeric offset in PAX 00 sparse header", - "23 GNU.sparse.offset=a\n26 GNU.sparse.numbytes=10\n"), - Arguments.of( - "Numbytes in PAX 00 sparse header without offset", - "26 GNU.sparse.numbytes=10\n" - ), - Arguments.of("Missing trailing newline in PAX header", "30 atime=1321711775.9720594634")); - } - @ParameterizedTest(name = "{0}") @MethodSource void testReadPaxHeaderInvalidCases(final String description, final String header) { diff --git a/src/test/java/org/apache/commons/compress/harmony/internal/AttributeLayoutParserTest.java b/src/test/java/org/apache/commons/compress/harmony/internal/AttributeLayoutParserTest.java index c53b9a976..7c45618ad 100644 --- a/src/test/java/org/apache/commons/compress/harmony/internal/AttributeLayoutParserTest.java +++ b/src/test/java/org/apache/commons/compress/harmony/internal/AttributeLayoutParserTest.java @@ -69,10 +69,10 @@ private static class LayoutElement { private LayoutElement(int callableIndex) { } - private LayoutElement(String tag) { + private LayoutElement(List<LayoutElement> body) { } - private LayoutElement(List<LayoutElement> body) { + private LayoutElement(String tag) { } private LayoutElement(String anyInt, List<AttributeLayoutParser.UnionCaseData<LayoutElement>> cases, List<LayoutElement> body) { @@ -129,16 +129,16 @@ void testInvalidLayout(String layout) { } @ParameterizedTest - @MethodSource({"validLayouts", "validCallableLayouts"}) - void testReadElement(String layout) throws Pack200Exception { - final List<LayoutElement> result = AttributeLayoutUtils.readAttributeLayout(layout, FACTORY); + @MethodSource("validLayouts") + void testReadBody(String layout) throws Pack200Exception { + final List<LayoutElement> result = AttributeLayoutUtils.readBody(layout, FACTORY); assertFalse(result.isEmpty(), "Expected at least one LayoutElement for layout: " + layout); } @ParameterizedTest - @MethodSource("validLayouts") - void testReadBody(String layout) throws Pack200Exception { - final List<LayoutElement> result = AttributeLayoutUtils.readBody(layout, FACTORY); + @MethodSource({"validLayouts", "validCallableLayouts"}) + void testReadElement(String layout) throws Pack200Exception { + final List<LayoutElement> result = AttributeLayoutUtils.readAttributeLayout(layout, FACTORY); assertFalse(result.isEmpty(), "Expected at least one LayoutElement for layout: " + layout); } }
