Skip to content

fix(reading): probe absolute offsets when searching for the superblock - #185

Open
Blackclaws wants to merge 1 commit into
Apollo3zehn:devfrom
Blackclaws:fix/superblock-search-offsets
Open

fix(reading): probe absolute offsets when searching for the superblock#185
Blackclaws wants to merge 1 commit into
Apollo3zehn:devfrom
Blackclaws:fix/superblock-search-offsets

Conversation

@Blackclaws

Copy link
Copy Markdown
Contributor

Fixes #183.

A file written with UserBlockSize above 512 could not be reopened: NativeFile.InternalOpenAsync advanced by a doubling delta relative to the current position, so after the 512 candidate it probed 1536, 3584, 7680, … instead of 1024, 2048, 4096, …. h5dump read the same files fine, so only the reader was affected.

The search now seeks to each candidate offset absolutely. The bounds check moved with it: it rejects an offset that cannot hold the 8-byte signature, rather than testing the position after a seek that may already be past the end.

Test plan

CanRoundTrip_WithUserBlock in Writing/MiscTests.cs writes and reads back a 4,096-element int dataset for user block sizes 0, 512, 1024, 2048 and 4096. Before the fix the last three throw "The file is not a valid HDF 5 file."; all five pass after it. Full suite green on net8.0 (no .NET 6 runtime available here, so net6.0 was not exercised).

Breaking changes

None.

🤖 Generated with Claude Code

The candidate offsets are 0, 512, 1024, 2048, ..., but the search
advanced by a doubling delta from the current position, so it probed
1536, 3584, 7680, ... and only found the superblock for user block
sizes of 0 or 512. The bounds check now rejects an offset that cannot
hold the 8-byte signature instead of testing the position after a seek
that may already be past the end.

Closes Apollo3zehn#183
Co-Authored-By: Claude <noreply@anthropic.com>
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.

Reader cannot reopen files with UserBlockSize greater than 512

1 participant