Skip to content

fix: clamp a declared value length to the bytes present (GHSA-xwvm-687g-rm36) - #652

Merged
wayfarer3130 merged 3 commits into
1.0-betafrom
fix/1.0-beta-declared-length-bounds
Nov 24, 2026
Merged

wayfarer3130 merged 3 commits into
1.0-betafrom
fix/1.0-beta-declared-length-bounds

Conversation

@wayfarer3130

Copy link
Copy Markdown
Contributor

Summary

This PR is the 1.0 port of the 0.x fix for the security advisory GHSA-xwvm-687g-rm36 (commit 6da1c81, merged by 559a20a). A declared value length can be longer than the bytes in the file. With this fix, the reader reads only the bytes that are present, and it logs a validation warning.

Changes

  • packages/core/src/SplitDataView.js: slice clamps the end to the bytes that the view holds, the same as ArrayBuffer.prototype.slice. A start at or after the end gives an empty buffer.
  • packages/core/src/ValueRepresentation.js: readBytes reads the bytes that are present when the declared length is longer. It logs a validationLog warning.
  • The code is the same as in 0.x, at the same places in the 1.x files.
  • beta-1-release-notes.md: one bullet for the change.
  • Behavior change, the same as in 0.x: a file that ends inside a multi-byte header field now throws RangeError. Before, the reader read bytes that were not in the file.
  • The 1.x AsyncDicomReader needs no change. For the same input, it throws Stream has insufficient data. The parser fromPart10Stream also throws on this input, and its tests require that behavior.

Review

An independent review found no blocker. The review covered every 1.x read path. No path allocates a buffer from a declared length that is longer than the data. The review found one gap: no test checked the warning. A new commit adds that check.

Tests

The 0.x test test/declared-length-bounds.test.js moves to test/issues/ghsa-xwvm-687g-rm36-declared-length-bounds.test.js. Only the imports and a header comment change.

  • Before the fix, 12 of the 14 tests fail.
  • After the fix, all 14 tests pass. The full suite passes: 119 suites, 1290 tests.

The API must do this:

  • SplitDataView.slice and ReadBufferStream return only the bytes that are present.
  • readBytes logs the validation warning when the declared length is longer than the data. If the clamp in readBytes is removed, this test fails.

The user experience must have this:

  • A file with a declared length that is longer than the data reads without an allocation of the declared size.

🤖 Generated with Claude Code

wayfarer3130 and others added 3 commits November 24, 2026 13:41
1.0 port of commit 6da1c81 (merged by 559a20a), for GHSA-xwvm-687g-rm36.

SplitDataView.slice in packages/core clamps the end to the bytes held,
the way ArrayBuffer.prototype.slice does, and returns an empty buffer
when the start is at or after the end. BinaryRepresentation.readBytes
reads only the bytes present when the declared value length is longer,
and logs a validationLog warning.

The 0.x test test/declared-length-bounds.test.js moves to
test/issues/GHSA-xwvm-687g-rm36-declared-length-bounds.test.js.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review item S1 of the 1.0 port of GHSA-xwvm-687g-rm36. The SplitDataView.slice clamp alone makes the readBytes tests pass, so the readBytes tests now also expect the validationLog.warn call. Without the readBytes clamp, 5 tests fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Maintainer decision on the review of the 1.0 port of GHSA-xwvm-687g-rm36 (commit 6da1c81): one bullet for the warning and for the RangeError of a truncated header field (review N3).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wayfarer3130
wayfarer3130 marked this pull request as ready for review November 24, 2026 19:48
@wayfarer3130
wayfarer3130 merged commit c0bee7d into 1.0-beta Nov 24, 2026
2 of 4 checks passed
@wayfarer3130
wayfarer3130 deleted the fix/1.0-beta-declared-length-bounds branch November 24, 2026 19:54
@github-actions

Copy link
Copy Markdown

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

The release is available on:

Your semantic-release bot 📦🚀

wayfarer3130 added a commit that referenced this pull request Nov 25, 2026
…e exponent (#654)

* fix(VR): format DS numbers to 16 characters instead of cutting off the exponent

1.0 port of #610 (commit aee06e4), with the round trip test of #624.

denaturalizeDataset in packages/core now formats each number of a DS
array with DecimalString.convertToString before denaturalizeValue, so
3.5163338899999997e-10 is written as 3.5163338900e-10 and not cut to
3.51633388999999.

Both tests go in test/issues/issue531-ds-exponent.test.js (#610 fixes
#531).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(VR): format a single DS number and a Number object to 16 characters

Review items S1 and N1 of the 1.0 port of #610. The 1.x port now also
formats the scalar case: a VM 1 DS attribute, for example
SliceThickness or SliceLocation, is a single number in a 1.x
naturalized dataset, and it went through String() and was cut to 16
characters. A Number object (new Number(...)) is formatted the same way.
One formatDs function serves the scalar and the list form.

master (0.x) has the same scalar gap after #610.

The JSDoc of denaturalizeDataset cites PS3.5 Table 6.2-1. The
bundle-size ceilings move to 1.081 and 1.063 for this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: record the DS formatting in NAT-U-RT-8 and the release notes

Maintainer decision Q2 of the review of the 1.0 port of #610: NAT-U-RT-8 in docs/specs/naturalized-dataset.md, with the PS3.5 Section 6.2, Table 6.2-1 reference and the test file, and one bullet in beta-1-release-notes.md. No NAT-I rule covers the DS write, so no NAT-I rule changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(bundle-size): raise the dcmjs.es.js ceiling to 1.064 after #652

The rebase onto 1.0-beta adds the declared length clamp of #652 to the DS formatting of this branch: dcmjs.es.js is x1.0632.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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