validate trace packet payload layout before using its accessors#9230
Open
Nashit-h wants to merge 1 commit into
Open
validate trace packet payload layout before using its accessors#9230Nashit-h wants to merge 1 commit into
Nashit-h wants to merge 1 commit into
Conversation
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.
Both trace-packet readers take
size,dimensions,lanesand the element type straight from the stream and then hand out pointers computed from them:value()iscoordinates() + dimensionsandfunc()isvalue() + lanes * type().bytes(), so a packet declaring 2000 dimensions with a four-byte payload putsfunc()8001 bytes into a 4096-byte payload array.HalideTraceDumprunsstring(p.func())on that (ASAN reports a heap-buffer-overflow READ instrlen; without ASAN it prints whatever memory follows the packet as a Func name) andHalideTraceVizindexescoordinates()the same way;sizeis also used unchecked insize - header_size, so a size below the header underflows the payload length. Both readers now reject an undersizedsizeand check, once the payload is in, that the coordinates and value fit in the bytes actually read and that the func name and trace tag are terminated inside them, which every packet written bysrc/runtime/tracing.cppalready satisfies since it derivessizefrom exactly those parts.The trace tools aren't built or exercised by the test suite, so there's no natural home for a regression test; I checked this with crafted trace files against a standalone harness around the reader, and with a well-formed packet to confirm valid input still parses identically.
Checklist