Repository navigation
fix: fall back to a structural meta-group walk when (0002,0000) is overstated - #549
Merged
awatson1978 merged 1 commit intoSep 30, 2026
Merged
Conversation
…erstated An overstated File Meta Information Group Length used to pull dataset elements into dicomDict.meta with no warning and drop them from dicomDict.dict. readFile now checks that the declared window holds only group-0002 elements; when it does not, it warns and re-walks the meta group structurally, framing the body at the first non-meta element. Understated lengths and the allowMissingHeader / missing group-length leniencies are unchanged. Also adds the missing TagHex.MediaStorageSOPClassUID constant, which the sampleDicomPart10 test helper referenced; without it the helper wrote that element under a garbage (0000,000F) tag inside the meta group of every synthetic sample file. Pins review finding 24 from the PR #512 review map. Co-Authored-By: Claude Fable 5 <[email protected]>
awatson1978
force-pushed
the
core/finding-24-meta-group-length
branch
from
September 30, 2026 12:12
67240d6 to
92925e4
Compare
|
🎉 This PR is included in version 1.0.0-beta.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This closes the quiet half of the wrong-group-length problem: an overstated (0002,0000) no longer pulls dataset elements into the meta header. Review finding 24 from the PR #512 review map.
Quick background. A Part 10 file opens with the File Meta Information — a small group-0002 header whose first element, (0002,0000) File Meta Information Group Length, declares how many bytes of meta follow it.
readFiletrusts that number: it slices a window of exactly that many bytes and parses the meta group out of it. Real clinical files get this number wrong in both directions, and the two directions fail very differently. An understated length just means the declared window ends early — the window still holds only group-0002 elements. An overstated length is worse: the window reaches past the end of the meta group and swallows the first dataset elements whole. Before this fix that file still parsed without a single warning — the swallowed elements sat indicomDict.meta, were missing fromdicomDict.dict, and the body was mis-framed from its first element. The quiet case, not the warned case.The fix is one guard in
readFile. After parsing the declared window, it checks that every element in it actually belongs to group 0002. If anything else got in, it warns and re-walks the meta group structurally from just after the group-length element, stopping at the first non-meta tag — the same structural walk the missing-group-length path already uses — so the body is framed exactly where the meta group really ends:What deliberately did not change: understated lengths are left alone — a short window still holds only group-0002 elements, so it is used as-is, exactly as before. The
allowMissingHeaderopt-in from issue #93 and the structural fallback for files with no (0002,0000) at all are untouched; the new guard only fires when a group-length element is present and overstated. WhetherreadFileshould also grow a strict mode that throws on a wrong group length is the review map's open question 8, and stays open — this PR keeps recovery as the behavior.Writing the regression test surfaced a small fixture bug worth confessing: the
sampleDicomPart10helper referencedTagHex.MediaStorageSOPClassUID, which didn't exist in the constants, so every synthetic sample file carried that element under a mangled (0000,000F) tag inside its meta group. The constant now exists and the helper writes a proper (0002,0002).The new test in
test/data.test.jspins it: it builds a sample file, bumps (0002,0000) by exactly the size of the first dataset element, and asserts the meta header stays pure group-0002, the swallowed element lands back in the dataset, and the recovery warns. It fails on the unguarded code and passes with the fix. Full suite is green: 620 passed, 18 skipped. For what it's worth, master (0.49.x line) has the identical unguarded window read, so this gap exists there too.🤖 Generated with Claude Code