Skip to content

Recognize legacy TAR headers by checksum - #168

Open
ViktorBystrov72 wants to merge 1 commit into
h2non:masterfrom
ViktorBystrov72:fix/legacy-tar-checksum
Open

ViktorBystrov72 wants to merge 1 commit into
h2non:masterfrom
ViktorBystrov72:fix/legacy-tar-checksum

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

Fixes #109. Related to #113.

Legacy V7 TAR archives do not have a ustar signature, so Match and MatchReader currently return unknown for valid archives. Add a checksum fallback over a complete 512-byte header. It validates the octal checksum syntax before scanning the header and accepts both unsigned-byte and historical signed-byte checksums. The existing USTAR signature check remains the fast path.

Tests generate archives locally and verify their header and payload with Go's archive/tar before checking detection. They cover full archives, header-only buffers, non-ASCII names, signed checksums, malformed checksum fields, corruption, zero/random data, and truncated buffers. Nine V7 cases fail on the unchanged base and pass with this change.

Validation on macOS arm64:

  • Go 1.19.13: go test -count=1 ./... passed.
  • Go 1.26.11: go test -race -count=1 ./... passed.
  • gofmt -s and git diff --check passed.
  • Whole-repository go vet ./... reports the existing copylock at filetype.go:11 (Types = types.Types). This also occurs on unchanged upstream with both toolchains. All other vet analyzers pass with go vet -copylocks=false ./....
  • Detection benchmarks remain allocation-free. The direct legacy-header checksum check measured about 183 ns/op locally. A separate controlled comparison fixed matcher ordering within the existing categories; public USTAR Match stayed around 2.4 µs/op. This controlled comparison is not a production-throughput estimate because the registry's map iteration order varies.

This is header sniffing, not full archive validation. MatchReader retains its existing short-read padding behavior, addressed separately in #167. Truncation tests therefore exercise direct buffers; reader tests use full inputs.

Check a complete legacy header when the USTAR signature is absent.
Validate octal checksum syntax before scanning, and accept historical
signed-byte checksums alongside unsigned checksums.

Fixes h2non#109.

Signed-off-by: Виктор Быстров <anatema@bk.ru>
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.

Tar filetype doesn't match for Pre-POSIX.1-1988 tar headers

1 participant