Skip to content

fix: readFile allowMissingHeader opt-in accepts preamble-less and bare datasets - #536

Merged
awatson1978 merged 2 commits into
release/1.0-beta-corefrom
core/readfile-missing-header
Sep 29, 2026
Merged

awatson1978 merged 2 commits into
release/1.0-beta-corefrom
core/readfile-missing-header

Conversation

@awatson1978

@awatson1978 awatson1978 commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

This is the fix for issue #93: an explicit way to read DICOM data that's missing its file header.

Some background for readers who don't live in Part 10. A standard DICOM file starts with a 128-byte preamble followed by the four ASCII bytes "DICM". After that comes the File Meta Information — a small group-0002 header that, among other things, names the transfer syntax of the dataset. But files in the wild sometimes have the preamble stripped off. And data captured straight from the network (DIMSE) never had a file header in the first place — it's just a bare dataset. DicomMessage.readFile has always refused both, and issue #93 asked for a way to force-read them anyway.

This PR adds an explicit opt-in, allowMissingHeader, to DicomMessage.readFile:

const { DicomMessage } = dcmjs.data;

// Default behavior is unchanged: headerless input still throws.
DicomMessage.readFile(strippedBuffer);
// -> Error: Invalid DICOM file, expected header is missing

// With the opt-in, readFile accepts three input shapes:
const dicomDict = DicomMessage.readFile(buffer, { allowMissingHeader: true });
// 1. Full Part 10 (preamble + DICM): reads exactly as before.
// 2. Preamble-less but with File Meta Information: meta parsing starts at byte 0.
// 3. Bare dataset (DIMSE-style, no meta group at all): parsed directly as a dataset.

The mechanics live in src/DicomMessage.js. When the opt-in is set and there's no DICM marker, readFile checks whether the first element belongs to group 0002. If it does, File Meta parsing simply starts at byte 0. If it doesn't, there is no meta group to read — so a small sniffer, _detectBareSyntax, looks at bytes 4-5 of the first element header. If they form a valid explicit VR code (VR = value representation, the two-letter type code an explicit-VR file stores inline), the dataset is treated as Explicit Little Endian; otherwise Implicit Little Endian. The opt-in also extends the existing leniency for meta groups that start directly at (0002,0010) without a (0002,0000) group-length element.

Nothing changes without the opt-in. The default path throws exactly the errors it always has, and the regression suite (test/issues/issue93-missing-preamble.test.js) pins both sides: the old refusals — including that ignoreErrors does not bypass the DICM check — and the new opt-in behavior for all three input shapes. Two tests in the suite are skipped placeholders for the streaming reader's half of the issue-93 contract; they unskip in the streaming reader PR. The streaming reader depends on this option for its raw-dataset fallback, which is why this PR lands first.

🤖 Generated with Claude Code

@awatson1978
awatson1978 merged commit 0de86c4 into release/1.0-beta-core Sep 29, 2026
8 checks passed
@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