Repository navigation
Refuse encapsulation option padding that runs past the buffer end - #349
Rahul-cs50 wants to merge 1 commit into
Conversation
read_encapsulation() subtracts the option alignment from end_ when the representation options request trailing padding. On a buffer too short to actually contain that padding, end_ was moved before the read cursor; the remaining length then underflowed and later reads ran off the buffer, segfaulting. This is reachable from untrusted input, e.g. deserializing a truncated 4-byte CDR header through rmw_fastrtps (reported as ros2/rmw_fastrtps#940). Refuse such input with NotEnoughMemoryException before moving end_, the same way the other bounds checks in this file do. Buffers that are long enough to carry the padding are unaffected. Adds a regression test covering both the truncated header (now refused) and a buffer long enough to hold the padding (still accepted). Signed-off-by: Rahul-cs50 <rahulseervi.dev@gmail.com>
|
Independent verification of the fix in The completed run #41280186916 covers 448 executions: 2 arms × 2 RMW backends × 7 For
All seven layouts reject the reported four-byte header-only input after the fix. This includes five signal→error cases and one accepted→error case; Evidence artifact: per-case outcomes, comparison, source/patch and library fingerprints, package versions, mapped-library checks and build logs. Harness at the run commit. AI assistance was used for the verification harness, analysis and this summary; the figures above were checked against the completed run's output. This is additional regression evidence for this PR, rather than a general deserialization-safety claim. |
|
Thanks for checking this independently across both backends, @heathsanchez. It's good to see the four-byte header-only input rejected in all seven layouts, with the valid controls still passing. |
Description
Cdr::read_encapsulation()subtracts the option alignment fromend_when the representation options request trailing padding (end_ -= option_align). On a buffer that is too short to actually contain that padding,end_was moved before the read cursoroffset_; the remaining lengthend_ - offset_then underflowed and later reads ran off the buffer, leading to a segmentation fault (observed inCdr::read_string).This is reachable from untrusted input. Deserializing a truncated 4-byte CDR header (a valid encapsulation header with no payload) through
rmw_fastrtpscrashes the process; it was reported publicly as ros2/rmw_fastrtps#940.The fix refuses such input with
NotEnoughMemoryExceptionbefore movingend_, using the same(end_ - offset_)bounds check as the rest of the file. Buffers that are long enough to carry the padding are unaffected.Contributor Checklist
CDRTests.DDSEncapsulationTruncatedOptionAlignmentintest/cdr/SimpleTest.cppcovers both the truncated header (now refused) and a buffer long enough to hold the padding (still accepted). The fullUnitTests(356) andxcdr_tests(1720) suites pass with the change.