ppkarwasz commented on code in PR #715:
URL: https://github.com/apache/commons-compress/pull/715#discussion_r2435750427


##########
src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java:
##########
@@ -820,37 +731,15 @@ public long skip(final long n) throws IOException {
      * @throws IOException if a truncated tar archive is detected.
      */
     private void skipRecordPadding() throws IOException {
-        if (!isDirectory() && this.entrySize > 0 && this.entrySize % 
getRecordSize() != 0) {
-            final long available = in.available();
-            final long numRecords = this.entrySize / getRecordSize() + 1;
-            final long padding = numRecords * getRecordSize() - this.entrySize;
-            long skipped = IOUtils.skip(in, padding);
-            skipped = getActuallySkipped(available, skipped, padding);
+        final long entrySize = currEntry != null ? currEntry.getSize() : 0;
+        if (!isDirectory() && entrySize > 0 && entrySize % getRecordSize() != 
0) {
+            final long padding = getRecordSize() - (entrySize % 
getRecordSize());
+            final long skipped = org.apache.commons.io.IOUtils.skip(in, 
padding);
             count(skipped);
-        }
-    }
-
-    /**
-     * Skip n bytes from current input stream, if the current input stream 
doesn't have enough data to skip, jump to the next input stream and skip the 
rest
-     * bytes, keep doing this until total n bytes are skipped or the input 
streams are all skipped
-     *
-     * @param n bytes of data to skip.
-     * @return actual bytes of data skipped.
-     * @throws IOException if an I/O error occurs.
-     */
-    private long skipSparse(final long n) throws IOException {
-        if (sparseInputStreams == null || sparseInputStreams.isEmpty()) {
-            return in.skip(n);
-        }
-        long bytesSkipped = 0;
-        while (bytesSkipped < n && currentSparseInputStreamIndex < 
sparseInputStreams.size()) {
-            final InputStream currentInputStream = 
sparseInputStreams.get(currentSparseInputStreamIndex);
-            bytesSkipped += currentInputStream.skip(n - bytesSkipped);
-            if (bytesSkipped < n) {
-                currentSparseInputStreamIndex++;
+            if (skipped != padding) {
+                throw new EOFException(String.format("Truncated TAR archive: 
failed to skip record padding for entry '%s'", currEntry.getName()));

Review Comment:
   `IOUtils.skip` reads until EOF, so this exception truly means the stream is 
exhausted.
   
   The only question is whether we should be tolerant (according to Postel's 
law) and allow EOF within the padding area. In fact, we already do so:
   
   * When the archive omits the two zero blocks (non-compliant but tolerated). 
In fact we don't even throw an exception if EOF occurs while reading a record, 
which is probably a bug.
   * When the archive isn’t padded to a full block multiple (non-required but 
common).
   



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