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


##########
src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java:
##########
@@ -797,21 +718,11 @@ public long skip(final long n) throws IOException {
         if (n <= 0 || isDirectory()) {
             return 0;
         }
-        final long availableOfInputStream = in.available();
-        final long available = currEntry.getRealSize() - entryOffset;
-        final long numToSkip = Math.min(n, available);
-        long skipped;
-        if (!currEntry.isSparse()) {
-            skipped = IOUtils.skip(in, numToSkip);
-            // for non-sparse entry, we should get the bytes actually skipped 
bytes along with
-            // inputStream.available() if inputStream is instance of 
FileInputStream
-            skipped = getActuallySkipped(availableOfInputStream, skipped, 
numToSkip);
-        } else {
-            skipped = skipSparse(numToSkip);
+        if (currEntry == null || currentInputStream == null) {
+            throw new IllegalStateException("No current tar entry");

Review Comment:
   This situation occurs when `skip()` is called **before** `getNextEntry()`, 
so it represents a programming error rather than a malformed archive, which 
justifies using `IllegalStateException`.
   
   However, `java.util.ZipInputStream` silently returns `0` in the same 
scenario. We could consider aligning with that behavior across all archive 
formats, but that would be best handled in a separate PR.
   
   



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