Fix out-of-bounds write from failed bytes-list skips in fast parsing#120631
Fix out-of-bounds write from failed bytes-list skips in fast parsing#120631Abhinav-143x wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request improves error handling in ParseBytesFeature by checking the return value of stream->Skip(bytes_length) and returning -1 if it fails. Additionally, a new unit test SparseStringMalformedBytesListReportsError has been added to example_proto_fast_parsing_test.cc to verify that parsing a malformed bytes list correctly reports an error. There are no review comments to address, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
This change fixes a memory-safety issue in the fast example parser by making the bytes-list counting path reject failed
CodedInputStream::Skip()calls.Today the copy path returns an error when
ReadRaw()fails, but the count path can continue after a failedSkip(). For malformed bytes-list input, that can make the parser record an element count during the count pass and then observe an error during the copy pass. In sparseSequenceExampleparsing, that count/copy mismatch can lead to sparse-index writes past the allocated tensor buffer.The fix propagates the failed
Skip()as an error so malformed input is rejected consistently before sparse-index output construction.A regression test covers a malformed sparse string
SequenceExamplewhere a bytes-list value declares more bytes than are present.Tested:
git diff --checkSkip()fix: PASSED