You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/12/30 17:18:04 UTC

[GitHub] [commons-compress] garydgregory commented on a change in pull request #113: COMPRESS-540: Implement TarFile to allow random access to tar files

garydgregory commented on a change in pull request #113:
URL: https://github.com/apache/commons-compress/pull/113#discussion_r550266500



##########
File path: src/main/java/org/apache/commons/compress/utils/BoundedArchiveInputStream.java
##########
@@ -0,0 +1,98 @@
+/*

Review comment:
       Is it time to depend on Commons IO instead of creating a mini Commons IO in Compress?

##########
File path: src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
##########
@@ -553,6 +554,23 @@ public TarArchiveEntry(final byte[] headerBuf, final ZipEncoding encoding, final
         parseTarHeader(headerBuf, encoding, false, lenient);
     }
 
+    /**
+     * Construct an entry from an archive's header bytes for random access tar. File is set to null.
+     * @param headerBuf the header bytes from a tar archive entry.
+     * @param encoding encoding to use for file names.
+     * @param lenient when set to true illegal values for group/userid, mode, device numbers and timestamp will be
+     * ignored and the fields set to {@link #UNKNOWN}. When set to false such illegal fields cause an exception instead.
+     * @param dataOffset position of the entry data in the random access file.
+     * @since 1.21
+     * @throws IllegalArgumentException if any of the numeric fields have an invalid format.
+     * @throws IOException on error.
+     */
+    public TarArchiveEntry(final byte[] headerBuf, final ZipEncoding encoding, final boolean lenient,
+            final long dataOffset) throws IOException {
+        this(headerBuf, encoding, lenient);
+        this.dataOffset = dataOffset;
+    }

Review comment:
       Should we throw an IAE if the offset is negative or larger than the parent can hold?

##########
File path: src/test/java/org/apache/commons/compress/archivers/TarTestCase.java
##########
@@ -335,6 +482,18 @@ public void testCOMPRESS178() throws Exception {
         in.close();
     }
 
+    @Test
+    public void testTarFileCOMPRESS178() throws Exception {
+        final File input = getFile("COMPRESS-178.tar");
+        try (final TarFile tarFile = new TarFile(input)) {
+            // Compared to the TarArchiveInputStream all entries are read when instantiating the tar file
+            fail("Expected IOException");
+        } catch (final IOException e) {

Review comment:
       Use assertThrows().




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org