Validate indices in set cover file readers to prevent OOB access#5260
Open
TristanInSec wants to merge 1 commit into
Open
Validate indices in set cover file readers to prevent OOB access#5260TristanInSec wants to merge 1 commit into
TristanInSec wants to merge 1 commit into
Conversation
The ORLIB SCP/Rail and solution text/proto readers accept file-derived integer values as array indices without validating that they are non-negative and in range. When the signed BaseInt (int32_t) is negative, StrongVector::operator[] casts it to size_t, producing a massive offset that causes out-of-bounds heap access. Add CHECK_GE/CHECK_LT guards in each reader function and a defense-in- depth check in AddElementToSubset to reject negative indices early.
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.
Summary
The ORLIB SCP/Rail readers and solution text/proto readers accept file-derived integer values as array indices without validating that they are non-negative and in range.
ReadOrlibScp: 1-indexed subset values are converted to 0-indexed viaParseNextInteger() - 1. A file value of0producesSubsetIndex(-1).ReadOrlibRail: Same pattern for element indices.ReadSetCoverSolutionText: 0-indexed subset values are used directly without range checking.ReadSetCoverSolutionProto: Same pattern.When the signed
BaseInt(int32_t) is negative,StrongVector::operator[]casts it tosize_t, producing a massive offset that causes out-of-bounds heap access. The existing guard inAddElementToSubset(subset >= num_subsets()) does not catch negative values because-1 >= 0evaluates tofalsefor signed comparison.Changes
CHECK_GEvalidation in each reader function to reject invalid indices from file input before they reach the model.CHECK_LTfor solution readers to validate indices are within the declared range.CHECK_GEinAddElementToSubsetto catch negative element/subset indices from any caller.Affected files
ortools/set_cover/set_cover_reader.cc(4 reader functions)ortools/set_cover/set_cover_model.cc(AddElementToSubset)