Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent arraybuffers from being excluded of naturalized datasets #229

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion src/DicomMetaDictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ class DicomMetaDictionary {

if (naturalDataset[naturalName].length === 1) {
const sqZero = naturalDataset[naturalName][0];
//add accessor to object props, leave arrays and arraybuffers unchanged
if (
sqZero &&
typeof sqZero === "object" &&
!sqZero.length
!sqZero.length &&
!(sqZero instanceof ArrayBuffer)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@wayfarer3130 can you look and test?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm looking at it, but I don't know under what conditions it would be an instance of an array buffer.
Would like to see an example integrated into a unit test.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense for Seg, or anything else that decodes direct to raw buffers, still would like to see a unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addAccessors function is fine, the problem comes from the conditions to which it's being called. Before, it would make naturalDataset[naturalName] = naturalDataset[naturalName][0] and now it leaves it as is which will breaks downstream code and make it undefined.

Have no ideia why it made sense before to remove the element out of the array but code was made with that assumption and the proposed safeguard just tries to make it backward compatible.

anyway, I'll put a test later if it helps

) {
addAccessors(naturalDataset[naturalName], sqZero);
} else {
Expand Down
3 changes: 2 additions & 1 deletion test/test_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const tests = {
.PixelMeasuresSequence.SpacingBetweenSlices;
expect(spacing).to.equal(0.12);
expect(Array.isArray(naturalSequence.SharedFunctionalGroupsSequence)).to.equal(true);

expect(naturalSequence.ProcedureCodeSequence).to.have.property(
"CodingSchemeDesignator",
"L"
Expand Down Expand Up @@ -269,6 +269,7 @@ const tests = {
const dataset = DicomMetaDictionary.naturalizeDataset(
dicomDict.dict
);
expect(dataset.PixelData instanceof ArrayBuffer).to.be.true;
datasets.push(dataset);
});

Expand Down