-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add non-copying string and byte getters on a TLV reader. #9249
Add non-copying string and byte getters on a TLV reader. #9249
Conversation
d3382c6
to
77d19a3
Compare
@bzbarsky-apple Looks like a real build failure |
3292d8a
to
1b2393a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking request changes to understand the separation - on second consideration, the new code also creates spans using GetLength() as the previous code, so actual length is identical as before, except the benefit of not really allocating it but just creating a view.
Following that line of reasoning, these methods could work on TLVReader as before or we may not even need the methods and just call GetDataPtr/GetLength in the places in setup payload as needed (stop allocating temporary storage space)
But only after calling a method (
Sure thing. If you know enough about the state of your reader. The new setup just delegates that state verification to the compiler, which is less error-prone than having humans do it.
Yes, we could absolutely do that. The drawbacks there are that it's non-obvious code to write, so people are not likely to write it by default. Instead they reach for I initially started with an attempt to just remove I am open to other API shapes here, by the way; what we have so far is not perfect by any means. It's a bit of a compromise between expediency and redesigning the entire TLV reader setup wholesale. |
Approved based on comments. I wish we had some resources to make TLV better - I think it went too far into trying to optimize backing store at the expense of safety and I am not convinced the fancy backing store is actually that used. |
d15c4a4
to
72c21b2
Compare
72c21b2
to
fd19050
Compare
@msandstedt @saurabhst @LuDuda @jepenven-silabs @jmartinez-silabs Please take a look? |
18c1aea
to
0ea82a9
Compare
We have existing callsites that are doing what GetString/GetBytes say to do and call GetLength() to decide how big a buffer to allocate. But the return value from GetLength() doesn't have to be sane, so we end up allocating buffers with attacker-controlled sizes. The changes here are: 1) Add ContiguousBufferTLVReader that is always backed by a single buffer, so it can guarantee that the in-place view makes sense. 2) Use the new class in setup payload parsers, fixing various bugs in the process. Fixes project-chip#9009
10 minutes keeps timing out.
0ea82a9
to
baa7f31
Compare
Size increase report for "esp32-example-build" from 488a3b0
Full report output
|
…p#9249) * Add non-copying string and byte getters on a TLV reader. We have existing callsites that are doing what GetString/GetBytes say to do and call GetLength() to decide how big a buffer to allocate. But the return value from GetLength() doesn't have to be sane, so we end up allocating buffers with attacker-controlled sizes. The changes here are: 1) Add ContiguousBufferTLVReader that is always backed by a single buffer, so it can guarantee that the in-place view makes sense. 2) Use the new class in setup payload parsers, fixing various bugs in the process. Fixes project-chip#9009 * Addressing review comments * More review comments * Bump Darwin build job bootstrap timeout to match other Darwin jobs. 10 minutes keeps timing out.
We have existing callsites that are doing what GetString/GetBytes say to do and call GetLength() to decide how big a buffer to allocate. But the return value from GetLength() doesn't have to be sane, so we end up allocating buffers with attacker-controlled sizes.
The changes here are:
Add ContiguousBufferTLVReader that is always backed by a single
buffer, so it can guarantee that the in-place view makes sense.
Use the new class in setup payload parsers, fixing various bugs in
the process.
Fixes #9009
Problem
See above.
Change overview
See above.
Testing
Added unit tests for the new readers. I haven't found a good way to test the buggy codepaths being fixed: for
retrieveOptionalInfoString
we would need to feed it invalid TLV data, andAdditionalDataPayloadParser
is completely untested (tracked in #9248).