Skip to content

fix: make registerTag symmetric without mutating the shared nameMap - #548

Merged
awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/finding-32-namemap-isolation
Sep 30, 2026
Merged

awatson1978 merged 1 commit into
release/1.0-beta-corefrom
core/finding-32-namemap-isolation

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

registerTag() is now symmetric — a registered custom keyword denaturalizes back to its tag — and the symmetry comes from the registry itself, never from mutating the shared nameMap.

The situation before this PR: registerTag("00091001", { name: "AcmePrivateValue", vr: "LO" }) taught the dictionary a custom keyword, so naturalizeDataset happily emitted dataset.AcmePrivateValue. But DicomMetaDictionary.nameMap — the reverse index that denaturalizeDataset uses — is built once from the standard dictionary and never learns registered names. So the renamed element was dropped on the way back with an "Unknown name in dataset" warning: registration worked in one direction only.

The PR #512 development branch closed this gap the wrong way, and that's review finding 32: its naturalizer wrote registered entries into the static DicomMetaDictionary.nameMap as a side effect of reading a dataset. Whether denaturalizeDataset succeeded for a given input then depended on whether some earlier, unrelated call had happened to naturalize a dataset containing that tag — tests that pass in a full suite run and fail alone, custom entries leaking into every later naturalization in the process, and no way to undo it. The review's guidance was to put the global change where a caller expects one: in registerTag() itself.

That's what this does. registerTag() now also indexes the entry by its keyword in a registry-local name index (one Map.set per registration — the lazy nameMap build is untouched, nothing is rebuilt per call), and static denaturalizeDataset consults that index only on a nameMap miss. Reading a dataset mutates nothing; an explicitly passed custom nameMap (the instance path) stays authoritative.

registerTag("00091001", { name: "AcmePrivateValue", vr: "LO", vm: "1" });

const dataset = DicomMetaDictionary.naturalizeDataset(dicomDict.dict);
dataset.AcmePrivateValue; // "private-top" — this always worked

const denaturalized = DicomMetaDictionary.denaturalizeDataset(dataset);
// before: element dropped ("Unknown name in dataset AcmePrivateValue")
// after:  { "00091001": { vr: "LO", Value: ["private-top"] } }

DicomMetaDictionary.nameMap.AcmePrivateValue; // undefined — the shared map is never touched

Two tests pin it in test/issues/issue388-private-tags.test.js: the #215 asymmetric-registration known-gap skip, now green and unskipped, and a new guard asserting that a naturalize → denaturalize pass over a dataset with a registered tag leaves DicomMetaDictionary.nameMap byte-for-byte alone — the exact leak from review finding 32 of the PR #512 review map. For the record, the mutation defect itself never existed on master (0.52): master has registerTag() with the same one-way asymmetry, but its naturalizer never wrote into nameMap — the leak was new code in the #512 development branch.

🤖 Generated with Claude Code

registerTag() now also indexes its entry by keyword in a registry-local
name index, and static denaturalizeDataset consults that index on a
nameMap miss. Registered custom names round-trip through
naturalize -> denaturalize, and reading a dataset never writes into the
shared DicomMetaDictionary.nameMap, so no custom entry can leak from one
dataset into later naturalizations.

Review finding 32 from the PR #512 review map; unskips the #215
asymmetric-registration known-gap test and adds a nameMap-isolation
guard in test/issues/issue388-private-tags.test.js.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit b636e58 into release/1.0-beta-core Sep 30, 2026
7 of 8 checks passed
@awatson1978
awatson1978 deleted the core/finding-32-namemap-isolation branch September 30, 2026 11:40
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant