Skip to content

fix(model): return an error for truncated tree bytes - #6132

Open
Vanshul97 wants to merge 1 commit into
grafana:mainfrom
Vanshul97:fix/unmarshal-tree-truncated-input
Open

Vanshul97 wants to merge 1 commit into
grafana:mainfrom
Vanshul97:fix/unmarshal-tree-truncated-input

Conversation

@Vanshul97

Copy link
Copy Markdown

UnmarshalTree is meant to return errMalformedTreeBytes for bad input, but truncated input was not handled consistently:

  • a function name length running past the end of the buffer panicked with a slice bounds error
  • reading a varint at or past the end of the buffer panicked or, when the buffer was exactly exhausted, returned a zero length read that was not treated as an error, so some truncated trees were accepted silently
  • the children slice was sized from an unchecked length read from the input

This validates offsets and lengths (treating a zero length varint read as malformed, and bounding the child count by the remaining bytes) and returns errMalformedTreeBytes in those cases. Valid input is unaffected.

Tested: added TestUnmarshalTree_TruncatedInput, which truncates marshaled function and location trees at every length. It fails without the change (panics and missing errors) and passes with it. go test -race ./pkg/model/ ./pkg/frontend/... passes.

UnmarshalTree panicked on truncated input in several places (slicing
the name past the end of the buffer, reading varints past the end) and
silently accepted other truncations because a zero length varint read
was not treated as an error. It also sized the children slice from an
unchecked length. Validate offsets and lengths and return
errMalformedTreeBytes instead.
@cla-assistant

cla-assistant Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Nov 23, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant

cla-assistant Bot commented Nov 23, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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