Setting single value in the string with VM > 1 results in an incorrect string

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Oleh
Posts: 2
Joined: Thu, 2024-09-12, 08:45

Setting single value in the string with VM > 1 results in an incorrect string

#1 Post by Oleh »

Hi,

I've recently encountered DCMTK behavior that looks like a bug to me, and I can't find similar threads or existing tickets.

Scenario:
* Start with any valid DICOM data set
* Add element 0020, 0032 - Image Position (VR: Decimal string, VM - 3). For example set it to "-1\-2\-3" (padding is ommited)
* Try to replace only middle value - either by calling putOFStringAtPos("2", 1) or via similar call to the putFloat64

Expected result: value is changed to the "-1\2\-3"
actual: value is "1\2-3"

Note: similar issue happens with other tags, like 0020,0037 for the intermediate positions
Looking at the sources of DCMTK, I think the problem is in the

Code: Select all

OFCondition DcmByteString::putOFStringAtPos
implementation

in the very end, it contains:

Code: Select all

       else
        {
            str = str.replace(leftPos+1, rightPos - leftPos, stringVal);
        }

which is called for such intermediate replacements.

but the second parameter should be rightPos - leftPos - 1, otherwise it overwrites characted at the rightPos, which is the next backslash.

Michael Onken
DCMTK Developer
Posts: 2073
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Setting single value in the string with VM > 1 results in an incorrect string

#2 Post by Michael Onken »

This simply looks like a bug, we are looking into it. Thank you for reporting!

BR Michael

Michael Onken
DCMTK Developer
Posts: 2073
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Setting single value in the string with VM > 1 results in an incorrect string

#3 Post by Michael Onken »

Hi,

your report and patch have been correct, thanks again :-)

I submitted a patch along with some test code to the DCMTK repository which will be available on the public mirrors within the next days.

BR Michael

Oleh
Posts: 2
Joined: Thu, 2024-09-12, 08:45

Re: Setting single value in the string with VM > 1 results in an incorrect string

#4 Post by Oleh »

Perfect,

Thank you!

J. Riesmeier
DCMTK Developer
Posts: 2549
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Setting single value in the string with VM > 1 results in an incorrect string

#5 Post by J. Riesmeier »

Here it is.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest