Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function _getReferencedDisplaySetMetadata(referencedDisplaySet, segDisplaySet) {

const PixelMeasures = Array.isArray(PixelMeasuresSequence)
? PixelMeasuresSequence[0]
: PixelMeasuresSequence;
: PixelMeasuresSequence || {};
Comment on lines 295 to +297
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 The || {} fallback is applied to the non-array branch, but the crash described in the PR occurs when PixelMeasuresSequence is an array — specifically an empty one. When PixelMeasuresSequence = [], Array.isArray([]) is true, so the true branch is taken: PixelMeasuresSequence[0] evaluates to undefined, and then const { SpacingBetweenSlices, SliceThickness } = undefined still throws a TypeError. The fix must guard the true (array) branch as well.

Suggested change
const PixelMeasures = Array.isArray(PixelMeasuresSequence)
? PixelMeasuresSequence[0]
: PixelMeasuresSequence;
: PixelMeasuresSequence || {};
const PixelMeasures = Array.isArray(PixelMeasuresSequence)
? PixelMeasuresSequence[0] || {}
: PixelMeasuresSequence || {};
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/cornerstone-dicom-seg/src/viewports/OHIFCornerstoneSEGViewport.tsx
Line: 295-297

Comment:
The `|| {}` fallback is applied to the **non-array** branch, but the crash described in the PR occurs when `PixelMeasuresSequence` **is** an array — specifically an empty one. When `PixelMeasuresSequence = []`, `Array.isArray([])` is `true`, so the true branch is taken: `PixelMeasuresSequence[0]` evaluates to `undefined`, and then `const { SpacingBetweenSlices, SliceThickness } = undefined` still throws a `TypeError`. The fix must guard the true (array) branch as well.

```suggestion
  const PixelMeasures = Array.isArray(PixelMeasuresSequence)
    ? PixelMeasuresSequence[0] || {}
    : PixelMeasuresSequence || {};
```

How can I resolve this? If you propose a fix, please make it concise.


const { SpacingBetweenSlices, SliceThickness } = PixelMeasures;

Expand Down