Skip to content

Commit eb51626

Browse files
authored
Merge pull request #101 from yagni/vr-callback-undefined-fix
Fix bug where peeking to determine whether a field is an SQ would be …
2 parents 04fcbbe + 7e504ce commit eb51626

4 files changed

+50
-10
lines changed

src/readDicomElementImplicit.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import { isPrivateTag } from './util/util.js';
99

1010
const isSequence = (element, byteStream, vrCallback) => {
1111
// if a data dictionary callback was provided, use that to verify that the element is a sequence.
12-
if (typeof vrCallback !== 'undefined') {
13-
return (vrCallback(element.tag) === 'SQ');
12+
if (vrCallback !== undefined) {
13+
const callbackValue = vrCallback(element.tag);
14+
if (callbackValue !== undefined) {
15+
return (callbackValue === 'SQ');
16+
}
1417
}
1518

1619
if ((byteStream.position + 4) <= byteStream.byteArray.length) {

test/parseDicomDataSet_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('parseDicomDataSet', () => {
9090
0xfe, 0xff, 0x00, 0xe0, 0x0A, 0x00, 0x00, 0x00,
9191
];
9292
const callback = (tag) => {
93-
return undefined; // nothing should be interpreted as an SQ
93+
return (tag === 'x7fe00010') ? 'OW' : undefined;
9494
};
9595
const byteArray = convertToByteArray(bytes);
9696
const byteStream = new ByteStream(littleEndianByteArrayParser, byteArray);

test/readDicomElementImplicit_test.js

+41-4
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,33 @@ describe('readDicomElementImplicit', () => {
142142
expect(invoker).to.throw();
143143
});
144144

145-
it('bytes resembling an item tag are not treated like an SQ item when using a callback', () => {
145+
it('bytes resembling an item tag look like an implicit SQ item when using a callback that returns undefined', () => {
146146
// Arrange
147147
// (7fe0,0010) 8
148148
const bytes = [0xe0, 0x7f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00,
149149
// Looks like an item tag, but isn't since it's within pixel data
150150
0xfe, 0xff, 0x00, 0xe0, 0x0A, 0x00, 0x00, 0x00,
151151
];
152152
const callback = (tag) => {
153-
return undefined; // nothing should be interpreted as an SQ
153+
return undefined;
154+
};
155+
const byteStream = new ByteStream(littleEndianByteArrayParser, convertToByteArray(bytes));
156+
const invoker = () => readDicomElementImplicit(byteStream, undefined, callback);
157+
158+
// Act/Assert
159+
// invalid value for parameter 'maxPosition'
160+
expect(invoker).to.throw();
161+
});
162+
163+
it('bytes resembling an item tag are not treated like an SQ item when using a callback (callback overrides peeking)', () => {
164+
// Arrange
165+
// (7fe0,0010) 8
166+
const bytes = [0xe0, 0x7f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00,
167+
// Looks like an item tag, but isn't since it's within pixel data
168+
0xfe, 0xff, 0x00, 0xe0, 0x0A, 0x00, 0x00, 0x00,
169+
];
170+
const callback = (tag) => {
171+
return (tag === 'x7fe00010') ? 'OW' : undefined;
154172
};
155173
const byteStream = new ByteStream(littleEndianByteArrayParser, convertToByteArray(bytes));
156174

@@ -179,7 +197,26 @@ describe('readDicomElementImplicit', () => {
179197
expect(invoker).to.throw();
180198
});
181199

182-
it('bytes resembling an end-of-sequence tag are not treated like an SQ item when using a callback', () => {
200+
it('bytes resembling an end-of-sequence tag look like an implicit SQ item when using a callback that returns undefined', () => {
201+
// Arrange
202+
// (7fe0,0010) 11
203+
const bytes = [0xe0, 0x7f, 0x10, 0x00, 0x0B, 0x00, 0x00, 0x00,
204+
// Looks like a sequence delimiter tag, but isn't since it's within pixel data
205+
0xfe, 0xff, 0xdd, 0xe0, 0x0A, 0x00, 0x00, 0x00,
206+
0x12, 0x43, 0x98,
207+
];
208+
const callback = (tag) => {
209+
return undefined;
210+
};
211+
const byteStream = new ByteStream(littleEndianByteArrayParser, convertToByteArray(bytes));
212+
const invoker = () => readDicomElementImplicit(byteStream, undefined, callback);
213+
214+
// Act/Assert
215+
// item tag (FFFE,E000) not found at offset 8
216+
expect(invoker).to.throw();
217+
});
218+
219+
it('bytes resembling an end-of-sequence tag are not treated like an SQ item when using a callback (callback overrides peeking)', () => {
183220
// Arrange
184221
// (7fe0,0010) 11
185222
const bytes = [0xe0, 0x7f, 0x10, 0x00, 0x0B, 0x00, 0x00, 0x00,
@@ -188,7 +225,7 @@ describe('readDicomElementImplicit', () => {
188225
0x12, 0x43, 0x98,
189226
];
190227
const callback = (tag) => {
191-
return undefined; // nothing should be interpreted as an SQ
228+
return (tag === 'x7fe00010') ? 'OW' : undefined;
192229
};
193230
const byteStream = new ByteStream(littleEndianByteArrayParser, convertToByteArray(bytes));
194231

test/readSequenceItemsImplicit_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('readSequenceItemsImplicit', () => {
2828
0xfe, 0xff, 0xdd, 0xe0, 0x00, 0x00, 0x00, 0x00,
2929
];
3030
const callback = (tag) => {
31-
return undefined; // nothing should be interpreted as an SQ
31+
return (tag === 'x7fe00010') ? 'OW' : undefined;
3232
};
3333
const byteStream = new ByteStream(littleEndianByteArrayParser, convertToByteArray(bytes));
3434
const element = { length: 0xFFFFFFFF };
@@ -95,7 +95,7 @@ describe('readSequenceItemsImplicit', () => {
9595
0xfe, 0xff, 0xdd, 0xe0, 0x00, 0x00, 0x00, 0x00,
9696
];
9797
const callback = (tag) => {
98-
return undefined; // nothing should be interpreted as an SQ
98+
return (tag === 'x7fe00010') ? 'OW' : undefined;
9999
};
100100
const byteStream = new ByteStream(littleEndianByteArrayParser, convertToByteArray(bytes));
101101
const element = { length: 0xFFFFFFFF };
@@ -128,7 +128,7 @@ describe('readSequenceItemsImplicit', () => {
128128
0xfe, 0xff, 0x00, 0xe0, 0x0A, 0x00, 0x00, 0x00,
129129
];
130130
const callback = (tag) => {
131-
return undefined; // nothing should be interpreted as an SQ
131+
return (tag === 'x7fe00010') ? 'OW' : undefined;
132132
};
133133
const byteStream = new ByteStream(littleEndianByteArrayParser, convertToByteArray(bytes));
134134
const element = {dataOffset: 0, length: 24};

0 commit comments

Comments
 (0)