Skip to content

[COMPRESS-645] Reject an incomplete TAR record before the end of the archive - #836

Open
Clickin wants to merge 2 commits into
apache:masterfrom
Clickin:COMPRESS-645-truncated-record
Open

Clickin wants to merge 2 commits into
apache:masterfrom
Clickin:COMPRESS-645-truncated-record

Conversation

@Clickin

@Clickin Clickin commented Nov 8, 2026

Copy link
Copy Markdown

JIRA: https://issues.apache.org/jira/browse/COMPRESS-645

TarArchiveInputStream.getNextEntry() returns null for non-TAR input shorter than one record, so it looks like an empty archive. A gzipped TAR holding one small file is only 113 bytes. A partial record after a valid entry is dropped the same way. Non-TAR input of 512 bytes or more already fails while parsing the header, and TarFile already throws EOFException for short input.

readRecord() now throws EOFException when a read returns some bytes but fewer than a record, unless the EOF marker has already been read. The message follows the other "Truncated TAR archive" messages in the class.

Zero-byte input is still an empty archive, an archive without an EOF marker still reads, and padding or garbage after the EOF record is still ignored. There is no format detection and no change to checksum handling.

TarArchiveInputStreamTest covers the rejected and the unchanged cases. Without the change, three cases fail: 1-byte input, 511-byte input, and a partial record after an entry. The default mvn build passes on JDK 17, and TarArchiveInputStreamTest passes on JDK 8.

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute?
    OpenAI GPT-6 Astra wrote the change and the tests; Claude Opus 5.5 reviewed them and wrote this description. The commit carries Generated-by and Assisted-By trailers.
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.

🤖 Generated with Claude Code

…archive

TarArchiveInputStream.readRecord() returned null both at a clean end of
input and when fewer than 512 bytes were available, so input shorter
than one record, such as a small .tar.gz passed to the TAR reader, was
reported as an empty archive. Throw EOFException for a partial record
unless the EOF marker has already been read.

Generated-by: OpenAI GPT-6 Astra
Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring the branch up to date with master before review.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@Clickin
Clickin marked this pull request as ready for review November 8, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant