Skip to content

xml: fix DataClassification unmarshal over-reading past its element - #275

Open
arpitjain099 wants to merge 1 commit into
CycloneDX:masterfrom
arpitjain099:chore/dataclassification-xml-endtag
Open

xml: fix DataClassification unmarshal over-reading past its element#275
arpitjain099 wants to merge 1 commit into
CycloneDX:masterfrom
arpitjain099:chore/dataclassification-xml-endtag

Conversation

@arpitjain099

Copy link
Copy Markdown

DataClassification.UnmarshalXML terminates its token loop on </dataflow> (a hardcoded literal), but the same type is also bound to the <classification> element via EvidenceData.Classification (xml:"data>classification"), not only <dataflow> (xml:"data>dataflow"). When decoding a <classification> element the loop never sees </dataflow>, so it keeps reading past its own end tag and consumes following tokens until io.EOF, which surfaces as a decode error. Any BOM that carries an evidence-data classification then fails to decode, and content after it is silently dropped.

The fix compares against the element the unmarshaler was actually called for (start.Name) instead of a literal, which is the usual depth-0 termination pattern for a custom UnmarshalXML. Child elements are still consumed by the inner loops, so the first top-level end element is always this element's own close.

I added a round-trip test with a 1.6 BOM whose declarations carry an evidence-data classification followed by a components block: it fails to decode with EOF before the change and decodes cleanly (classification parsed, components preserved) after.

DataClassification.UnmarshalXML ends its token loop on a hardcoded
</dataflow> end tag, but the same type is also bound to the
<classification> element (EvidenceData.Classification, xml:"data>classification")
in addition to <dataflow> (xml:"data>dataflow"). When decoding a
<classification> element the loop never sees </dataflow>, so it reads
past its own end tag and consumes following tokens until io.EOF, which
surfaces as a decode error and silently drops any content after it.

Compare against start.Name instead of the literal, which is the normal
depth-0 termination for a custom UnmarshalXML. Adds a round-trip test
with an evidence-data classification followed by a components block.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@arpitjain099
arpitjain099 requested a review from a team as a code owner July 13, 2026 19:29
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant