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 2024/02/17 22:16:22 UTC

(commons-compress) branch master updated (ca1052f13 -> bf50b7d91)

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 ca1052f13 Bump github/codeql-action from 3.24.0 to 3.24.3 (#481)
     new 84e2ad3cb Javadoc
     new b845198e6 Internal refactoring
     new 1d534c51a Internal refactoring
     new 9399923c4 Reuse IOUtils.readRange()
     new b7ca1e4dd Internal refactoring
     new 0df503de8 Reuse IOUtils.readRange()
     new c55e16585 Javadoc
     new 25a54419d Add a band set parameter check
     new 9f2f97925 Pack200Exception extends IOException
     new 6f007a3f4 Preserve input argument
     new b778b64d0 Internal refactoring
     new 48333267c Rename test package for pack200
     new d49764528 Rename test package for unpack200
     new bf50b7d91 Internal refactoring

The 14 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:
 pom.xml                                            |   4 +-
 .../commons/compress/harmony/pack200/Codec.java    |  25 ++++-
 .../compress/harmony/pack200/Pack200Exception.java |  10 +-
 .../compress/harmony/pack200/PopulationCodec.java  |   2 +-
 .../commons/compress/harmony/pack200/RunCodec.java |   2 +-
 .../compress/harmony/unpack200/Archive.java        |  72 +++++++------
 .../compress/harmony/unpack200/BandSet.java        |  22 ++--
 .../compress/harmony/unpack200/CpBands.java        |  20 ++--
 .../compress/harmony/unpack200/FileBands.java      |  10 +-
 .../harmony/unpack200/Pack200UnpackerAdapter.java  | 119 +++++++++++++++++++++
 .../compress/harmony/unpack200/Segment.java        |  14 +--
 .../compress/harmony/unpack200/SegmentHeader.java  |  28 +----
 .../commons/compress/java/util/jar/Pack200.java    |   5 +-
 .../commons/compress/utils/BoundedInputStream.java |   6 ++
 .../org/apache/commons/compress/utils/IOUtils.java |  36 +++----
 .../commons/compress/archivers/ListerTest.java     |   5 +-
 .../harmony/pack200/{tests => }/ArchiveTest.java   |   5 +-
 .../harmony/pack200/{tests => }/BHSDCodecTest.java |   6 +-
 .../pack200/{tests => }/CodecEncodingTest.java     |   8 +-
 .../harmony/pack200/{tests => }/CodecTest.java     |   6 +-
 .../pack200/{tests => }/Compress626Test.java       |   5 +-
 .../pack200/{tests => }/Compress628Test.java       |   5 +-
 .../harmony/pack200/{tests => }/HelloWorld.java    |   2 +-
 .../pack200/{tests => }/NewAttributeBandsTest.java |  10 +-
 .../pack200/{tests => }/PackingOptionsTest.java    |   6 +-
 .../pack200/{tests => }/PopulationCodecTest.java   |   5 +-
 .../harmony/pack200/{tests => }/RunCodecTest.java  |  36 ++++++-
 .../unpack200/{tests => }/AbstractBandsTest.java   |   7 +-
 .../harmony/unpack200/{tests => }/ArchiveTest.java |  60 ++++++++++-
 .../{tests => }/AttributeLayoutMapTest.java        |   4 +-
 .../unpack200/{tests => }/AttributeLayoutTest.java |   5 +-
 .../harmony/unpack200/{tests => }/BandSetTest.java |   5 +-
 .../harmony/unpack200/{tests => }/BcBandsTest.java |   8 +-
 .../harmony/unpack200/{tests => }/CPUTF8Test.java  |   2 +-
 .../unpack200/{tests => }/ClassBandsTest.java      |   5 +-
 .../unpack200/{tests => }/CodeAttributeTest.java   |   5 +-
 .../Codec_decodeInts_OutOfMemoryErrorTest.java     |   2 +-
 .../harmony/unpack200/{tests => }/ICTupleTest.java |   3 +-
 .../{tests => }/NewAttributeBandsTest.java         |   5 +-
 .../SegmentConstantPoolArrayCacheTest.java         |   3 +-
 .../{tests => }/SegmentConstantPoolTest.java       |   5 +-
 .../unpack200/{tests => }/SegmentOptionsTest.java  |   3 +-
 .../harmony/unpack200/{tests => }/SegmentTest.java |  55 +++++++++-
 .../unpack200/{tests => }/SegmentUtilsTest.java    |   4 +-
 .../{tests => }/bytecode/ByteCodeTest.java         |   3 +-
 .../{tests => }/bytecode/ClassFileEntryTest.java   |  10 +-
 .../{tests => }/bytecode/ConstantPoolTest.java     |   6 +-
 .../apache/commons/compress/pack/bandint_oom.pack  | Bin 0 -> 88 bytes
 .../apache/commons/compress/pack/cpfloat_oom.pack  | Bin 0 -> 178 bytes
 .../apache/commons/compress/pack/cputf8_oom.pack   | Bin 0 -> 427 bytes
 .../apache/commons/compress/pack/favoured_oom.pack | Bin 0 -> 84 bytes
 .../apache/commons/compress/pack/filebits_oom.pack | Bin 0 -> 309 bytes
 .../apache/commons/compress/pack/flags_oom.pack    | Bin 0 -> 1624 bytes
 .../commons/compress/pack/references_oom.pack      | Bin 0 -> 66 bytes
 .../commons/compress/pack/segment_header_oom.pack  | Bin 0 -> 41 bytes
 .../commons/compress/pack/signatures_oom.pack      | Bin 0 -> 121 bytes
 56 files changed, 429 insertions(+), 245 deletions(-)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/ArchiveTest.java (98%)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/BHSDCodecTest.java (91%)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/CodecEncodingTest.java (96%)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/CodecTest.java (97%)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/Compress626Test.java (88%)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/Compress628Test.java (83%)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/HelloWorld.java (95%)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/NewAttributeBandsTest.java (96%)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/PackingOptionsTest.java (98%)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/PopulationCodecTest.java (93%)
 rename src/test/java/org/apache/commons/compress/harmony/pack200/{tests => }/RunCodecTest.java (79%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/AbstractBandsTest.java (85%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/ArchiveTest.java (84%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/AttributeLayoutMapTest.java (92%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/AttributeLayoutTest.java (96%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/BandSetTest.java (91%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/BcBandsTest.java (98%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/CPUTF8Test.java (95%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/ClassBandsTest.java (96%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/CodeAttributeTest.java (96%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/Codec_decodeInts_OutOfMemoryErrorTest.java (98%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/ICTupleTest.java (95%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/NewAttributeBandsTest.java (97%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/SegmentConstantPoolArrayCacheTest.java (95%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/SegmentConstantPoolTest.java (95%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/SegmentOptionsTest.java (91%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/SegmentTest.java (63%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/SegmentUtilsTest.java (94%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/bytecode/ByteCodeTest.java (91%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/bytecode/ClassFileEntryTest.java (86%)
 rename src/test/java/org/apache/commons/compress/harmony/unpack200/{tests => }/bytecode/ConstantPoolTest.java (86%)
 create mode 100644 src/test/resources/org/apache/commons/compress/pack/bandint_oom.pack
 create mode 100644 src/test/resources/org/apache/commons/compress/pack/cpfloat_oom.pack
 create mode 100644 src/test/resources/org/apache/commons/compress/pack/cputf8_oom.pack
 create mode 100644 src/test/resources/org/apache/commons/compress/pack/favoured_oom.pack
 create mode 100644 src/test/resources/org/apache/commons/compress/pack/filebits_oom.pack
 create mode 100644 src/test/resources/org/apache/commons/compress/pack/flags_oom.pack
 create mode 100644 src/test/resources/org/apache/commons/compress/pack/references_oom.pack
 create mode 100644 src/test/resources/org/apache/commons/compress/pack/segment_header_oom.pack
 create mode 100644 src/test/resources/org/apache/commons/compress/pack/signatures_oom.pack


(commons-compress) 07/14: 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 c55e16585f55bb197cb830110c8ce08a419dd07a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 10:17:34 2024 -0500

    Javadoc
---
 src/test/java/org/apache/commons/compress/archivers/ListerTest.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/compress/archivers/ListerTest.java b/src/test/java/org/apache/commons/compress/archivers/ListerTest.java
index 2a8c4e299..bf90f3446 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ListerTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ListerTest.java
@@ -32,7 +32,10 @@ import org.junit.jupiter.params.provider.MethodSource;
 public class ListerTest {
 
     /**
-     * Creates a stream of paths of test fixtures with file names that don't end with "-fail" for specific file extensions.
+     * Creates a stream of paths of test fixtures with file names that don't end with {@code "-fail"} for specific file extensions.
+     *
+     * @return a stream of paths.
+     * @throws IOException if an I/O error is thrown.
      */
     public static Stream<Path> getFixtures() throws IOException {
         return PathUtils.walk(Paths.get("src/test/resources"), new RegexFileFilter("^(?!.*(-fail)).*\\.(tar|ar|arj|apk|dump)$"), 10, false);


(commons-compress) 14/14: Internal refactoring

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 bf50b7d915ee406298670ceebcaa1e22616a23e0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 17:11:22 2024 -0500

    Internal refactoring
    
    - Set version of SPDX to avoid odd issue on Java 8
    - Reuse BoundedInputStream
    - Add Archive tests
    - Add Segment tests
---
 pom.xml                                            |   4 +-
 .../commons/compress/harmony/pack200/Codec.java    |   2 +-
 .../compress/harmony/unpack200/Archive.java        |  26 +++--
 .../harmony/unpack200/Pack200UnpackerAdapter.java  | 107 ++++++++++++++++++++-
 .../compress/harmony/unpack200/Segment.java        |   6 +-
 .../commons/compress/java/util/jar/Pack200.java    |   5 +-
 .../compress/harmony/unpack200/ArchiveTest.java    |  38 ++++++--
 .../compress/harmony/unpack200/SegmentTest.java    |  31 ++++--
 8 files changed, 179 insertions(+), 40 deletions(-)

diff --git a/pom.xml b/pom.xml
index 2332273f2..cc6f1b89b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,6 +63,7 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
       javax.crypto.*;resolution:=optional,
       org.apache.commons.commons-codec;resolution:=optional,
       org.apache.commons.commons-io;resolution:=optional,
+      org.apache.commons.lang3.reflect;resolution:=optional,
       *
     </commons.osgi.import>
 
@@ -78,6 +79,8 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
     <slf4j.version>2.0.12</slf4j.version>
     <asm.version>9.6</asm.version>
     <project.build.outputTimestamp>2024-01-01T00:00:00Z</project.build.outputTimestamp>
+    <!-- spdx 0.6.0 can require Java 11 depending on undocumented behavior which kicks in for us here. -->
+    <commons.spdx.version>0.5.5</commons.spdx.version>
   </properties>
 
   <issueManagement>
@@ -211,7 +214,6 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
       <version>3.14.0</version>
-      <scope>test</scope>
     </dependency>    
     <dependency>
       <groupId>org.osgi</groupId>
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/Codec.java b/src/main/java/org/apache/commons/compress/harmony/pack200/Codec.java
index a575558ba..06630b323 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/Codec.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/Codec.java
@@ -144,7 +144,7 @@ public abstract class Codec {
      * @throws Pack200Exception if there is a problem decoding the value or that the value is invalid
      */
     public int[] decodeInts(final int n, final InputStream in, final int firstValue) throws IOException, Pack200Exception {
-        final int[] result = new int[check(n + 1, in)];
+        final int[] result = new int[check(n, in) + 1];
         result[0] = firstValue;
         int last = firstValue;
         for (int i = 1; i < n + 1; i++) {
diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java
index f70c56ca9..ff39c3142 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java
@@ -24,7 +24,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.UncheckedIOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -69,18 +68,15 @@ public class Archive {
      * Creates an Archive with streams for the input and output files. Note: If you use this method then calling {@link #setRemovePackFile(boolean)} will have
      * no effect.
      *
-     * @param inputStream  TODO
-     * @param outputStream TODO
+     * @param inputStream  the input stream, preferably a {@link BoundedInputStream}. The bound can the the file size.
+     * @param outputStream the JAR output stream.
+     * @throws IOException if an I/O error occurs
      */
-    public Archive(final InputStream inputStream, final JarOutputStream outputStream) {
-        this.inputStream = inputStream instanceof BoundedInputStream ? (BoundedInputStream) inputStream : new BoundedInputStream(inputStream);
+    public Archive(final InputStream inputStream, final JarOutputStream outputStream) throws IOException {
+        this.inputStream = Pack200UnpackerAdapter.newBoundedInputStream(inputStream);
         this.outputStream = outputStream;
         if (inputStream instanceof FileInputStream) {
-            try {
-                inputPath = Paths.get(((FileInputStream) inputStream).getFD().toString());
-            } catch (final IOException e) {
-                throw new UncheckedIOException(e);
-            }
+            inputPath = Paths.get(Pack200UnpackerAdapter.readPath((FileInputStream) inputStream));
         } else {
             inputPath = null;
         }
@@ -90,18 +86,18 @@ public class Archive {
     /**
      * Creates an Archive with the given input and output file names.
      *
-     * @param inputFileName  TODO
-     * @param outputFileName TODO
+     * @param inputFileName  the input file name.
+     * @param outputFileName the output file name
      * @throws FileNotFoundException if the input file does not exist
-     * @throws FileNotFoundException TODO
-     * @throws IOException           TODO
+     * @throws IOException           if an I/O error occurs
      */
+    @SuppressWarnings("resource")
     public Archive(final String inputFileName, final String outputFileName) throws FileNotFoundException, IOException {
         this.inputPath = Paths.get(inputFileName);
-        this.outputFileName = outputFileName;
         this.inputSize = Files.size(this.inputPath);
         this.inputStream = new BoundedInputStream(Files.newInputStream(inputPath), inputSize);
         this.outputStream = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(outputFileName)));
+        this.outputFileName = outputFileName;
     }
 
     private boolean available(final InputStream inputStream) throws IOException {
diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
index f8038ba71..6817f6ca5 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
@@ -18,8 +18,12 @@ package org.apache.commons.compress.harmony.unpack200;
 
 import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -29,25 +33,124 @@ import org.apache.commons.compress.harmony.pack200.Pack200Adapter;
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
 import org.apache.commons.compress.java.util.jar.Pack200.Unpacker;
 import org.apache.commons.io.input.BoundedInputStream;
+import org.apache.commons.lang3.reflect.FieldUtils;
 
 /**
  * This class provides the binding between the standard Pack200 interface and the internal interface for (un)packing.
  */
 public class Pack200UnpackerAdapter extends Pack200Adapter implements Unpacker {
 
+    /**
+     * Creates a new BoundedInputStream bound by the size of the given file.
+     * <p>
+     * The new BoundedInputStream wraps a new {@link BufferedInputStream}.
+     * </p>
+     *
+     * @param file The file.
+     * @return a new BoundedInputStream
+     * @throws IOException if an I/O error occurs
+     */
     static BoundedInputStream newBoundedInputStream(final File file) throws IOException {
         return newBoundedInputStream(file.toPath());
     }
 
+    private static BoundedInputStream newBoundedInputStream(final FileInputStream fileInputStream) throws IOException {
+        return newBoundedInputStream(readPath(fileInputStream));
+    }
+
+    static BoundedInputStream newBoundedInputStream(final InputStream inputStream) throws IOException {
+        if (inputStream instanceof BoundedInputStream) {
+            return (BoundedInputStream) inputStream;
+        }
+        if (inputStream instanceof FilterInputStream) {
+            return newBoundedInputStream(unwrap((FilterInputStream) inputStream));
+        }
+        if (inputStream instanceof FileInputStream) {
+            return newBoundedInputStream((FileInputStream) inputStream);
+        }
+        // No limit
+        return new BoundedInputStream(inputStream);
+    }
+
+    /**
+     * Creates a new BoundedInputStream bound by the size of the given path.
+     * <p>
+     * The new BoundedInputStream wraps a new {@link BufferedInputStream}.
+     * </p>
+     *
+     * @param path The path.
+     * @return a new BoundedInputStream
+     * @throws IOException if an I/O error occurs
+     */
     @SuppressWarnings("resource")
-    static BoundedInputStream newBoundedInputStream(final Path inputPath) throws IOException {
-        return new BoundedInputStream(new BufferedInputStream(Files.newInputStream(inputPath)), Files.size(inputPath));
+    static BoundedInputStream newBoundedInputStream(final Path path) throws IOException {
+        return new BoundedInputStream(new BufferedInputStream(Files.newInputStream(path)), Files.size(path));
     }
 
+    /**
+     * Creates a new BoundedInputStream bound by the size of the given file.
+     * <p>
+     * The new BoundedInputStream wraps a new {@link BufferedInputStream}.
+     * </p>
+     *
+     * @param first the path string or initial part of the path string.
+     * @param more  additional strings to be joined to form the path string.
+     * @return a new BoundedInputStream
+     * @throws IOException if an I/O error occurs
+     */
     static BoundedInputStream newBoundedInputStream(final String first, final String... more) throws IOException {
         return newBoundedInputStream(Paths.get(first, more));
     }
 
+    /**
+     * Creates a new BoundedInputStream bound by the size of the given URL to a file.
+     * <p>
+     * The new BoundedInputStream wraps a new {@link BufferedInputStream}.
+     * </p>
+     *
+     * @param path The URL.
+     * @return a new BoundedInputStream
+     * @throws IOException        if an I/O error occurs
+     * @throws URISyntaxException
+     */
+    static BoundedInputStream newBoundedInputStream(final URL url) throws IOException, URISyntaxException {
+        return newBoundedInputStream(Paths.get(url.toURI()));
+    }
+
+    @SuppressWarnings("unchecked")
+    private static <T> T readField(final Object object, final String fieldName) {
+        try {
+            return (T) FieldUtils.readField(object, fieldName, true);
+        } catch (final IllegalAccessException e) {
+            return null;
+        }
+    }
+
+    static String readPath(final FileInputStream fis) {
+        return readField(fis, "path");
+    }
+
+    /**
+     * Unwraps the given FilterInputStream to return its wrapped InputStream.
+     *
+     * @param filterInputStream The FilterInputStream to unwrap.
+     * @return The wrapped InputStream
+     */
+    static InputStream unwrap(final FilterInputStream filterInputStream) {
+        return readField(filterInputStream, "in");
+    }
+
+    /**
+     * Unwraps the given InputStream if it is an FilterInputStream to return its wrapped InputStream.
+     *
+     * @param filterInputStream The FilterInputStream to unwrap.
+     * @return The wrapped InputStream
+     */
+    @SuppressWarnings("resource")
+    static InputStream unwrap(final InputStream inputStream) {
+        return inputStream instanceof FilterInputStream ? unwrap((FilterInputStream) inputStream) : inputStream;
+    }
+
     @Override
     public void unpack(final File file, final JarOutputStream out) throws IOException {
         if (file == null || out == null) {
diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
index 576fead75..262cebccd 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
@@ -49,6 +49,7 @@ import org.apache.commons.compress.harmony.unpack200.bytecode.ClassFile;
 import org.apache.commons.compress.harmony.unpack200.bytecode.ClassFileEntry;
 import org.apache.commons.compress.harmony.unpack200.bytecode.InnerClassesAttribute;
 import org.apache.commons.compress.harmony.unpack200.bytecode.SourceFileAttribute;
+import org.apache.commons.io.input.BoundedInputStream;
 
 /**
  * A Pack200 archive consists of one or more segments. Each segment is stand-alone, in the sense that every segment has the magic number header; thus, every
@@ -462,7 +463,7 @@ public class Segment {
     /**
      * Unpacks a packed stream (either .pack. or .pack.gz) into a corresponding JarOuputStream.
      *
-     * @param inputStream  a packed input stream.
+     * @param inputStream  a packed input stream, preferably a {@link BoundedInputStream}.
      * @param out output stream.
      * @throws Pack200Exception if there is a problem unpacking
      * @throws IOException      if there is a problem with I/O during unpacking
@@ -484,7 +485,8 @@ public class Segment {
      * Package-private accessors for unpacking stages
      */
     void unpackRead(final InputStream inputStream) throws IOException, Pack200Exception {
-        final InputStream in = inputStream.markSupported() ? inputStream : new BufferedInputStream(inputStream);
+        @SuppressWarnings("resource")
+        final InputStream in = Pack200UnpackerAdapter.newBoundedInputStream(inputStream);
 
         header = new SegmentHeader(this);
         header.read(in);
diff --git a/src/main/java/org/apache/commons/compress/java/util/jar/Pack200.java b/src/main/java/org/apache/commons/compress/java/util/jar/Pack200.java
index c836b25e6..1055503bc 100644
--- a/src/main/java/org/apache/commons/compress/java/util/jar/Pack200.java
+++ b/src/main/java/org/apache/commons/compress/java/util/jar/Pack200.java
@@ -30,6 +30,7 @@ import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
 
 import org.apache.commons.compress.harmony.archive.internal.nls.Messages;
+import org.apache.commons.io.input.BoundedInputStream;
 
 /**
  * Class factory for {@link Pack200.Packer} and {@link Pack200.Unpacker}.
@@ -230,7 +231,7 @@ public abstract class Pack200 {
         /**
          * Unpacks the contents of the specified {@code File} to the specified JAR output stream.
          *
-         * @param in  file to be uncompressed.
+         * @param in  file to uncompress.
          * @param out JAR output stream of uncompressed data.
          * @throws IOException if I/O exception occurs.
          */
@@ -239,7 +240,7 @@ public abstract class Pack200 {
         /**
          * Unpacks the specified stream to the specified JAR output stream.
          *
-         * @param in  stream to uncompressed.
+         * @param in  stream to uncompress, preferably a {@link BoundedInputStream}.
          * @param out JAR output stream of uncompressed data.
          * @throws IOException if I/O exception occurs.
          */
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java
index 9b0d0cc10..fc8372b98 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java
@@ -33,9 +33,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.Enumeration;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
@@ -196,18 +193,39 @@ public class ArchiveTest extends AbstractTempDirTest {
             "references_oom.pack",
             "segment_header_oom.pack",
             "signatures_oom.pack"
-            // @formatter:on
+    // @formatter:on
     })
     // Tests of various files that can cause out of memory errors
-    public void testParsingOOM(final String testFileName) throws Exception {
+    public void testParsingOOMBounded(final String testFileName) throws Exception {
         final URL url = Segment.class.getResource("/org/apache/commons/compress/pack/" + testFileName);
-        final Path path = Paths.get(url.toURI());
-        try (InputStream in = new BoundedInputStream(new BufferedInputStream(Files.newInputStream(path)), Files.size(path));
+        try (BoundedInputStream in = Pack200UnpackerAdapter.newBoundedInputStream(url);
                 JarOutputStream out = new JarOutputStream(NullOutputStream.INSTANCE)) {
             assertThrows(IOException.class, () -> new Archive(in, out).unpack());
         }
     }
 
+    @ParameterizedTest
+    @ValueSource(strings = {
+    // @formatter:off
+            "bandint_oom.pack",
+            "cpfloat_oom.pack",
+            "cputf8_oom.pack",
+            "favoured_oom.pack",
+            "filebits_oom.pack",
+            "flags_oom.pack",
+            "references_oom.pack",
+            "segment_header_oom.pack",
+            "signatures_oom.pack"
+    // @formatter:on
+    })
+    // Tests of various files that can cause out of memory errors
+    public void testParsingOOMUnbounded(final String testFileName) throws Exception {
+        try (InputStream is = Segment.class.getResourceAsStream("/org/apache/commons/compress/pack/" + testFileName);
+                JarOutputStream out = new JarOutputStream(NullOutputStream.INSTANCE)) {
+            assertThrows(IOException.class, () -> new Archive(is, out).unpack());
+        }
+    }
+
     @Test
     public void testRemovePackFile() throws Exception {
         final File original = new File(Archive.class.getResource("/pack200/sql.pack.gz").toURI());
@@ -221,10 +239,10 @@ public class ArchiveTest extends AbstractTempDirTest {
                 read = inputStream.read(bytes);
             }
         }
-        final String inputFile = copy.getPath();
+        final String inputFileName = copy.getPath();
         final File file = createTempFile("sqlout", ".jar");
-        final String outputFile = file.getPath();
-        final Archive archive = new Archive(inputFile, outputFile);
+        final String outputFileName = file.getPath();
+        final Archive archive = new Archive(inputFileName, outputFileName);
         archive.setRemovePackFile(true);
         archive.unpack();
         assertFalse(copy.exists());
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentTest.java
index 5a3b8937a..f4ba3d671 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentTest.java
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
-import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -28,9 +27,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
@@ -113,10 +109,31 @@ public class SegmentTest extends AbstractTempDirTest {
             // @formatter:on
     })
     // Tests of various files that can cause out of memory errors
-    public void testParsingOOM(final String testFileName) throws Exception {
+    public void testParsingOOMBounded(final String testFileName) throws Exception {
         final URL url = Segment.class.getResource("/org/apache/commons/compress/pack/" + testFileName);
-        final Path path = Paths.get(url.toURI());
-        try (InputStream in = new BoundedInputStream(new BufferedInputStream(Files.newInputStream(path)), Files.size(path));
+        try (BoundedInputStream in = Pack200UnpackerAdapter.newBoundedInputStream(url);
+                JarOutputStream out = new JarOutputStream(NullOutputStream.INSTANCE)) {
+            assertThrows(IOException.class, () -> new Segment().unpack(in, out));
+        }
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = {
+    // @formatter:off
+            "bandint_oom.pack",
+            "cpfloat_oom.pack",
+            "cputf8_oom.pack",
+            "favoured_oom.pack",
+            "filebits_oom.pack",
+            "flags_oom.pack",
+            "references_oom.pack",
+            "segment_header_oom.pack",
+            "signatures_oom.pack"
+            // @formatter:on
+    })
+    // Tests of various files that can cause out of memory errors
+    public void testParsingOOMUnounded(final String testFileName) throws Exception {
+        try (InputStream in = Segment.class.getResourceAsStream("/org/apache/commons/compress/pack/" + testFileName);
                 JarOutputStream out = new JarOutputStream(NullOutputStream.INSTANCE)) {
             assertThrows(IOException.class, () -> new Segment().unpack(in, out));
         }


(commons-compress) 01/14: 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 84e2ad3cb96e5c4efa221dbb5a939d37884326da
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 10:03:05 2024 -0500

    Javadoc
    
    Better parameter names
---
 .../org/apache/commons/compress/utils/IOUtils.java | 36 +++++++++++-----------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/utils/IOUtils.java b/src/main/java/org/apache/commons/compress/utils/IOUtils.java
index 7983db97f..708b88a9c 100644
--- a/src/main/java/org/apache/commons/compress/utils/IOUtils.java
+++ b/src/main/java/org/apache/commons/compress/utils/IOUtils.java
@@ -124,7 +124,7 @@ public final class IOUtils {
      * Copies part of the content of a InputStream into an OutputStream
      *
      * @param input      the InputStream to copy
-     * @param len        maximum amount of bytes to copy
+     * @param length        maximum amount of bytes to copy
      * @param output     the target, may be null to simulate output to dev/null on Linux and NUL on Windows
      * @param bufferSize the buffer size to use, must be bigger than 0
      * @return the number of bytes copied
@@ -134,14 +134,14 @@ public final class IOUtils {
      * @deprecated No longer used.
      */
     @Deprecated
-    public static long copyRange(final InputStream input, final long len, final OutputStream output, final int bufferSize) throws IOException {
+    public static long copyRange(final InputStream input, final long length, final OutputStream output, final int bufferSize) throws IOException {
         if (bufferSize < 1) {
             throw new IllegalArgumentException("bufferSize must be bigger than 0");
         }
-        final byte[] buffer = new byte[(int) Math.min(bufferSize, Math.max(0, len))];
+        final byte[] buffer = new byte[(int) Math.min(bufferSize, Math.max(0, length))];
         int n = 0;
         long count = 0;
-        while (count < len && -1 != (n = input.read(buffer, 0, (int) Math.min(len - count, buffer.length)))) {
+        while (count < length && -1 != (n = input.read(buffer, 0, (int) Math.min(length - count, buffer.length)))) {
             if (output != null) {
                 output.write(buffer, 0, n);
             }
@@ -194,15 +194,15 @@ public final class IOUtils {
      * @param input  stream to read from
      * @param array  buffer to fill
      * @param offset offset into the buffer to start filling at
-     * @param len    of bytes to read
+     * @param length    of bytes to read
      * @return the number of bytes actually read
      * @throws IOException if an I/O error has occurred
      */
-    public static int readFully(final InputStream input, final byte[] array, final int offset, final int len) throws IOException {
-        if (len < 0 || offset < 0 || len + offset > array.length || len + offset < 0) {
+    public static int readFully(final InputStream input, final byte[] array, final int offset, final int length) throws IOException {
+        if (length < 0 || offset < 0 || length + offset > array.length || length + offset < 0) {
             throw new IndexOutOfBoundsException();
         }
-        return org.apache.commons.io.IOUtils.read(input, array, offset, len);
+        return org.apache.commons.io.IOUtils.read(input, array, offset, length);
     }
 
     /**
@@ -214,8 +214,8 @@ public final class IOUtils {
      *
      * @param channel    the channel to read from
      * @param byteBuffer the buffer into which the data is read.
-     * @throws IOException  - if an I/O error occurs.
-     * @throws EOFException - if the channel reaches the end before reading all the bytes.
+     * @throws IOException  if an I/O error occurs.
+     * @throws EOFException if the channel reaches the end before reading all the bytes.
      */
     public static void readFully(final ReadableByteChannel channel, final ByteBuffer byteBuffer) throws IOException {
         final int expectedLength = byteBuffer.remaining();
@@ -229,15 +229,15 @@ public final class IOUtils {
      * Gets part of the contents of an {@code InputStream} as a {@code byte[]}.
      *
      * @param input the {@code InputStream} to read from
-     * @param len   maximum amount of bytes to copy
+     * @param length   maximum amount of bytes to copy
      * @return the requested byte array
      * @throws NullPointerException if the input is null
      * @throws IOException          if an I/O error occurs
      * @since 1.21
      */
-    public static byte[] readRange(final InputStream input, final int len) throws IOException {
+    public static byte[] readRange(final InputStream input, final int length) throws IOException {
         final ByteArrayOutputStream output = new ByteArrayOutputStream();
-        org.apache.commons.io.IOUtils.copyLarge(input, output, 0, len);
+        org.apache.commons.io.IOUtils.copyLarge(input, output, 0, length);
         return output.toByteArray();
     }
 
@@ -245,19 +245,19 @@ public final class IOUtils {
      * Gets part of the contents of an {@code ReadableByteChannel} as a {@code byte[]}.
      *
      * @param input the {@code ReadableByteChannel} to read from
-     * @param len   maximum amount of bytes to copy
+     * @param length   maximum amount of bytes to copy
      * @return the requested byte array
      * @throws NullPointerException if the input is null
      * @throws IOException          if an I/O error occurs
      * @since 1.21
      */
-    public static byte[] readRange(final ReadableByteChannel input, final int len) throws IOException {
+    public static byte[] readRange(final ReadableByteChannel input, final int length) throws IOException {
         final ByteArrayOutputStream output = new ByteArrayOutputStream();
-        final ByteBuffer b = ByteBuffer.allocate(Math.min(len, COPY_BUF_SIZE));
+        final ByteBuffer b = ByteBuffer.allocate(Math.min(length, COPY_BUF_SIZE));
         int read = 0;
-        while (read < len) {
+        while (read < length) {
             // Make sure we never read more than len bytes
-            b.limit(Math.min(len - read, b.capacity()));
+            b.limit(Math.min(length - read, b.capacity()));
             final int readNow = input.read(b);
             if (readNow <= 0) {
                 break;


(commons-compress) 08/14: Add a band set parameter check

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 25a54419d9715a77577e4a31e8303e20fbe34506
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 10:54:15 2024 -0500

    Add a band set parameter check
---
 .../java/org/apache/commons/compress/harmony/unpack200/BandSet.java  | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java
index b9eb7389d..67a6b5a3e 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java
@@ -64,7 +64,9 @@ public abstract class BandSet {
      * @throws Pack200Exception if there is a problem decoding the value or that the value is invalid
      */
     public int[] decodeBandInt(final String name, final InputStream in, final BHSDCodec codec, final int count) throws IOException, Pack200Exception {
-        int[] band;
+        if (count < 0) {
+            throw new Pack200Exception("count < 0");
+        }
         // Useful for debugging
 //        if (count > 0) {
 //            System.out.println("decoding " + name + " " + count);
@@ -78,6 +80,7 @@ public abstract class BandSet {
             return getFirst;
         }
         final int first = getFirst[0];
+        int[] band;
         if (codec.isSigned() && first >= -256 && first <= -1) {
             // Non-default codec should be used
             codecUsed = CodecEncoding.getCodec(-1 - first, header.getBandHeadersInputStream(), codec);


(commons-compress) 13/14: Rename test package for unpack200

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 d4976452847ce4448d89176fedb0e32ace6887c4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 14:52:18 2024 -0500

    Rename test package for unpack200
---
 .../harmony/unpack200/{tests => }/AbstractBandsTest.java       |  7 +------
 .../compress/harmony/unpack200/{tests => }/ArchiveTest.java    |  4 +---
 .../harmony/unpack200/{tests => }/AttributeLayoutMapTest.java  |  4 +---
 .../harmony/unpack200/{tests => }/AttributeLayoutTest.java     |  5 +----
 .../compress/harmony/unpack200/{tests => }/BandSetTest.java    |  5 +----
 .../compress/harmony/unpack200/{tests => }/BcBandsTest.java    |  8 +-------
 .../compress/harmony/unpack200/{tests => }/CPUTF8Test.java     |  2 +-
 .../compress/harmony/unpack200/{tests => }/ClassBandsTest.java |  5 +----
 .../harmony/unpack200/{tests => }/CodeAttributeTest.java       |  5 +----
 .../{tests => }/Codec_decodeInts_OutOfMemoryErrorTest.java     |  2 +-
 .../compress/harmony/unpack200/{tests => }/ICTupleTest.java    |  3 +--
 .../harmony/unpack200/{tests => }/NewAttributeBandsTest.java   |  5 +----
 .../{tests => }/SegmentConstantPoolArrayCacheTest.java         |  3 +--
 .../harmony/unpack200/{tests => }/SegmentConstantPoolTest.java |  5 +----
 .../harmony/unpack200/{tests => }/SegmentOptionsTest.java      |  3 +--
 .../compress/harmony/unpack200/{tests => }/SegmentTest.java    |  3 +--
 .../harmony/unpack200/{tests => }/SegmentUtilsTest.java        |  4 +---
 .../harmony/unpack200/{tests => }/bytecode/ByteCodeTest.java   |  3 +--
 .../unpack200/{tests => }/bytecode/ClassFileEntryTest.java     | 10 +---------
 .../unpack200/{tests => }/bytecode/ConstantPoolTest.java       |  6 +-----
 20 files changed, 20 insertions(+), 72 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/AbstractBandsTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/AbstractBandsTest.java
similarity index 85%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/AbstractBandsTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/AbstractBandsTest.java
index f39f07cf5..e5b8e1d7c 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/AbstractBandsTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/AbstractBandsTest.java
@@ -14,16 +14,11 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.fail;
 
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.unpack200.AttrDefinitionBands;
-import org.apache.commons.compress.harmony.unpack200.AttributeLayoutMap;
-import org.apache.commons.compress.harmony.unpack200.Segment;
-import org.apache.commons.compress.harmony.unpack200.SegmentHeader;
-import org.apache.commons.compress.harmony.unpack200.SegmentOptions;
 
 /**
  */
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ArchiveTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java
similarity index 98%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ArchiveTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java
index 98e1b1cd4..9b0d0cc10 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/ArchiveTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.Assert.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -43,8 +43,6 @@ import java.util.jar.JarOutputStream;
 import java.util.zip.ZipEntry;
 
 import org.apache.commons.compress.AbstractTempDirTest;
-import org.apache.commons.compress.harmony.unpack200.Archive;
-import org.apache.commons.compress.harmony.unpack200.Segment;
 import org.apache.commons.io.input.BoundedInputStream;
 import org.apache.commons.io.output.NullOutputStream;
 import org.junit.jupiter.api.AfterEach;
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/AttributeLayoutMapTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/AttributeLayoutMapTest.java
similarity index 92%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/AttributeLayoutMapTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/AttributeLayoutMapTest.java
index 7b634e87a..9e0af687f 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/AttributeLayoutMapTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/AttributeLayoutMapTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -22,8 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.unpack200.AttributeLayout;
-import org.apache.commons.compress.harmony.unpack200.AttributeLayoutMap;
 import org.junit.jupiter.api.Test;
 
 public class AttributeLayoutMapTest {
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/AttributeLayoutTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/AttributeLayoutTest.java
similarity index 96%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/AttributeLayoutTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/AttributeLayoutTest.java
index edac493b8..cda8b66e8 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/AttributeLayoutTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/AttributeLayoutTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -25,9 +25,6 @@ import java.util.stream.Stream;
 
 import org.apache.commons.compress.harmony.pack200.Codec;
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.unpack200.AttributeLayout;
-import org.apache.commons.compress.harmony.unpack200.Segment;
-import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool;
 import org.apache.commons.compress.harmony.unpack200.bytecode.CPUTF8;
 import org.apache.commons.compress.harmony.unpack200.bytecode.ClassFileEntry;
 import org.junit.jupiter.api.Test;
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/BandSetTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/BandSetTest.java
similarity index 91%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/BandSetTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/BandSetTest.java
index 7f6e988b2..6cef5988f 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/BandSetTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/BandSetTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
@@ -25,9 +25,6 @@ import java.io.InputStream;
 import org.apache.commons.compress.harmony.pack200.BHSDCodec;
 import org.apache.commons.compress.harmony.pack200.Codec;
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.unpack200.BandSet;
-import org.apache.commons.compress.harmony.unpack200.Segment;
-import org.apache.commons.compress.harmony.unpack200.SegmentHeader;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/BcBandsTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/BcBandsTest.java
similarity index 98%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/BcBandsTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/BcBandsTest.java
index 0c017be17..9b3fff94d 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/BcBandsTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/BcBandsTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
@@ -24,12 +24,6 @@ import java.io.InputStream;
 import java.util.ArrayList;
 
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.unpack200.AttrDefinitionBands;
-import org.apache.commons.compress.harmony.unpack200.BcBands;
-import org.apache.commons.compress.harmony.unpack200.ClassBands;
-import org.apache.commons.compress.harmony.unpack200.CpBands;
-import org.apache.commons.compress.harmony.unpack200.Segment;
-import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool;
 import org.apache.commons.compress.harmony.unpack200.bytecode.CPClass;
 import org.apache.commons.compress.harmony.unpack200.bytecode.CPDouble;
 import org.apache.commons.compress.harmony.unpack200.bytecode.CPFieldRef;
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/CPUTF8Test.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/CPUTF8Test.java
similarity index 95%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/CPUTF8Test.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/CPUTF8Test.java
index 228a2c65a..1ba328bdc 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/CPUTF8Test.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/CPUTF8Test.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ClassBandsTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/ClassBandsTest.java
similarity index 96%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ClassBandsTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/ClassBandsTest.java
index 971aa5f09..1957aff41 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ClassBandsTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/ClassBandsTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
@@ -25,9 +25,6 @@ import java.io.IOException;
 import org.apache.commons.compress.harmony.pack200.BHSDCodec;
 import org.apache.commons.compress.harmony.pack200.Codec;
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.unpack200.ClassBands;
-import org.apache.commons.compress.harmony.unpack200.CpBands;
-import org.apache.commons.compress.harmony.unpack200.Segment;
 import org.junit.jupiter.api.Test;
 
 /**
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/CodeAttributeTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/CodeAttributeTest.java
similarity index 96%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/CodeAttributeTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/CodeAttributeTest.java
index 5e2bf3a87..de5f86544 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/CodeAttributeTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/CodeAttributeTest.java
@@ -14,16 +14,13 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.compress.harmony.unpack200.CpBands;
-import org.apache.commons.compress.harmony.unpack200.Segment;
-import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool;
 import org.apache.commons.compress.harmony.unpack200.bytecode.CPFieldRef;
 import org.apache.commons.compress.harmony.unpack200.bytecode.CPMethodRef;
 import org.apache.commons.compress.harmony.unpack200.bytecode.CPString;
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/Codec_decodeInts_OutOfMemoryErrorTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/Codec_decodeInts_OutOfMemoryErrorTest.java
similarity index 98%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/Codec_decodeInts_OutOfMemoryErrorTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/Codec_decodeInts_OutOfMemoryErrorTest.java
index b6ad1058e..9f1edc732 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/Codec_decodeInts_OutOfMemoryErrorTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/Codec_decodeInts_OutOfMemoryErrorTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ICTupleTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/ICTupleTest.java
similarity index 95%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ICTupleTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/ICTupleTest.java
index b0e5e60bd..add432b68 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ICTupleTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/ICTupleTest.java
@@ -14,14 +14,13 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertAll;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.stream.Stream;
 
-import org.apache.commons.compress.harmony.unpack200.IcTuple;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/NewAttributeBandsTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/NewAttributeBandsTest.java
similarity index 97%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/NewAttributeBandsTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/NewAttributeBandsTest.java
index 7ef15400a..4b72d9df1 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/NewAttributeBandsTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/NewAttributeBandsTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -24,8 +24,6 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.unpack200.AttributeLayout;
-import org.apache.commons.compress.harmony.unpack200.NewAttributeBands;
 import org.apache.commons.compress.harmony.unpack200.NewAttributeBands.Call;
 import org.apache.commons.compress.harmony.unpack200.NewAttributeBands.Callable;
 import org.apache.commons.compress.harmony.unpack200.NewAttributeBands.Integral;
@@ -33,7 +31,6 @@ import org.apache.commons.compress.harmony.unpack200.NewAttributeBands.Reference
 import org.apache.commons.compress.harmony.unpack200.NewAttributeBands.Replication;
 import org.apache.commons.compress.harmony.unpack200.NewAttributeBands.Union;
 import org.apache.commons.compress.harmony.unpack200.NewAttributeBands.UnionCase;
-import org.apache.commons.compress.harmony.unpack200.Segment;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentConstantPoolArrayCacheTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentConstantPoolArrayCacheTest.java
similarity index 95%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentConstantPoolArrayCacheTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentConstantPoolArrayCacheTest.java
index cda9ee16d..5bc5415c6 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentConstantPoolArrayCacheTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentConstantPoolArrayCacheTest.java
@@ -15,13 +15,12 @@
  *  limitations under the License.
  */
 
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.List;
 
-import org.apache.commons.compress.harmony.unpack200.SegmentConstantPoolArrayCache;
 import org.junit.jupiter.api.Test;
 
 public class SegmentConstantPoolArrayCacheTest {
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentConstantPoolTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentConstantPoolTest.java
similarity index 95%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentConstantPoolTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentConstantPoolTest.java
index 82829febe..002238097 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentConstantPoolTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentConstantPoolTest.java
@@ -14,15 +14,12 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import org.apache.commons.compress.harmony.unpack200.CpBands;
-import org.apache.commons.compress.harmony.unpack200.Segment;
-import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool;
 import org.junit.jupiter.api.Test;
 
 /**
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentOptionsTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentOptionsTest.java
similarity index 91%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentOptionsTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentOptionsTest.java
index f3324b73b..7fd47e257 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentOptionsTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentOptionsTest.java
@@ -14,12 +14,11 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.unpack200.SegmentOptions;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
 
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentTest.java
similarity index 97%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentTest.java
index 76c2dc81b..5a3b8937a 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.Assert.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -36,7 +36,6 @@ import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
 
 import org.apache.commons.compress.AbstractTempDirTest;
-import org.apache.commons.compress.harmony.unpack200.Segment;
 import org.apache.commons.io.input.BoundedInputStream;
 import org.apache.commons.io.output.NullOutputStream;
 import org.junit.jupiter.api.Test;
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentUtilsTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentUtilsTest.java
similarity index 94%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentUtilsTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentUtilsTest.java
index 166a8c390..38bdf5423 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentUtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/SegmentUtilsTest.java
@@ -14,14 +14,12 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests;
+package org.apache.commons.compress.harmony.unpack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.stream.Stream;
 
-import org.apache.commons.compress.harmony.unpack200.IMatcher;
-import org.apache.commons.compress.harmony.unpack200.SegmentUtils;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/bytecode/ByteCodeTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/bytecode/ByteCodeTest.java
similarity index 91%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/bytecode/ByteCodeTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/bytecode/ByteCodeTest.java
index 3d4f023e6..b1372cfac 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/bytecode/ByteCodeTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/bytecode/ByteCodeTest.java
@@ -14,13 +14,12 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests.bytecode;
+package org.apache.commons.compress.harmony.unpack200.bytecode;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.stream.Stream;
 
-import org.apache.commons.compress.harmony.unpack200.bytecode.ByteCode;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/bytecode/ClassFileEntryTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/bytecode/ClassFileEntryTest.java
similarity index 86%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/bytecode/ClassFileEntryTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/bytecode/ClassFileEntryTest.java
index 591f831ba..dcc2db6ec 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/bytecode/ClassFileEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/bytecode/ClassFileEntryTest.java
@@ -14,20 +14,12 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests.bytecode;
+package org.apache.commons.compress.harmony.unpack200.bytecode;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import org.apache.commons.compress.harmony.unpack200.bytecode.CPDouble;
-import org.apache.commons.compress.harmony.unpack200.bytecode.CPFloat;
-import org.apache.commons.compress.harmony.unpack200.bytecode.CPInteger;
-import org.apache.commons.compress.harmony.unpack200.bytecode.CPLong;
-import org.apache.commons.compress.harmony.unpack200.bytecode.CPMember;
-import org.apache.commons.compress.harmony.unpack200.bytecode.CPString;
-import org.apache.commons.compress.harmony.unpack200.bytecode.CPUTF8;
-import org.apache.commons.compress.harmony.unpack200.bytecode.SourceFileAttribute;
 import org.junit.jupiter.api.Test;
 
 public class ClassFileEntryTest {
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/bytecode/ConstantPoolTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/bytecode/ConstantPoolTest.java
similarity index 86%
rename from src/test/java/org/apache/commons/compress/harmony/unpack200/tests/bytecode/ConstantPoolTest.java
rename to src/test/java/org/apache/commons/compress/harmony/unpack200/bytecode/ConstantPoolTest.java
index ea3985149..be1bb9a6a 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/bytecode/ConstantPoolTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/bytecode/ConstantPoolTest.java
@@ -14,16 +14,12 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.commons.compress.harmony.unpack200.tests.bytecode;
+package org.apache.commons.compress.harmony.unpack200.bytecode;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.apache.commons.compress.harmony.unpack200.Segment;
-import org.apache.commons.compress.harmony.unpack200.bytecode.CPClass;
-import org.apache.commons.compress.harmony.unpack200.bytecode.CPMember;
-import org.apache.commons.compress.harmony.unpack200.bytecode.CPUTF8;
-import org.apache.commons.compress.harmony.unpack200.bytecode.ClassConstantPool;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 


(commons-compress) 03/14: Internal refactoring

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 1d534c51a5127ae69c8a1fb96031576d98e8523a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 10:09:42 2024 -0500

    Internal refactoring
    
    - Move initialization of variables closer to use site
    - Throw exception on internal consistency  failure
    - Refactor magic string
---
 .../commons/compress/harmony/unpack200/CpBands.java  | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/CpBands.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/CpBands.java
index 6fdd4f307..bb30aff52 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/CpBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/CpBands.java
@@ -42,6 +42,8 @@ import org.apache.commons.compress.harmony.unpack200.bytecode.CPUTF8;
  */
 public class CpBands extends BandSet {
 
+    private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
     private final SegmentConstantPool pool = new SegmentConstantPool(this);
 
     private String[] cpClass;
@@ -397,8 +399,8 @@ public class CpBands extends BandSet {
 
     private void parseCpFloat(final InputStream in) throws IOException, Pack200Exception {
         final int cpFloatCount = header.getCpFloatCount();
-        cpFloat = new float[cpFloatCount];
         final int[] floatBits = decodeBandInt("cp_Float", in, Codec.UDELTA5, cpFloatCount);
+        cpFloat = new float[cpFloatCount];
         for (int i = 0; i < cpFloatCount; i++) {
             cpFloat[i] = Float.intBitsToFloat(floatBits[i]);
         }
@@ -524,10 +526,9 @@ public class CpBands extends BandSet {
 
     private void parseCpUtf8(final InputStream in) throws IOException, Pack200Exception {
         final int cpUTF8Count = header.getCpUTF8Count();
-        cpUTF8 = new String[cpUTF8Count];
-        mapUTF8 = new HashMap<>(cpUTF8Count + 1);
-        cpUTF8[0] = ""; //$NON-NLS-1$
-        mapUTF8.put("", Integer.valueOf(0));
+        if (cpUTF8Count <= 0) {
+            throw new IOException("cpUTF8Count value must be greater than 0");
+        }
         final int[] prefix = decodeBandInt("cpUTF8Prefix", in, Codec.DELTA5, cpUTF8Count - 2);
         int charCount = 0;
         int bigSuffixCount = 0;
@@ -540,8 +541,8 @@ public class CpBands extends BandSet {
                 charCount += element;
             }
         }
-        final char[] data = new char[charCount];
         final int[] dataBand = decodeBandInt("cp_Utf8_chars", in, Codec.CHAR3, charCount);
+        final char[] data = new char[charCount];
         for (int i = 0; i < data.length; i++) {
             data[i] = (char) dataBand[i];
         }
@@ -561,6 +562,13 @@ public class CpBands extends BandSet {
                 bigSuffixData[i][j] = (char) bigSuffixDataBand[i][j];
             }
         }
+
+        // Initialize variables
+        mapUTF8 = new HashMap<>(cpUTF8Count + 1);
+        cpUTF8 = new String[cpUTF8Count];
+        cpUTF8[0] = EMPTY_STRING;
+        mapUTF8.put(EMPTY_STRING, Integer.valueOf(0));
+
         // Go through the strings
         charCount = 0;
         bigSuffixCount = 0;


(commons-compress) 02/14: Internal refactoring

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 b845198e614576398d292c6f7d63af55ce496352
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 10:05:17 2024 -0500

    Internal refactoring
    
    - Move initialization of variables closer to use site
    - Throw exception on internal consistency  failure
---
 .../commons/compress/harmony/unpack200/BandSet.java     | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java
index bcd2cb1ce..b9eb7389d 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/BandSet.java
@@ -138,6 +138,9 @@ public abstract class BandSet {
         final int[] twoDResult = decodeBandInt(name, in, defaultCodec, totalCount);
         int index = 0;
         for (int i = 0; i < result.length; i++) {
+            if (counts[i] > twoDResult.length) {
+                throw new IOException("Counts value exceeds length of twoDResult");
+            }
             result[i] = new int[counts[i]];
             for (int j = 0; j < result[i].length; j++) {
                 result[i][j] = twoDResult[index];
@@ -282,18 +285,17 @@ public abstract class BandSet {
 
     protected CPUTF8[][] parseCPSignatureReferences(final String name, final InputStream in, final BHSDCodec codec, final int[] counts)
             throws IOException, Pack200Exception {
-        final CPUTF8[][] result = new CPUTF8[counts.length][];
         int sum = 0;
         for (int i = 0; i < counts.length; i++) {
-            result[i] = new CPUTF8[counts[i]];
             sum += counts[i];
         }
-        final CPUTF8[] result1 = new CPUTF8[sum];
         final int[] indices = decodeBandInt(name, in, codec, sum);
+        final CPUTF8[] result1 = new CPUTF8[sum];
         for (int i1 = 0; i1 < sum; i1++) {
             result1[i1] = segment.getCpBands().cpSignatureValue(indices[i1]);
         }
         int pos = 0;
+        final CPUTF8[][] result = new CPUTF8[counts.length][];
         for (int i = 0; i < counts.length; i++) {
             final int num = counts[i];
             result[i] = new CPUTF8[num];
@@ -367,7 +369,6 @@ public abstract class BandSet {
         int sum = 0;
         final long[][] result = new long[count][];
         for (int i = 0; i < count; i++) {
-            result[i] = new long[counts[i]];
             sum += counts[i];
         }
         int[] hi = null;
@@ -378,7 +379,8 @@ public abstract class BandSet {
         lo = decodeBandInt(name, in, loCodec, sum);
 
         int index = 0;
-        for (int i = 0; i < result.length; i++) {
+        for (int i = 0; i < count; i++) {
+            result[i] = new long[counts[i]];
             for (int j = 0; j < result[i].length; j++) {
                 if (hi != null) {
                     result[i][j] = (long) hi[index] << 32 | lo[index] & 4294967295L;
@@ -436,15 +438,13 @@ public abstract class BandSet {
         if (count == 0) {
             return new String[][] { {} };
         }
-        final String[][] result = new String[count][];
         int sum = 0;
         for (int i = 0; i < count; i++) {
-            result[i] = new String[counts[i]];
             sum += counts[i];
         }
         // TODO Merge the decode and parsing of a multiple structure into one
-        final String[] result1 = new String[sum];
         final int[] indices = decodeBandInt(name, in, codec, sum);
+        final String[] result1 = new String[sum];
         for (int i1 = 0; i1 < sum; i1++) {
             final int index = indices[i1];
             if (index < 0 || index >= reference.length) {
@@ -453,6 +453,7 @@ public abstract class BandSet {
             result1[i1] = reference[index];
         }
         // TODO Merge the decode and parsing of a multiple structure into one
+        final String[][] result = new String[count][];
         int pos = 0;
         for (int i = 0; i < count; i++) {
             final int num = counts[i];


(commons-compress) 09/14: Pack200Exception extends IOException

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 9f2f97925fdb52b5a3a32da6337ea1f113a3be82
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 11:09:30 2024 -0500

    Pack200Exception extends IOException
---
 .../commons/compress/harmony/pack200/Pack200Exception.java     | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java b/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java
index 16a5a2f56..1ba3f0156 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/Pack200Exception.java
@@ -16,17 +16,19 @@
  */
 package org.apache.commons.compress.harmony.pack200;
 
+import java.io.IOException;
+
 /**
- * Represents a problem with a Pack200 coding/decoding issue.
+ * Signals a problem with a Pack200 coding or decoding issue.
  */
-public class Pack200Exception extends Exception {
+public class Pack200Exception extends IOException {
 
     private static final long serialVersionUID = 5168177401552611803L;
 
     /**
-     * Creates a new Pack200 exception with the given message
+     * Constructs a new Pack200 exception with the given message
      *
-     * @param message the text message to display
+     * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method).
      */
     public Pack200Exception(final String message) {
         super(message);


(commons-compress) 11/14: Internal refactoring

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 b778b64d01811046ae5c69c94012508dde1c58b3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 14:35:32 2024 -0500

    Internal refactoring
---
 .../commons/compress/harmony/pack200/Codec.java    |  25 ++++++++-
 .../compress/harmony/pack200/PopulationCodec.java  |   2 +-
 .../commons/compress/harmony/pack200/RunCodec.java |   2 +-
 .../compress/harmony/unpack200/Archive.java        |  60 ++++++++++++---------
 .../harmony/unpack200/Pack200UnpackerAdapter.java  |  16 ++++++
 .../compress/harmony/unpack200/Segment.java        |   6 +--
 .../commons/compress/utils/BoundedInputStream.java |   6 +++
 .../harmony/pack200/tests/RunCodecTest.java        |  30 +++++++++++
 .../harmony/unpack200/tests/ArchiveTest.java       |  34 ++++++++++++
 .../harmony/unpack200/tests/SegmentTest.java       |  35 ++++++++++++
 .../apache/commons/compress/pack/bandint_oom.pack  | Bin 0 -> 88 bytes
 .../apache/commons/compress/pack/cpfloat_oom.pack  | Bin 0 -> 178 bytes
 .../apache/commons/compress/pack/cputf8_oom.pack   | Bin 0 -> 427 bytes
 .../apache/commons/compress/pack/favoured_oom.pack | Bin 0 -> 84 bytes
 .../apache/commons/compress/pack/filebits_oom.pack | Bin 0 -> 309 bytes
 .../apache/commons/compress/pack/flags_oom.pack    | Bin 0 -> 1624 bytes
 .../commons/compress/pack/references_oom.pack      | Bin 0 -> 66 bytes
 .../commons/compress/pack/segment_header_oom.pack  | Bin 0 -> 41 bytes
 .../commons/compress/pack/signatures_oom.pack      | Bin 0 -> 121 bytes
 19 files changed, 183 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/Codec.java b/src/main/java/org/apache/commons/compress/harmony/pack200/Codec.java
index a3f4d43f8..a575558ba 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/Codec.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/Codec.java
@@ -19,6 +19,8 @@ package org.apache.commons.compress.harmony.pack200;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.io.input.BoundedInputStream;
+
 /**
  * A Codec allows a sequence of bytes to be decoded into integer values (or vice versa).
  * <p>
@@ -123,7 +125,7 @@ public abstract class Codec {
      */
     public int[] decodeInts(final int n, final InputStream in) throws IOException, Pack200Exception {
         lastBandLength = 0;
-        final int[] result = new int[n];
+        final int[] result = new int[check(n, in)];
         int last = 0;
         for (int i = 0; i < n; i++) {
             result[i] = last = decode(in, last);
@@ -142,7 +144,7 @@ public abstract class Codec {
      * @throws Pack200Exception if there is a problem decoding the value or that the value is invalid
      */
     public int[] decodeInts(final int n, final InputStream in, final int firstValue) throws IOException, Pack200Exception {
-        final int[] result = new int[n + 1];
+        final int[] result = new int[check(n + 1, in)];
         result[0] = firstValue;
         int last = firstValue;
         for (int i = 1; i < n + 1; i++) {
@@ -151,6 +153,25 @@ public abstract class Codec {
         return result;
     }
 
+    int check(final int n, final InputStream in) throws Pack200Exception {
+        if (in instanceof BoundedInputStream) {
+            final BoundedInputStream bin = (BoundedInputStream) in;
+            final long count = bin.getCount();
+            final long maxLength = bin.getMaxLength();
+            if (maxLength > -1) {
+                final long remaining = maxLength - count;
+                final String format = "Can't read beyond end of stream (n = %,d, count = %,d, maxLength = %,d, remaining = %,d)";
+                if (count < -1) {
+                    throw new Pack200Exception(String.format(format, n, count, maxLength, remaining));
+                }
+                if (n > remaining) {
+                    throw new Pack200Exception(String.format(format, n, count, maxLength, remaining));
+                }
+            }
+        }
+        return n;
+    }
+
     /**
      * Encodes a single value into a sequence of bytes. Note that this method can only be used for non-delta encodings.
      *
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/PopulationCodec.java b/src/main/java/org/apache/commons/compress/harmony/pack200/PopulationCodec.java
index 1ac615995..d32c55701 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/PopulationCodec.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/PopulationCodec.java
@@ -60,7 +60,7 @@ public class PopulationCodec extends Codec {
     @Override
     public int[] decodeInts(final int n, final InputStream in) throws IOException, Pack200Exception {
         lastBandLength = 0;
-        favoured = new int[n]; // there must be <= n values, but probably a lot
+        favoured = new int[check(n, in)]; // there must be <= n values, but probably a lot
         // less
         int[] result;
         // read table of favorites first
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/RunCodec.java b/src/main/java/org/apache/commons/compress/harmony/pack200/RunCodec.java
index 1d0902b85..883a3095e 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/RunCodec.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/RunCodec.java
@@ -67,7 +67,7 @@ public class RunCodec extends Codec {
         normalise(aValues, aCodec);
         final int[] bValues = bCodec.decodeInts(n - k, in);
         normalise(bValues, bCodec);
-        final int[] band = new int[n];
+        final int[] band = new int[check(n, in)];
         System.arraycopy(aValues, 0, band, 0, k);
         System.arraycopy(bValues, 0, band, k, n - k);
         lastBandLength = aCodec.lastBandLength + bCodec.lastBandLength;
diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java
index 6b41eff9e..f70c56ca9 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java
@@ -18,13 +18,16 @@ package org.apache.commons.compress.harmony.unpack200;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
-import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
@@ -32,6 +35,7 @@ import java.util.zip.GZIPInputStream;
 
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.input.BoundedInputStream;
 
 /**
  * Archive is the main entry point to unpack200. An archive is constructed with either two file names, a pack file and an output file name or an input stream
@@ -39,7 +43,7 @@ import org.apache.commons.io.IOUtils;
  */
 public class Archive {
 
-    private InputStream inputStream;
+    private BoundedInputStream inputStream;
 
     private final JarOutputStream outputStream;
 
@@ -53,10 +57,14 @@ public class Archive {
 
     private boolean deflateHint;
 
-    private String inputFileName;
+    private final Path inputPath;
+
+    private final long inputSize;
 
     private String outputFileName;
 
+    private static final int[] MAGIC = { 0xCA, 0xFE, 0xD0, 0x0D };
+
     /**
      * Creates an Archive with streams for the input and output files. Note: If you use this method then calling {@link #setRemovePackFile(boolean)} will have
      * no effect.
@@ -65,8 +73,18 @@ public class Archive {
      * @param outputStream TODO
      */
     public Archive(final InputStream inputStream, final JarOutputStream outputStream) {
-        this.inputStream = inputStream;
+        this.inputStream = inputStream instanceof BoundedInputStream ? (BoundedInputStream) inputStream : new BoundedInputStream(inputStream);
         this.outputStream = outputStream;
+        if (inputStream instanceof FileInputStream) {
+            try {
+                inputPath = Paths.get(((FileInputStream) inputStream).getFD().toString());
+            } catch (final IOException e) {
+                throw new UncheckedIOException(e);
+            }
+        } else {
+            inputPath = null;
+        }
+        this.inputSize = -1;
     }
 
     /**
@@ -79,9 +97,10 @@ public class Archive {
      * @throws IOException           TODO
      */
     public Archive(final String inputFileName, final String outputFileName) throws FileNotFoundException, IOException {
-        this.inputFileName = inputFileName;
+        this.inputPath = Paths.get(inputFileName);
         this.outputFileName = outputFileName;
-        this.inputStream = new FileInputStream(inputFileName);
+        this.inputSize = Files.size(this.inputPath);
+        this.inputStream = new BoundedInputStream(Files.newInputStream(inputPath), inputSize);
         this.outputStream = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(outputFileName)));
     }
 
@@ -138,7 +157,7 @@ public class Archive {
         outputStream.setComment("PACK200");
         try {
             if (!inputStream.markSupported()) {
-                inputStream = new BufferedInputStream(inputStream);
+                inputStream = new BoundedInputStream(new BufferedInputStream(inputStream));
                 if (!inputStream.markSupported()) {
                     throw new IllegalStateException();
                 }
@@ -146,20 +165,19 @@ public class Archive {
             inputStream.mark(2);
             if ((inputStream.read() & 0xFF | (inputStream.read() & 0xFF) << 8) == GZIPInputStream.GZIP_MAGIC) {
                 inputStream.reset();
-                inputStream = new BufferedInputStream(new GZIPInputStream(inputStream));
+                inputStream = new BoundedInputStream(new BufferedInputStream(new GZIPInputStream(inputStream)));
             } else {
                 inputStream.reset();
             }
-            inputStream.mark(4);
-            final int[] magic = { 0xCA, 0xFE, 0xD0, 0x0D }; // Magic word for
+            inputStream.mark(MAGIC.length);
             // pack200
-            final int[] word = new int[4];
+            final int[] word = new int[MAGIC.length];
             for (int i = 0; i < word.length; i++) {
                 word[i] = inputStream.read();
             }
             boolean compressedWithE0 = false;
-            for (int m = 0; m < magic.length; m++) {
-                if (word[m] != magic[m]) {
+            for (int m = 0; m < MAGIC.length; m++) {
+                if (word[m] != MAGIC[m]) {
                     compressedWithE0 = true;
                 }
             }
@@ -188,7 +206,7 @@ public class Archive {
                     segment.setPreRead(false);
 
                     if (i == 1) {
-                        segment.log(Segment.LOG_LEVEL_VERBOSE, "Unpacking from " + inputFileName + " to " + outputFileName);
+                        segment.log(Segment.LOG_LEVEL_VERBOSE, "Unpacking from " + inputPath + " to " + outputFileName);
                     }
                     segment.log(Segment.LOG_LEVEL_VERBOSE, "Reading segment " + i);
                     if (overrideDeflateHint) {
@@ -196,10 +214,6 @@ public class Archive {
                     }
                     segment.unpack(inputStream, outputStream);
                     outputStream.flush();
-
-                    if (inputStream instanceof FileInputStream) {
-                        inputFileName = ((FileInputStream) inputStream).getFD().toString();
-                    }
                 }
             }
         } finally {
@@ -207,14 +221,8 @@ public class Archive {
             IOUtils.closeQuietly(outputStream);
             IOUtils.closeQuietly(logFile);
         }
-        if (removePackFile) {
-            boolean deleted = false;
-            if (inputFileName != null) {
-                deleted = new File(inputFileName).delete();
-            }
-            if (!deleted) {
-                throw new Pack200Exception("Failed to delete the input file.");
-            }
+        if (removePackFile && inputPath != null) {
+            Files.delete(inputPath);
         }
     }
 
diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
index 2c725fee2..f8038ba71 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
@@ -21,17 +21,33 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.jar.JarOutputStream;
 
 import org.apache.commons.compress.harmony.pack200.Pack200Adapter;
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
 import org.apache.commons.compress.java.util.jar.Pack200.Unpacker;
+import org.apache.commons.io.input.BoundedInputStream;
 
 /**
  * This class provides the binding between the standard Pack200 interface and the internal interface for (un)packing.
  */
 public class Pack200UnpackerAdapter extends Pack200Adapter implements Unpacker {
 
+    static BoundedInputStream newBoundedInputStream(final File file) throws IOException {
+        return newBoundedInputStream(file.toPath());
+    }
+
+    @SuppressWarnings("resource")
+    static BoundedInputStream newBoundedInputStream(final Path inputPath) throws IOException {
+        return new BoundedInputStream(new BufferedInputStream(Files.newInputStream(inputPath)), Files.size(inputPath));
+    }
+
+    static BoundedInputStream newBoundedInputStream(final String first, final String... more) throws IOException {
+        return newBoundedInputStream(Paths.get(first, more));
+    }
+
     @Override
     public void unpack(final File file, final JarOutputStream out) throws IOException {
         if (file == null || out == null) {
diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
index 014db4938..576fead75 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
@@ -462,13 +462,13 @@ public class Segment {
     /**
      * Unpacks a packed stream (either .pack. or .pack.gz) into a corresponding JarOuputStream.
      *
-     * @param in  a packed stream.
+     * @param inputStream  a packed input stream.
      * @param out output stream.
      * @throws Pack200Exception if there is a problem unpacking
      * @throws IOException      if there is a problem with I/O during unpacking
      */
-    public void unpack(final InputStream in, final JarOutputStream out) throws IOException, Pack200Exception {
-        unpackRead(in);
+    public void unpack(final InputStream inputStream, final JarOutputStream out) throws IOException, Pack200Exception {
+        unpackRead(inputStream);
         unpackProcess();
         unpackWrite(out);
     }
diff --git a/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java b/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
index 8da853372..b4622c8b3 100644
--- a/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
@@ -49,4 +49,10 @@ public class BoundedInputStream extends org.apache.commons.io.input.BoundedInput
         return getMaxLength() - getCount();
     }
 
+//    @Override
+//    protected void onMaxLength(long maxLength, long count) throws IOException {
+//        if (count > maxLength) {
+//            throw new IOException("Can't read past EOF.");
+//        }
+//    }
 }
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/RunCodecTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/RunCodecTest.java
index 0cb488fdd..cc86a288d 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/RunCodecTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/RunCodecTest.java
@@ -20,12 +20,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.util.stream.Stream;
 
 import org.apache.commons.compress.harmony.pack200.Codec;
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
 import org.apache.commons.compress.harmony.pack200.PopulationCodec;
 import org.apache.commons.compress.harmony.pack200.RunCodec;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
@@ -76,6 +78,21 @@ public class RunCodecTest {
         }
     }
 
+    @Disabled
+    @Test
+    public void testRunCodecDecodeIntsOverflow() throws Exception {
+        final byte[] bytes1 = Codec.DELTA5.encode(new int[] { 1, -2, -3, 1000, 55 });
+        final byte[] bytes2 = Codec.UNSIGNED5.encode(new int[] { 5, 10, 20 });
+        final byte[] bandEncoded = new byte[bytes1.length + bytes2.length];
+        System.arraycopy(bytes1, 0, bandEncoded, 0, bytes1.length);
+        System.arraycopy(bytes2, 0, bandEncoded, bytes1.length, bytes2.length);
+        final RunCodec runCodec = new RunCodec(5, Codec.DELTA5, Codec.UNSIGNED5);
+
+        // Should only throw an IOException and not an OutOfMemoryError
+        assertThrows(IOException.class, () -> runCodec.decodeInts(Integer.MAX_VALUE - 1, new ByteArrayInputStream(bandEncoded)));
+        assertThrows(IOException.class, () -> runCodec.decodeInts(Integer.MAX_VALUE - 1, new ByteArrayInputStream(bandEncoded), 1));
+    }
+
     @Test
     public void testEncodeSingleValue() {
         assertThrows(Pack200Exception.class, () -> new RunCodec(10, Codec.SIGNED5, Codec.UDELTA5).encode(5),
@@ -104,6 +121,19 @@ public class RunCodecTest {
         }
     }
 
+    @Disabled
+    @Test
+    public void testPopulationCodecDecodeIntsOverflow() throws Exception {
+        final byte[] bytes1 = Codec.DELTA5.encode(new int[] { 11, 12, 33, 4000, -555 });
+        final PopulationCodec popCodec = new PopulationCodec(Codec.UNSIGNED5, Codec.BYTE1, Codec.UNSIGNED5);
+        final byte[] bytes2 = popCodec.encode(new int[] { 10, 20 }, new int[] { 0, 1, 2, 1, 0, 2, 2, 2, 1, 1, 0, 2, 0, 1, 1, 0, 0 },
+                new int[] { 5, 3, 999, 789, 355, 12345 });
+        final byte[] bandEncoded = new byte[bytes1.length + bytes2.length];
+
+        // Should only throw an IOException and not an OutOfMemoryError
+        assertThrows(IOException.class, () -> popCodec.decodeInts(Integer.MAX_VALUE - 1, new ByteArrayInputStream(bandEncoded)));
+    }
+
     @Test
     public void testNestedRunCodec() throws Exception {
         final int[] band = { 1, 2, 3, 10, 20, 30, 100, 200, 300 };
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ArchiveTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ArchiveTest.java
index f169af182..98e1b1cd4 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/ArchiveTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.compress.harmony.unpack200.tests;
 
+import static org.junit.Assert.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -31,6 +32,10 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Enumeration;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
@@ -39,8 +44,13 @@ import java.util.zip.ZipEntry;
 
 import org.apache.commons.compress.AbstractTempDirTest;
 import org.apache.commons.compress.harmony.unpack200.Archive;
+import org.apache.commons.compress.harmony.unpack200.Segment;
+import org.apache.commons.io.input.BoundedInputStream;
+import org.apache.commons.io.output.NullOutputStream;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * Tests for org.apache.commons.compress.harmony.unpack200.Archive, which is the main class for unpack200.
@@ -176,6 +186,30 @@ public class ArchiveTest extends AbstractTempDirTest {
         }
     }
 
+    @ParameterizedTest
+    @ValueSource(strings = {
+    // @formatter:off
+            "bandint_oom.pack",
+            "cpfloat_oom.pack",
+            "cputf8_oom.pack",
+            "favoured_oom.pack",
+            "filebits_oom.pack",
+            "flags_oom.pack",
+            "references_oom.pack",
+            "segment_header_oom.pack",
+            "signatures_oom.pack"
+            // @formatter:on
+    })
+    // Tests of various files that can cause out of memory errors
+    public void testParsingOOM(final String testFileName) throws Exception {
+        final URL url = Segment.class.getResource("/org/apache/commons/compress/pack/" + testFileName);
+        final Path path = Paths.get(url.toURI());
+        try (InputStream in = new BoundedInputStream(new BufferedInputStream(Files.newInputStream(path)), Files.size(path));
+                JarOutputStream out = new JarOutputStream(NullOutputStream.INSTANCE)) {
+            assertThrows(IOException.class, () -> new Archive(in, out).unpack());
+        }
+    }
+
     @Test
     public void testRemovePackFile() throws Exception {
         final File original = new File(Archive.class.getResource("/pack200/sql.pack.gz").toURI());
diff --git a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentTest.java b/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentTest.java
index d3dd7f338..76c2dc81b 100644
--- a/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/unpack200/tests/SegmentTest.java
@@ -16,21 +16,32 @@
  */
 package org.apache.commons.compress.harmony.unpack200.tests;
 
+import static org.junit.Assert.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
+import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
 
 import org.apache.commons.compress.AbstractTempDirTest;
 import org.apache.commons.compress.harmony.unpack200.Segment;
+import org.apache.commons.io.input.BoundedInputStream;
+import org.apache.commons.io.output.NullOutputStream;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * Tests for org.apache.commons.compress.harmony.unpack200.Segment.
@@ -88,4 +99,28 @@ public class SegmentTest extends AbstractTempDirTest {
         }
     }
 
+    @ParameterizedTest
+    @ValueSource(strings = {
+    // @formatter:off
+            "bandint_oom.pack",
+            "cpfloat_oom.pack",
+            "cputf8_oom.pack",
+            "favoured_oom.pack",
+            "filebits_oom.pack",
+            "flags_oom.pack",
+            "references_oom.pack",
+            "segment_header_oom.pack",
+            "signatures_oom.pack"
+            // @formatter:on
+    })
+    // Tests of various files that can cause out of memory errors
+    public void testParsingOOM(final String testFileName) throws Exception {
+        final URL url = Segment.class.getResource("/org/apache/commons/compress/pack/" + testFileName);
+        final Path path = Paths.get(url.toURI());
+        try (InputStream in = new BoundedInputStream(new BufferedInputStream(Files.newInputStream(path)), Files.size(path));
+                JarOutputStream out = new JarOutputStream(NullOutputStream.INSTANCE)) {
+            assertThrows(IOException.class, () -> new Segment().unpack(in, out));
+        }
+    }
+
 }
diff --git a/src/test/resources/org/apache/commons/compress/pack/bandint_oom.pack b/src/test/resources/org/apache/commons/compress/pack/bandint_oom.pack
new file mode 100644
index 000000000..ad011e5f2
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/pack/bandint_oom.pack differ
diff --git a/src/test/resources/org/apache/commons/compress/pack/cpfloat_oom.pack b/src/test/resources/org/apache/commons/compress/pack/cpfloat_oom.pack
new file mode 100644
index 000000000..29255d14f
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/pack/cpfloat_oom.pack differ
diff --git a/src/test/resources/org/apache/commons/compress/pack/cputf8_oom.pack b/src/test/resources/org/apache/commons/compress/pack/cputf8_oom.pack
new file mode 100644
index 000000000..88632cb9c
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/pack/cputf8_oom.pack differ
diff --git a/src/test/resources/org/apache/commons/compress/pack/favoured_oom.pack b/src/test/resources/org/apache/commons/compress/pack/favoured_oom.pack
new file mode 100644
index 000000000..658be7f5f
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/pack/favoured_oom.pack differ
diff --git a/src/test/resources/org/apache/commons/compress/pack/filebits_oom.pack b/src/test/resources/org/apache/commons/compress/pack/filebits_oom.pack
new file mode 100644
index 000000000..282967e47
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/pack/filebits_oom.pack differ
diff --git a/src/test/resources/org/apache/commons/compress/pack/flags_oom.pack b/src/test/resources/org/apache/commons/compress/pack/flags_oom.pack
new file mode 100644
index 000000000..2608ee02d
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/pack/flags_oom.pack differ
diff --git a/src/test/resources/org/apache/commons/compress/pack/references_oom.pack b/src/test/resources/org/apache/commons/compress/pack/references_oom.pack
new file mode 100644
index 000000000..b613eaa4d
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/pack/references_oom.pack differ
diff --git a/src/test/resources/org/apache/commons/compress/pack/segment_header_oom.pack b/src/test/resources/org/apache/commons/compress/pack/segment_header_oom.pack
new file mode 100644
index 000000000..033967067
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/pack/segment_header_oom.pack differ
diff --git a/src/test/resources/org/apache/commons/compress/pack/signatures_oom.pack b/src/test/resources/org/apache/commons/compress/pack/signatures_oom.pack
new file mode 100644
index 000000000..aa4b2fc79
Binary files /dev/null and b/src/test/resources/org/apache/commons/compress/pack/signatures_oom.pack differ


(commons-compress) 12/14: Rename test package for pack200

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 48333267c7ec2f4e9023ca204939d3e2529909d9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 14:39:10 2024 -0500

    Rename test package for pack200
---
 .../compress/harmony/pack200/{tests => }/ArchiveTest.java      |  5 +----
 .../compress/harmony/pack200/{tests => }/BHSDCodecTest.java    |  6 +-----
 .../harmony/pack200/{tests => }/CodecEncodingTest.java         |  8 +-------
 .../compress/harmony/pack200/{tests => }/CodecTest.java        |  6 +-----
 .../compress/harmony/pack200/{tests => }/Compress626Test.java  |  5 +----
 .../compress/harmony/pack200/{tests => }/Compress628Test.java  |  5 +----
 .../compress/harmony/pack200/{tests => }/HelloWorld.java       |  2 +-
 .../harmony/pack200/{tests => }/NewAttributeBandsTest.java     | 10 +---------
 .../harmony/pack200/{tests => }/PackingOptionsTest.java        |  6 +-----
 .../harmony/pack200/{tests => }/PopulationCodecTest.java       |  5 +----
 .../compress/harmony/pack200/{tests => }/RunCodecTest.java     |  6 +-----
 11 files changed, 11 insertions(+), 53 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/ArchiveTest.java
similarity index 98%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/ArchiveTest.java
index 9a615fab1..0589db47e 100755
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/ArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/ArchiveTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -38,9 +38,6 @@ import java.util.jar.JarOutputStream;
 import java.util.stream.Stream;
 
 import org.apache.commons.compress.AbstractTempDirTest;
-import org.apache.commons.compress.harmony.pack200.Archive;
-import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.pack200.PackingOptions;
 import org.apache.commons.compress.harmony.unpack200.Segment;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/BHSDCodecTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/BHSDCodecTest.java
similarity index 91%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/BHSDCodecTest.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/BHSDCodecTest.java
index 2b650d0cd..15f9e29f5 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/BHSDCodecTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/BHSDCodecTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.fail;
@@ -25,10 +25,6 @@ import java.io.IOException;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
-import org.apache.commons.compress.harmony.pack200.BHSDCodec;
-import org.apache.commons.compress.harmony.pack200.Codec;
-import org.apache.commons.compress.harmony.pack200.CodecEncoding;
-import org.apache.commons.compress.harmony.pack200.Pack200Exception;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/CodecEncodingTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/CodecEncodingTest.java
similarity index 96%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/CodecEncodingTest.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/CodecEncodingTest.java
index 6be6b7f77..e9e6c9f09 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/CodecEncodingTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/CodecEncodingTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -25,12 +25,6 @@ import java.io.InputStream;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
-import org.apache.commons.compress.harmony.pack200.BHSDCodec;
-import org.apache.commons.compress.harmony.pack200.Codec;
-import org.apache.commons.compress.harmony.pack200.CodecEncoding;
-import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.pack200.PopulationCodec;
-import org.apache.commons.compress.harmony.pack200.RunCodec;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/CodecTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/CodecTest.java
similarity index 97%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/CodecTest.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/CodecTest.java
index 6ca70a616..433516113 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/CodecTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/CodecTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -29,10 +29,6 @@ import java.io.IOException;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
-import org.apache.commons.compress.harmony.pack200.BHSDCodec;
-import org.apache.commons.compress.harmony.pack200.CanonicalCodecFamilies;
-import org.apache.commons.compress.harmony.pack200.Codec;
-import org.apache.commons.compress.harmony.pack200.Pack200Exception;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/Compress626Test.java b/src/test/java/org/apache/commons/compress/harmony/pack200/Compress626Test.java
similarity index 88%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/Compress626Test.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/Compress626Test.java
index 2ca9db5e8..096d53aa5 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/Compress626Test.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/Compress626Test.java
@@ -15,7 +15,7 @@
  *  limitations under the License.
  */
 
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 
@@ -25,9 +25,6 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.jar.JarOutputStream;
 
-import org.apache.commons.compress.harmony.pack200.AttributeDefinitionBands;
-import org.apache.commons.compress.harmony.pack200.CPUTF8;
-import org.apache.commons.compress.harmony.pack200.NewAttributeBands;
 import org.apache.commons.compress.java.util.jar.Pack200;
 import org.apache.commons.io.output.NullOutputStream;
 import org.junit.jupiter.api.Test;
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/Compress628Test.java b/src/test/java/org/apache/commons/compress/harmony/pack200/Compress628Test.java
similarity index 83%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/Compress628Test.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/Compress628Test.java
index 3f8b5aa20..d19d15df8 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/Compress628Test.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/Compress628Test.java
@@ -15,13 +15,10 @@
  *  limitations under the License.
  */
 
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 
-import org.apache.commons.compress.harmony.pack200.AttributeDefinitionBands;
-import org.apache.commons.compress.harmony.pack200.CPUTF8;
-import org.apache.commons.compress.harmony.pack200.NewAttributeBands;
 import org.junit.jupiter.api.Test;
 
 public class Compress628Test {
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/HelloWorld.java b/src/test/java/org/apache/commons/compress/harmony/pack200/HelloWorld.java
similarity index 95%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/HelloWorld.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/HelloWorld.java
index 2d9f36216..a1f61ae49 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/HelloWorld.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/HelloWorld.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 /**
  * This is intended to be used as a test class for unpacking a packed Jar file.
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/NewAttributeBandsTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/NewAttributeBandsTest.java
similarity index 96%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/NewAttributeBandsTest.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/NewAttributeBandsTest.java
index e995610a8..ffb5068e4 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/NewAttributeBandsTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/NewAttributeBandsTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -25,13 +25,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.List;
 
-import org.apache.commons.compress.harmony.pack200.AttributeDefinitionBands;
 import org.apache.commons.compress.harmony.pack200.AttributeDefinitionBands.AttributeDefinition;
-import org.apache.commons.compress.harmony.pack200.CPUTF8;
-import org.apache.commons.compress.harmony.pack200.Codec;
-import org.apache.commons.compress.harmony.pack200.CpBands;
-import org.apache.commons.compress.harmony.pack200.NewAttribute;
-import org.apache.commons.compress.harmony.pack200.NewAttributeBands;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.AttributeLayoutElement;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Call;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Callable;
@@ -41,8 +35,6 @@ import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Reference;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Replication;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Union;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.UnionCase;
-import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.pack200.SegmentHeader;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/PackingOptionsTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/PackingOptionsTest.java
similarity index 98%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/PackingOptionsTest.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/PackingOptionsTest.java
index 3cb5c4e42..f6d3b7ff7 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/PackingOptionsTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/PackingOptionsTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -39,10 +39,6 @@ import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
 
 import org.apache.commons.compress.AbstractTempDirTest;
-import org.apache.commons.compress.harmony.pack200.Archive;
-import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.pack200.PackingOptions;
-import org.apache.commons.compress.harmony.pack200.PackingUtils;
 import org.junit.jupiter.api.Test;
 
 /**
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/PopulationCodecTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/PopulationCodecTest.java
similarity index 93%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/PopulationCodecTest.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/PopulationCodecTest.java
index 82e28ad7c..70671cb3c 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/PopulationCodecTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/PopulationCodecTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -24,9 +24,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.stream.Stream;
 
-import org.apache.commons.compress.harmony.pack200.Codec;
-import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.pack200.PopulationCodec;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/RunCodecTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/RunCodecTest.java
similarity index 96%
rename from src/test/java/org/apache/commons/compress/harmony/pack200/tests/RunCodecTest.java
rename to src/test/java/org/apache/commons/compress/harmony/pack200/RunCodecTest.java
index cc86a288d..3f217c571 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/RunCodecTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/RunCodecTest.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.commons.compress.harmony.pack200.tests;
+package org.apache.commons.compress.harmony.pack200;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -23,10 +23,6 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.stream.Stream;
 
-import org.apache.commons.compress.harmony.pack200.Codec;
-import org.apache.commons.compress.harmony.pack200.Pack200Exception;
-import org.apache.commons.compress.harmony.pack200.PopulationCodec;
-import org.apache.commons.compress.harmony.pack200.RunCodec;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;


(commons-compress) 10/14: Preserve input argument

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 6f007a3f43f5c2651eac994b8e64b268acbca7b2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 11:16:15 2024 -0500

    Preserve input argument
    
    For debugging
---
 .../java/org/apache/commons/compress/harmony/unpack200/Segment.java | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
index 00fbc0294..014db4938 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/Segment.java
@@ -483,10 +483,8 @@ public class Segment {
     /*
      * Package-private accessors for unpacking stages
      */
-    void unpackRead(InputStream in) throws IOException, Pack200Exception {
-        if (!in.markSupported()) {
-            in = new BufferedInputStream(in);
-        }
+    void unpackRead(final InputStream inputStream) throws IOException, Pack200Exception {
+        final InputStream in = inputStream.markSupported() ? inputStream : new BufferedInputStream(inputStream);
 
         header = new SegmentHeader(this);
         header.read(in);


(commons-compress) 06/14: Reuse IOUtils.readRange()

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 0df503de8cb080117191e07091c748db5aa33e26
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 10:13:46 2024 -0500

    Reuse IOUtils.readRange()
---
 .../compress/harmony/unpack200/SegmentHeader.java  | 28 ++--------------------
 1 file changed, 2 insertions(+), 26 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java
index 01b1b12d4..a83057518 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java
@@ -17,13 +17,13 @@
 package org.apache.commons.compress.harmony.unpack200;
 
 import java.io.ByteArrayInputStream;
-import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.commons.compress.harmony.pack200.BHSDCodec;
 import org.apache.commons.compress.harmony.pack200.Codec;
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
+import org.apache.commons.compress.utils.IOUtils;
 
 /**
  * SegmentHeader is the header band of a {@link Segment}
@@ -299,36 +299,12 @@ public class SegmentHeader {
         parseClassCounts(in);
 
         if (getBandHeadersSize() > 0) {
-            final byte[] bandHeaders = new byte[getBandHeadersSize()];
-            readFully(in, bandHeaders);
-            setBandHeadersData(bandHeaders);
+            setBandHeadersData(IOUtils.readRange(in, getBandHeadersSize()));
         }
 
         archiveSizeOffset -= in.available();
     }
 
-    /**
-     * Completely reads in a byte array, akin to the implementation in {@link java.io.DataInputStream}. TODO Refactor out into a separate InputStream handling
-     * class
-     *
-     * @param in   the input stream to read from
-     * @param data the byte array to read into
-     * @throws IOException if a problem occurs during reading from the underlying stream
-     */
-    private void readFully(final InputStream in, final byte[] data) throws IOException {
-        int total = in.read(data);
-        if (total == -1) {
-            throw new EOFException("Failed to read any data from input stream");
-        }
-        while (total < data.length) {
-            final int delta = in.read(data, total, data.length - total);
-            if (delta == -1) {
-                throw new EOFException("Failed to read some data from input stream");
-            }
-            total += delta;
-        }
-    }
-
     /**
      * Sets the major version of this archive.
      *


(commons-compress) 04/14: Reuse IOUtils.readRange()

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 9399923c47e7dd9b2a202be21770b4d42dcdddda
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 10:10:48 2024 -0500

    Reuse IOUtils.readRange()
---
 .../apache/commons/compress/harmony/unpack200/FileBands.java   | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/unpack200/FileBands.java b/src/main/java/org/apache/commons/compress/harmony/unpack200/FileBands.java
index e6db16fda..6aab4eed5 100644
--- a/src/main/java/org/apache/commons/compress/harmony/unpack200/FileBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/unpack200/FileBands.java
@@ -73,18 +73,16 @@ public class FileBands extends BandSet {
     }
 
     // TODO: stream the file bits directly somehow
-    public void processFileBits() throws IOException, Pack200Exception {
+    public void processFileBits() throws IOException {
         // now read in the bytes
         final int numberOfFiles = header.getNumberOfFiles();
         fileBits = new byte[numberOfFiles][];
         for (int i = 0; i < numberOfFiles; i++) {
             final int size = (int) fileSize[i];
-            // TODO This breaks if file_size > 2^32. Probably an array is
-            // not the right choice, and we should just serialize it here?
-            fileBits[i] = new byte[size];
-            final int read = IOUtils.readFully(in, fileBits[i]);
+            fileBits[i] = IOUtils.readRange(in, size);
+            final int read = fileBits[i].length;
             if (size != 0 && read < size) {
-                throw new Pack200Exception("Expected to read " + size + " bytes but read " + read);
+                throw new IOException("Expected to read " + size + " bytes but read " + read);
             }
         }
     }


(commons-compress) 05/14: Internal refactoring

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 b7ca1e4dd94c8ebe36585e35710fcab0163eb1e7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 17 10:13:19 2024 -0500

    Internal refactoring
    
    - Move initialization of variables closer to use site
---
 src/main/java/org/apache/commons/compress/harmony/pack200/RunCodec.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/RunCodec.java b/src/main/java/org/apache/commons/compress/harmony/pack200/RunCodec.java
index 78d77fc6d..1d0902b85 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/RunCodec.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/RunCodec.java
@@ -63,11 +63,11 @@ public class RunCodec extends Codec {
 
     @Override
     public int[] decodeInts(final int n, final InputStream in) throws IOException, Pack200Exception {
-        final int[] band = new int[n];
         final int[] aValues = aCodec.decodeInts(k, in);
         normalise(aValues, aCodec);
         final int[] bValues = bCodec.decodeInts(n - k, in);
         normalise(bValues, bCodec);
+        final int[] band = new int[n];
         System.arraycopy(aValues, 0, band, 0, k);
         System.arraycopy(bValues, 0, band, k, n - k);
         lastBandLength = aCodec.lastBandLength + bCodec.lastBandLength;