Fix String Vector OOB Vulnerability#1066
Open
sayanshaw24 wants to merge 2 commits into
Open
Conversation
added 2 commits
May 21, 2026 13:56
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request hardens the TF-String text operators’ mapping-table parsing to prevent a heap out-of-bounds write when the map attribute contains inconsistent value-column widths across lines.
Changes:
- Added a strict column-count equality check in
VectorToStringImpl::ParseValuesto prevent writes past the preallocatedvaluesbuffer. - Added the same check in
StringToVectorImpl::ParseValuesfor the sibling operator. - Added new static unit tests validating rejection of inconsistent column widths and acceptance of consistent mappings.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
operators/text/vector_to_string.cc |
Adds a guard to reject mapping lines whose token count differs from the expected vector length, preventing OOB writes. |
operators/text/string_to_vector.cc |
Mirrors the same guard in the reverse mapping operator for consistent safety behavior. |
test/static_test/test_vector_string_parse.cc |
Adds regression tests for inconsistent/consistent mapping table line widths for both operators. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fix heap OOB write in VectorToStringImpl::ParseValues and StringToVectorImpl::ParseValues
Summary
Adds a bounds check to
ParseValuesin bothVectorToStringImplandStringToVectorImplto prevent a heap buffer overflow write when a crafted ONNX model supplies amapattribute with inconsistent line widths.Problem
ParseMappingTablederivesvector_len_from the first line of themapattribute and allocates a fixed-sizestd::vector<int64_t> values(vector_len_). It then callsParseValuesfor every subsequent line using the same buffer.ParseValuesiterates based on the current line's token count (value_strs.size()) and writes tovalues[i]without checking whetheriis within bounds.An attacker-authored model with a short first line and a longer later line triggers a linear heap OOB write of attacker-chosen
int64_tvalues at session-creation time.Fix
Added a size check at the top of
ParseValuesin both files:This enforces the invariant that every line in the map must have the same number of value columns as the first line, and throws before any write occurs if violated.
Files changed
operators/text/vector_to_string.cc— bounds check inParseValuesoperators/text/string_to_vector.cc— bounds check inParseValues(copy-paste sibling)test/static_test/test_vector_string_parse.cc— new unit testsTesting
6 new tests added to the
ocos_testtarget covering both operators:All 60 tests in
ocos_testpass.