Enet4 / dicom-rs

Rust implementation of the DICOM standard
https://dicom-rs.github.io
Apache License 2.0
404 stars 76 forks source link

InMemDicomObject with defined Length retains Length value after changes to inner value of object #362

Closed jmlaka closed 11 months ago

jmlaka commented 1 year ago

Suppose we have a sequence with defined Length from reading a dicom file.

Parsing the sequence into items yields InMemDicomObjects with defined Length value. After changes are made to such InMemDicomObject (.remove_element .put ...) it retains it's original Length value.

How I found out: Constructing file output from such changed InMemDicomObjects results in faulty output.

A workaround is constructing a InMemDicomObject::from_element_iter(vec![original_object]) which sets the Length::UNDEFINED

Can the API be changed so that any changes to internal value of InMemDicomObject will reset the Length to undefined ?

Thank you

Enet4 commented 1 year ago

Thank you for reporting, @jmlaka. That is right, the byte length is not updated automatically. Recalculating it on every change would be too expensive, but resetting it to undefined sounds good to me!

How I found out: Constructing file output from such changed InMemDicomObjects results in faulty output.

This sounds more serious though. I had the impression that I had fixed these cases in #172, but as it turns out, it only redetermines the length of primitive data elements, and not of nested data sets. In cases where the length cannot be trusted, it is better to leave the length as implicitly defined upon writing.

Could you work on a pull request? Much appreciated!

Enet4 commented 11 months ago

Resolved via #364.