Describe the Bug
@cornerstonejs/adapters throws TypeError: pixelDataChunks.subarray is not a function when loading a DICOM Segmentation object with SegmentationType = LABELMAP that is in RLE Lossless transfer syntax. The crash happens in processLabelmapChunk because that function calls .subarray() on pixelDataChunks, but in the RLE code path pixelDataChunks is a JS Array wrapping a single Uint8Array, not a Uint8Array itself.
Environment
- Package: @cornerstonejs/adapters 4.15.29
- File: dist/esm/adapters/Cornerstone3D/Segmentation/labelmapImagesFromBuffer.js
- Function: insertPixelDataPlanar → processLabelmapChunk
- Line: 281
Root Cause
In createLabelmapsFromBufferInternal (lines 80–98), pixelDataChunks is populated based on the SEG's transfer syntax:
if (TransferSyntaxUID === "1.2.840.10008.1.2.5") {
// RLE branch
pixelData = decode(rleEncodedFrames, multiframe.Rows, multiframe.Columns);
// ...
pixelDataChunks = [pixelData]; // <-- always a JS Array
} else {
pixelDataChunks = unpackPixelData(multiframe, { maxBytesPerChunk }); // returns Uint8Array | Uint16Array
}
So:
-
RLE branch: pixelDataChunks is a JS Array containing one Uint8Array. The outer Array has no .subarray method.
-
Uncompressed branch: pixelDataChunks is a typed array (Uint8Array or Uint16Array), which does have .subarray.
-
insertPixelDataPlanar then routes LABELMAP-type SEGs to processLabelmapChunk, where line 281 calls pixelDataChunks.subarray(...). This works for uncompressed SEGs (typed array) but throws for RLE
SEGs (plain Array).
The sibling code paths in the same file already handle this correctly via the imported helper readFromUnpackedChunks, used at line 197 (the non-LABELMAP planar branch) and line 356
(getAlignedPixelData). processLabelmapChunk was apparently added later without being wired into that helper, so it only happens to work for inputs that take the uncompressed branch.
Steps to Reproduce
Load a DICOM SEG with the following characteristics through createLabelmapsFromBuffer:
| Attribute |
Value |
| (0002,0010) TransferSyntaxUID |
1.2.840.10008.1.2.5 (RLE Lossless) |
| (0062,0001) SegmentationType |
LABELMAP |
| (0028,0100) BitsAllocated |
8 |
| (0028,0101) BitsStored |
8 (must not be 1 — bit-packed RLE is unsupported and bails out earlier) |
Frame count and dimensions are not relevant; the bug fires on the first frame.
A minimal repro is to take any uncompressed LABELMAP SEG and transcode it to RLE Lossless with dcmcrle:
dcmcrle input.dcm seg_rle.dcm
The current behavior
TypeError: pixelDataChunks.subarray is not a function
at processLabelmapChunk (labelmapImagesFromBuffer.js:281)
at insertPixelDataPlanar (...)
at createLabelmapsFromBufferInternal (...)
Offending code:
const view = pixelDataChunks.subarray(i * sliceLength, (i + 1) * sliceLength);
The expected behavior
The DICOM SEG should load without an error.
System Information
System:
OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
CPU: (2) x64 Intel Core Processor (Skylake, IBRS)
Memory: 3.23 GB / 11.68 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 22.22.0 - ~/.nvm/versions/node/v22.22.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v22.22.0/bin/yarn
npm: 10.9.4 - ~/.nvm/versions/node/v22.22.0/bin/npm
Browsers:
Chrome: 145.0.7632.159
Firefox: 149.0
Describe the Bug
@cornerstonejs/adaptersthrowsTypeError: pixelDataChunks.subarrayis not a function when loading a DICOM Segmentation object withSegmentationType = LABELMAPthat is in RLE Lossless transfer syntax. The crash happens inprocessLabelmapChunkbecause that function calls.subarray()onpixelDataChunks, but in the RLE code pathpixelDataChunksis a JS Array wrapping a singleUint8Array, not aUint8Arrayitself.Environment
Root Cause
In
createLabelmapsFromBufferInternal(lines 80–98),pixelDataChunksis populated based on the SEG's transfer syntax:So:
RLE branch:
pixelDataChunksis a JS Array containing one Uint8Array. The outer Array has no.subarraymethod.Uncompressed branch:
pixelDataChunksis a typed array (Uint8ArrayorUint16Array), which does have.subarray.insertPixelDataPlanarthen routes LABELMAP-type SEGs toprocessLabelmapChunk, where line 281 callspixelDataChunks.subarray(...). This works for uncompressed SEGs (typed array) but throws for RLESEGs (plain Array).
The sibling code paths in the same file already handle this correctly via the imported helper readFromUnpackedChunks, used at line 197 (the non-LABELMAP planar branch) and line 356
(getAlignedPixelData). processLabelmapChunk was apparently added later without being wired into that helper, so it only happens to work for inputs that take the uncompressed branch.
Steps to Reproduce
Load a DICOM SEG with the following characteristics through
createLabelmapsFromBuffer:Frame count and dimensions are not relevant; the bug fires on the first frame.
A minimal repro is to take any uncompressed LABELMAP SEG and transcode it to RLE Lossless with dcmcrle:
The current behavior
Offending code:
The expected behavior
The DICOM SEG should load without an error.
System Information