xml: fix DataClassification unmarshal over-reading past its element - #275
Open
arpitjain099 wants to merge 1 commit into
Open
xml: fix DataClassification unmarshal over-reading past its element#275arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
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>
Up to standards ✅🟢 Issues
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DataClassification.UnmarshalXMLterminates its token loop on</dataflow>(a hardcoded literal), but the same type is also bound to the<classification>element viaEvidenceData.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 untilio.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 customUnmarshalXML. 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
EOFbefore the change and decodes cleanly (classification parsed, components preserved) after.