Copilot commented on code in PR #722:
URL: https://github.com/apache/commons-compress/pull/722#discussion_r2502511292


##########
src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java:
##########
@@ -42,14 +42,15 @@
 import java.util.zip.ZipEntry;
 
 import org.apache.commons.compress.AbstractTest;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.RandomAccessFileMode;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
-import shaded.org.apache.commons.io.IOUtils;
-
 /**
  * Tests {@link ZipFile} Zip64 support.
  */
+@Disabled

Review Comment:
   The entire test class has been disabled with `@Disabled` annotation. This is 
a significant change that should be documented. Consider adding a reason 
parameter to explain why these tests are disabled, e.g., `@Disabled("Reason for 
disabling")`, to help future maintainers understand the context.



##########
src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStreamTest.java:
##########
@@ -45,13 +45,12 @@
 import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.compress.compressors.gzip.ExtraField.SubField;
 import org.apache.commons.compress.compressors.gzip.GzipParameters.OS;
+import org.apache.commons.io.IOUtils;

Review Comment:
   The import statement has been changed from 
`shaded.org.apache.commons.io.IOUtils` to `org.apache.commons.io.IOUtils`. 
Verify that this unshaded version is available and properly configured in the 
project dependencies. This change suggests the project is moving away from 
shaded dependencies for commons-io.



##########
src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java:
##########
@@ -332,8 +356,7 @@ public int available() throws IOException {
      * </p>
      */
     private void buildSparseInputStreams() throws IOException {
-        currentSparseInputStreamIndex = -1;
-        sparseInputStreams = new ArrayList<>();
+        final List<InputStream> sparseInputStreams = new ArrayList<>();

Review Comment:
   The contents of this container are never accessed.



##########
src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java:
##########
@@ -42,14 +42,15 @@
 import java.util.zip.ZipEntry;
 
 import org.apache.commons.compress.AbstractTest;
+import org.apache.commons.io.IOUtils;

Review Comment:
   The import statement has been changed from 
`shaded.org.apache.commons.io.IOUtils` to `org.apache.commons.io.IOUtils`. This 
is the same change as in GzipCompressorOutputStreamTest.java. Ensure 
consistency across the codebase and verify that the unshaded commons-io 
dependency is properly configured.



##########
src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java:
##########
@@ -760,23 +707,26 @@ protected static Map<String, String> 
parsePaxHeaders(final InputStream inputStre
                     while ((ch = inputStream.read()) != -1) {
                         read++;
                         totalRead++;
-                        if (totalRead < 0 || headerSize >= 0 && totalRead >= 
headerSize) {
+                        if (totalRead < 0 || totalRead >= headerSize) {

Review Comment:
   Test is always false.



##########
src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java:
##########
@@ -486,6 +615,30 @@ public static int toNonNegativeInt(final String 
description, final long value) t
 
     private final boolean tryToRecoverBrokenArchives;
 
+    private final int maxEntryNameLength;
+
+    private SevenZFile(final Builder builder) throws IOException {
+        this.channel = builder.getChannel(SeekableByteChannel.class);
+        try {
+            this.fileName = builder.getName();
+            this.maxEntryNameLength = builder.getMaxEntryNameLength();
+            this.maxMemoryLimitKiB = builder.maxMemoryLimitKiB;
+            this.useDefaultNameForUnnamedEntries = 
builder.useDefaultNameForUnnamedEntries;
+            this.tryToRecoverBrokenArchives = 
builder.tryToRecoverBrokenArchives;
+            final byte[] password = builder.password;
+            archive = readHeaders(password);
+            this.password = password != null ? Arrays.copyOf(password, 
password.length) : null;

Review Comment:
   Potentially confusing name: [SevenZFile](1) also refers to field 
[password](2) (as this.password).
   ```suggestion
               final byte[] builderPassword = builder.password;
               archive = readHeaders(builderPassword);
               this.password = builderPassword != null ? 
Arrays.copyOf(builderPassword, builderPassword.length) : null;
   ```



##########
src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java:
##########
@@ -2231,6 +2330,32 @@ private boolean skipEntriesWhenNeeded(final int 
entryIndex, final boolean isInSa
         return true;
     }
 
+    /**
+     * {@inheritDoc}
+     *
+     * @since 1.29.0
+     */
+    @Override
+    public IOStream<? extends SevenZArchiveEntry> stream() {
+        return IOStream.of(archive.files);
+    }
+
+    /**
+     * Converts the given ByteBuffer to a byte array of the given size.
+     *
+     * @param header The buffer containing the 7z header data.
+     * @param size  The size of the byte array to create.
+     * @return A byte array containing the data from the buffer.
+     * @throws IOException if there are insufficient resources to allocate the 
array or insufficient data in the buffer.
+     */
+    private byte[] toByteArray(final ByteBuffer header, final int size) throws 
IOException {
+        // Check if we have enough resources to allocate the array
+        MemoryLimitException.checkKiB(bytesToKiB(size * Byte.BYTES), 
maxMemoryLimitKiB);

Review Comment:
   Potential overflow in [int multiplication](1) before it is converted to long 
by use in an invocation context.
   ```suggestion
           MemoryLimitException.checkKiB(bytesToKiB(((long) size) * 
Byte.BYTES), maxMemoryLimitKiB);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to