ppkarwasz commented on code in PR #715:
URL: https://github.com/apache/commons-compress/pull/715#discussion_r2425567995
##########
src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java:
##########
@@ -49,91 +53,45 @@
*/
public class TarFile implements ArchiveFile<TarArchiveEntry> {
+ /**
+ * InputStream that reads a specific entry from the archive.
+ *
+ * <p>It ensures that:</p>
+ * <ul>
+ * <li>No more than the specified number of bytes are read from the
underlying channel.</li>
+ * <li>If the end of the entry is reached before the expected number of
bytes, an {@link EOFException} is thrown.</li>
+ * </ul>
+ */
private final class BoundedTarEntryInputStream extends
BoundedArchiveInputStream {
private final SeekableByteChannel channel;
- private final TarArchiveEntry entry;
+ private final long end;
- private long entryOffset;
-
- private int currentSparseInputStreamIndex;
-
- BoundedTarEntryInputStream(final TarArchiveEntry entry, final
SeekableByteChannel channel) throws IOException {
- super(entry.getDataOffset(), entry.getRealSize());
- if (channel.size() - entry.getSize() < entry.getDataOffset()) {
- throw new ArchiveException("Entry size exceeds archive size");
- }
Review Comment:
Removing this check lets users read as much of the TAR entry as is actually
available, even if the archive is truncated.
The `read()` method below already detects a short stream and throws an
`EOFException` if the data ends before the declared entry size.
--
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]