Skip to content

fix(file): report the bytes actually read on invalid magic - #9300

Open
crossthebridgetpa wants to merge 1 commit into
lance-format:mainfrom
crossthebridgetpa:fix/decode-footer-magic-error
Open

crossthebridgetpa wants to merge 1 commit into
lance-format:mainfrom
crossthebridgetpa:fix/decode-footer-magic-error

Conversation

@crossthebridgetpa

Copy link
Copy Markdown

Bug

decode_footer in rust/lance-file/src/reader.rs checks the trailing 4 bytes of a file against MAGIC and, on mismatch, formats the error with MAGIC (the expected value) instead of the bytes actually read. Every invalid-magic error therefore prints invalid magic: [76, 65, 78, 67] (b"LANC", the correct value), which looks like the check passed and sends readers diagnosing a genuinely corrupt file down the wrong path.

Field report: bennyhodl/centinel#69, where a user hit this while diagnosing a corrupt fragment file.

Change

  • Interpolate the bytes actually read (magic_bytes.as_ref()) instead of MAGIC, and also show the expected value for context: invalid magic: {actual}, expected {expected}.
  • Add a unit test that constructs a minimal footer with a bad magic and asserts the error message contains the actual (wrong) bytes.

Not included

The file path / object-store location is not threaded through this error, since decode_footer only receives the raw footer bytes and its callers (read_raw_metadata_for_dispatch, etc.) would need a signature change to pass it in. Left out to keep this PR minimal; flagging as a possible follow-up if it's wanted.

cargo check -p lance-file and the new test pass locally. rustfmt/cargo fmt were not available in this environment (no sudo to install); the diff was hand-matched to the surrounding style.

🤖 Generated with Claude Code

decode_footer compares the trailing 4 bytes of a Lance file against MAGIC, but on mismatch it formats the error with MAGIC (the expected value) instead of the bytes actually read. Every such error therefore printed "invalid magic: [76, 65, 78, 67]", which looks like the check passed and sends readers diagnosing a corrupt file down the wrong path.

Field report: bennyhodl/centinel#69

Interpolate the actual magic bytes read from the file, and also show the expected value for context. Adds a unit test that decode_footer surfaces the wrong bytes on a mismatched footer.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added A-encoding Encoding, IO, file reader/writer bug Something isn't working labels Sep 16, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gate recommendation: approve.

The patch corrects the misleading invalid-magic diagnostic at the narrow footer-validation boundary by reporting the actual bytes alongside the expected magic, with a focused regression test. Successful reads and the on-disk format are unchanged.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-encoding Encoding, IO, file reader/writer bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant