Skip to content

Add validation for input data#2220

Open
apsonawane wants to merge 4 commits into
mainfrom
asonawane/beamsearch
Open

Add validation for input data#2220
apsonawane wants to merge 4 commits into
mainfrom
asonawane/beamsearch

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request focuses on improving type safety and robustness when converting JSON configuration values to integers, and fixes a potential overflow bug in the beam search scorer. The most important changes are:

Type Safety and Robustness in Configuration Parsing:

  • Replaced direct static_cast<int> conversions with SafeDoubleToInt for several configuration parameters in src/config.cpp, including context_length, max_length, batch_size, and num_beams, to prevent unsafe casts and handle errors more gracefully. [1] [2]

Bug Fix in Beam Search Scorer:

  • Fixed a possible integer overflow in the calculation of per_beam by explicitly casting max_length_ to size_t before multiplication in src/beam_search_scorer.cpp.

@apsonawane apsonawane requested a review from a team as a code owner June 11, 2026 23:01
Copilot AI review requested due to automatic review settings June 11, 2026 23:01
@apsonawane apsonawane enabled auto-merge (squash) June 11, 2026 23:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to harden JSON configuration parsing for integer-valued fields and to prevent overflow-related issues in beam search buffer sizing, improving robustness of generation configuration and runtime stability.

Changes:

  • Switched selected JSON numeric-to-int conversions in src/config.cpp from direct casts to SafeDoubleToInt.
  • Updated the beam search intermediate buffer sizing math in src/beam_search_scorer.cpp to use size_t arithmetic.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/config.cpp Uses a safer conversion helper for several integer-valued JSON fields during config parsing.
src/beam_search_scorer.cpp Adjusts per_beam sizing computation to avoid signed overflow during buffer allocation.

Comment thread src/config.cpp
Comment thread src/config.cpp
Comment thread src/config.cpp
Comment thread src/beam_search_scorer.cpp
Comment thread src/config.cpp Outdated
Comment thread src/config.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants