Skip to content

Validate indices in set cover file readers to prevent OOB access#5260

Open
TristanInSec wants to merge 1 commit into
google:stablefrom
TristanInSec:fix/set-cover-reader-bounds-check
Open

Validate indices in set cover file readers to prevent OOB access#5260
TristanInSec wants to merge 1 commit into
google:stablefrom
TristanInSec:fix/set-cover-reader-bounds-check

Conversation

@TristanInSec

@TristanInSec TristanInSec commented Jul 18, 2026

Copy link
Copy Markdown

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 via ParseNextInteger() - 1. A file value of 0 produces SubsetIndex(-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 to size_t, producing a massive offset that causes out-of-bounds heap access. The existing guard in AddElementToSubset (subset >= num_subsets()) does not catch negative values because -1 >= 0 evaluates to false for signed comparison.

Changes

  • Add CHECK_GE validation in each reader function to reject invalid indices from file input before they reach the model.
  • Add CHECK_LT for solution readers to validate indices are within the declared range.
  • Add defense-in-depth CHECK_GE in AddElementToSubset to 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)

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.
@TristanInSec
TristanInSec changed the base branch from main to stable July 18, 2026 17:18
@Mizux Mizux added the Solver: Set Cover Solver in set_cover/ label Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Solver: Set Cover Solver in set_cover/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants