Skip to content

Commit 693b743

Browse files
committed
fix(ultrasound): guard inline region decode against malformed values
decodeUltrasoundRegion throws on truncated FD/US bytes. Mirror the file path's try/catch in DicomMetaLoader so a malformed sequence can't abort the metadata stream. Also align the unit-code comment to decimal (matches the spec test) and note that applyUltrasoundSpacing reads only chunks[0].
1 parent b622bc0 commit 693b743

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/core/streaming/dicom/dicomMetaLoader.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ export class DicomMetaLoader implements MetaLoader {
7878
el.element === SEQUENCE_OF_ULTRASOUND_REGIONS[1] &&
7979
!ultrasoundRegions
8080
) {
81-
ultrasoundRegions = decodeUltrasoundRegion(el.data);
81+
// Decoding can throw if a malformed FD/US value has an unexpected
82+
// length; swallow rather than abort the whole metadata load.
83+
try {
84+
ultrasoundRegions = decodeUltrasoundRegion(el.data);
85+
} catch (err) {
86+
console.warn('Failed to decode SequenceOfUltrasoundRegions:', err);
87+
}
8288
}
8389
},
8490
});

src/core/streaming/dicom/ultrasoundRegion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { Tags, tagToGroupElement } from '@/src/core/dicomTags';
77
// DICOM unit codes for PhysicalUnitsXDirection / YDirection.
88
// See DICOM PS3.3 C.8.5.5.1.15. The only spatial spacing code defined for
99
// this field is 3 (cm). Other codes (0=none, 1=percent, 2=dB, 4=seconds,
10-
// 5=hertz, 6=dB/seconds, 7=cm/sec, 8=cm², 9=cm²/sec, A=cm³, B=cm³/sec,
11-
// C=degrees) are time, frequency, velocity, area, volume, or angle, so
10+
// 5=hertz, 6=dB/sec, 7=cm/sec, 8=cm², 9=cm²/sec, 10=cm³, 11=cm³/sec,
11+
// 12=degrees) are time, frequency, velocity, area, volume, or angle, so
1212
// they are not converted to a VTK image spacing.
1313
export const US_UNIT_CENTIMETERS = 3;
1414

src/core/streaming/dicomChunkImage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ export default class DicomChunkImage
286286
private applyUltrasoundSpacing() {
287287
if (this.getModality() !== 'US') return;
288288

289+
// Ultrasound DICOMs are typically a single multi-frame chunk, so the
290+
// region table on chunk[0] applies to the whole image. If a US series
291+
// ever spanned multiple chunks with differing regions, this would
292+
// silently use the first chunk's spacing for all of them.
289293
const regions = this.chunks[0]?.ultrasoundRegions;
290294
if (!regions?.region) return;
291295

0 commit comments

Comments
 (0)