Skip to content

Reject whitespace-prefixed negative values in stou64 - #4694

Merged
mzegla merged 1 commit into
openvinotoolkit:mainfrom
Veditha08:fix-stou64-whitespace-negative
Oct 26, 2026
Merged

mzegla merged 1 commit into
openvinotoolkit:mainfrom
Veditha08:fix-stou64-whitespace-negative

Conversation

@Veditha08

@Veditha08 Veditha08 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🛠 Summary

Fix ovms::stou64 to reject whitespace-prefixed negative numbers.

std::stoull skips leading whitespace before parsing. The existing negative-number guard checked only the first character, allowing inputs such as " -100" and "\t-100" to bypass the check and wrap around into large positive uint64_t values.

This change checks the first non-whitespace character and adds regression coverage while preserving the expected handling of valid positive values.

Fixes #4695

🧪 Validation

  • OpenVINO Model Server StringUtils Bazel tests: 16 passed, 0 failed.
  • clang-format 6.0.1: no formatting discrepancies detected.
  • License-header check: passed.
  • Forbidden-function check: passed.
  • The full make sdl-check and make test_checksec targets were not completed because of environment/prerequisite limitations.

Checklist

  • Unit tests added.
  • The documentation updated — not applicable to this internal parsing fix.
  • Change follows security best practices.

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.

🟢 Approval recommended

The localized fix addresses the reported parsing bypass with relevant regression coverage and no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes #4695 by updating OVMS’s stou64 utility to reject whitespace-prefixed negative values while preserving valid positive conversions.

Changes:

  • Checks the first non-whitespace character before unsigned conversion.
  • Adds regression tests for negative inputs with leading whitespace, valid positive inputs, and empty or whitespace-only strings.
File Description
src/​test/​stringutils_test.cpp Adds regression and boundary-case coverage for stou64.
src/​stringutils.cpp Rejects negative values after leading whitespace.

Review effort: Balanced

@mzegla
mzegla merged commit 687dff1 into openvinotoolkit:main Oct 26, 2026
10 checks passed
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.

stou64() accepts negative values preceded by whitespace

3 participants