Skip to content

Fix parsing of truncated byte arrays - #203

Open
jmhmd wants to merge 2 commits into
cornerstonejs:masterfrom
jmhmd:fix/parse-truncated
Open

Fix parsing of truncated byte arrays#203
jmhmd wants to merge 2 commits into
cornerstonejs:masterfrom
jmhmd:fix/parse-truncated

Conversation

@jmhmd

@jmhmd jmhmd commented Jun 8, 2022

Copy link
Copy Markdown

This change will catch dataset parsing exceptions and merge in the parsed metadata header dataset with the partially parsed dataset and re-throw the exception. This allows a truncated byte array to still be parsed (up to the point of the parsing exception).

MichaelLeeHobbs added a commit to MichaelLeeHobbs/dicomParser that referenced this pull request Jul 23, 2026
…pixel data

Phase 1 PR 3/5. Adds the discriminated-union element model
(value | sequence | encapsulated | unknown, upstream cornerstonejs#257/cornerstonejs#278), a frame-stack
tokenizer with no recursion and bounded loops (mission-critical standard;
maxDepth guard), structural delimiter consumption (cornerstonejs#244/cornerstonejs#143) with
delimitation items always treated as zero-length (cornerstonejs#266), CP-246 UN
undefined-length sequences, cornerstonejs#114 private implicit policy (never peek
private defined-length elements), stopAt with >= semantics (cornerstonejs#104/cornerstonejs#268/#52),
typed errors with partial-result salvage (#46/cornerstonejs#203/cornerstonejs#277), and the
encapsulated pixel-data scanner (BOT + fragments).

Ports readSequenceItemsExplicit/Implicit tests and the sequence/UN halves
of readDicomElementExplicit/Implicit tests; adds delimiter-pathology,
stopAt, truncation-salvage and depth-bound coverage.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DSSLWZvjSRByQP3KsghQcJ
MichaelLeeHobbs added a commit to MichaelLeeHobbs/dicomParser that referenced this pull request Jul 23, 2026
…pixel data (#5)

Phase 1 PR 3/5. Adds the discriminated-union element model
(value | sequence | encapsulated | unknown, upstream cornerstonejs#257/cornerstonejs#278), a frame-stack
tokenizer with no recursion and bounded loops (mission-critical standard;
maxDepth guard), structural delimiter consumption (cornerstonejs#244/cornerstonejs#143) with
delimitation items always treated as zero-length (cornerstonejs#266), CP-246 UN
undefined-length sequences, cornerstonejs#114 private implicit policy (never peek
private defined-length elements), stopAt with >= semantics (cornerstonejs#104/cornerstonejs#268/#52),
typed errors with partial-result salvage (#46/cornerstonejs#203/cornerstonejs#277), and the
encapsulated pixel-data scanner (BOT + fragments).

Ports readSequenceItemsExplicit/Implicit tests and the sequence/UN halves
of readDicomElementExplicit/Implicit tests; adds delimiter-pathology,
stopAt, truncation-salvage and depth-bound coverage.


Claude-Session: https://claude.ai/code/session_01DSSLWZvjSRByQP3KsghQcJ

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
MichaelLeeHobbs added a commit to MichaelLeeHobbs/dicomParser that referenced this pull request Jul 23, 2026
Phase 1 PR 4/5. Adds readPart10Header (preamble/DICM detection, explicit-LE
meta group via the tokenizer's stopAt, headerless datasets via the
transferSyntax option — #48, missing-preamble tolerance), the three-path
inflate strategy (injected inflater / node:zlib via process.getBuiltinModule
/ DecompressionStream('deflate-raw') in parseAsync) killing the pako
global-sniffing crash class (cornerstonejs#270/cornerstonejs#125/cornerstonejs#109), and parse()/parseAsync()
returning a ParseResult with meta + dataset + typed error + partial results
(cornerstonejs#203). GE private DLX transfer syntax is recognized and reported as
unsupported (cornerstonejs#107). Meta-group truncation is a hard error (a clamped
Transfer Syntax UID could silently parse wrong).

Ports parseDicom_test (BE/LE explicit, implicit, raw) and the p10 synthetic
builder from dcmtk.js; adds a real-fixture gate over testImages/ (CT1_UNC
variants vs DCMTK ground truth, deflated files on both inflate paths,
encapsulated single/multi-frame, whole-corpus smoke).


Claude-Session: https://claude.ai/code/session_01DSSLWZvjSRByQP3KsghQcJ

Co-authored-by: Claude Fable 5 <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.

1 participant