dcmjs-org / dcmjs

Javascript implementation of DICOM manipulation
https://dcmjs.netlify.com/
MIT License
287 stars 108 forks source link

Fail to denaturalize a sequence having private tags. #388

Open vpapaioannou opened 2 months ago

vpapaioannou commented 2 months ago

Assume a sequence SQ with some private tags. dcmjs converts SQ to an array of dictionaries and also converts the tag of headers without a keyword to a number e.g. (2005, 1404) -> 20051404. Hence, the SQ dictionary will have some keys that are string arithmetic e.g. '20051404'. Then, during addAccessor() a property '20051404' will be created. Given though that in Javascript and an array x, x[10] is the same as x['10'], adding a property '20051404' will cause the extension of the SQ to have at least 20051404 elements with undefined values as needed.

This extension causes problems during denaturalization for the SQ; when traversing SQ the undefined sub data sets will be encountered and there will be an error when trying to read these data sets and process their tags.

The remedy would be either to skip the arithmetic tags, to convert the tags back to tuples when adding getter/setter functions or to not covert the tags to numbers at all. Below is an example for skipping.

var addAccessors = function addAccessors(dest, src) {
    Object.keys(src).forEach(function (key) {
    if (!(!isNaN(key) && !isNaN(parseFloat(key)))) {
        // allow non-numeric keys only
        Object.defineProperty(dest, key, {
            get: function get() {
                return src[key];
            },
            set: function set(v) {
                src[key] = v;
            },
            configurable: true
        });
    }
    });
};

This error is found for dcmjs 0.19.9

pieper commented 2 months ago

Thanks for reporting 👍

I haven't run across data like this in dcmjs. Could you share or create a sample data and make a (failing) test that illustrates the issue so that solutions could be tested?