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

XML containing inline binary content followed by empty attribute is parsed incorrectly, with binary data being filled into the empty attribute #698

Closed
andpab opened this issue Mar 24, 2020 · 2 comments
Assignees
Labels
Milestone

Comments

@andpab
Copy link

andpab commented Mar 24, 2020

Describe the bug
When using the ContentHandlerAdapter to parse a valid NativeDicomModel XML string that contains a DicomAttribute of VR OB with an InlineBinary child node in Base64 encoding and a subsequent DicomAttribute with VR ST and no content, some binary content is being filled into the empty attribute.

To Reproduce

The following simplistic test reproduces the problem:

    @Test
    public void parseXmlContentWithInlineBinaryFollowedByEmptyDicomAttribute() throws ParserConfigurationException, SAXException, IOException {
        String inputXmlString =
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<NativeDicomModel xml:space=\"preserve\">" +
            "  <DicomAttribute keyword=\"aaa\" tag=\"04070006\" privateCreator=\"MYPRIVCREATOR\" vr=\"OB\">\n" +
            "    <InlineBinary>" +
            "AAAAAAEHAQH/XAATQEBISFBISFBISFBISFBISFD/UgAMAAAAAQAFBAAAABZpaGRyAAACAAAAApgAAQcHAAAAAAAPY29scgEAAAAAABEAAAAAanAyY/9P/1EAKQAAAAACmAAAAg" +
            "AAAAAAAAAAAAAAApgAAAIAAAAAAAAAAAAMalAgIA0KhwoAAAAUZnR5cGpwMiAAAAAAanAyIAAAAC1qcDJoBAAB/2QADwABTFdGX0pQMl8yMDT/kAAKAAAAAAAUAAH/k4CAgICAgP/Z" +
            "    </InlineBinary>\n" +
            "  </DicomAttribute>\n" +
            "  <DicomAttribute keyword=\"bbb\" tag=\"04070007\" privateCreator=\"MYPRIVCREATOR\" vr=\"ST\"/>\n" +
            "</NativeDicomModel>";

        Attributes dataset = new Attributes();
        SAXParserFactory f = SAXParserFactory.newInstance();
        SAXParser parser = f.newSAXParser();
        ContentHandlerAdapter dcm4che3ContentHandlerAdapter = new ContentHandlerAdapter(dataset);
        parser.parse(new ByteArrayInputStream(inputXmlString.getBytes(StandardCharsets.UTF_8)), dcm4che3ContentHandlerAdapter);
        String emptyStAttributeContent= dataset.getString("MYPRIVCREATOR", 0x04070007);
        assertNull(emptyStAttributeContent);
    }

With dcm4che 5.22.0 the test fails as there is binary data in the supposedly empty second attribute.

Expected behavior
Attributes are parsed correctly and test succeeds.

Analysis
It seems the flag inlineBinary in ContentHandlerAdapter is not set to false in some cases. Adding an inlineBinary = false; to the end of endElement() for example makes the test succeed.

@gunterze gunterze self-assigned this Apr 9, 2020
@gunterze gunterze added the bug label Apr 9, 2020
@gunterze gunterze added this to the 5.22.1 milestone Apr 9, 2020
@gunterze
Copy link
Member

gunterze commented Apr 9, 2020

Exemplary bug report! Thx!

@hczedik
Copy link
Member

hczedik commented Apr 14, 2020

This was a duplicate of the much older issue https://dcm4che.atlassian.net/browse/LIB-440 (which was moved to github as #52).
I have closed #52 and linked it to this one.

zhongl pushed a commit to iaerac/dcm4che that referenced this issue Apr 28, 2020
…arsed incorrectly, with binary data being filled into the empty attribute fix dcm4che#698
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants