Skip to content

Reject undefined pixel fragment lengths before reading - #471

Merged
CPBridge merged 2 commits into
ImagingDataCommons:masterfrom
jdotc1:bugfix/undefined-fragment-length
Oct 21, 2026
Merged

CPBridge merged 2 commits into
ImagingDataCommons:masterfrom
jdotc1:bugfix/undefined-fragment-length

Conversation

@jdotc1

@jdotc1 jdotc1 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #470.

Reject an encapsulated fragment length of 0xFFFFFFFF before passing it to the stream's read() method. This prevents an invalid fragment from requesting a nearly-4-GiB payload read when an offset table is supplied and the separate fragment scanner is bypassed.

Add one mocked-stream regression that expects OSError and verifies no payload read occurs. The test failed before the two-line fix and passed afterward. Validation used the actual reader method and new test loaded in isolation, with real pydicom tag handling and a mocked stream, without importing the full highdicom package. No large allocation, clinical files, codec, network, or full suite was used.

This is malformed-input/resource hardening, not a demonstrated exploit or memory-exhaustion claim.

@CPBridge CPBridge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted on #470 I am not convinced this is really an important problem, but on reflection I also don't see any harm in accepting this change, since a fragment should not have an odd number of bytes anyway, so 0xFFFFFFFF should never be encountered as a "true" fragment length.

However, I would rather not introduce a new test file just for this. Could you please add the test to the existing tests/test_io.py instead?

@jdotc1

jdotc1 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Moved the regression test into tests/test_io.py and removed the separate test file in fb78b20. The test assertions and production change are unchanged.

@CPBridge

Copy link
Copy Markdown
Collaborator

Ok thank you @jdotc1 !

@CPBridge
CPBridge merged commit 2761f81 into ImagingDataCommons:master Oct 21, 2026
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.

Reject undefined fragment lengths before reading raw frame payloads

2 participants