Repository navigation
fix(cli): parse_unsigned negative/overflow guards + --help in cli_parse.cpp (ADR-1088) - #794
Merged
Merged
Conversation
lusoris
marked this pull request as ready for review
June 6, 2026 20:46
lusoris
force-pushed
the
fix/r14-cli-flag-parsing
branch
from
June 6, 2026 22:34
5ea1835 to
d85b6ac
Compare
Merged
4 tasks
lusoris
force-pushed
the
fix/r14-cli-flag-parsing
branch
3 times, most recently
from
June 6, 2026 23:20
a4c34bf to
c91526d
Compare
lusoris
force-pushed
the
fix/r14-cli-flag-parsing
branch
from
June 7, 2026 01:46
c91526d to
b0902ad
Compare
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
parse_unsignedsilently accepted-1:strtoul("-1")wraps toULONG_MAXwithoutERANGE; the*end=='\0'guard passed, so--frame_cnt -1storedUINT_MAXinsettings->frame_cnt, causing the frame loop to attempt ~4 billion iterations. Fix: reject any optarg whose first character is'-'before callingstrtoul.parse_unsignedsilently accepted >32-bit values on 64-bit hosts:strtoul("5000000000")returns 5 000 000 000 without error; the(unsigned)cast silently wraps to 705 032 704. Fix: checkul > UINT_MAXafterstrtoul.--helpmissing from production binary:cli_parse.cpp(compiled since ADR-0809) lackedARG_HELP/--help;vmaf --helpfell into getopt's unknown-option path and printed a confusing mandatory-argument error. Ported fromcli_parse.c.Both overflow/negative paths emit
"Invalid argument … should be an integer in [0, 2^32-1]"andexit(1), consistent with every other bad-input path.Changed files
core/tools/cli_parse.cppcerrno/climitsincludes;parse_unsignedleading-'-'+ul > UINT_MAXguards;ARG_HELPenum value +long_opts[]entry +case ARG_HELP:arm + usage text linecore/tools/cli_parse.cparse_unsignedguards (used by unit test target)core/test/test_cli_parse_long_only_args.c--frame_cnt -1,--frame_skip_ref -5,--frame_skip_dist -1,--frame_cnt 5000000000,--threads -1core/tools/AGENTS.mddocs/adr/1088-r14-cli-flag-parsing.mddocs/adr/README.mdchangelog.d/fixed/1088-…mddocs/rebase-notes.mddocs/state.mdTest plan
meson test -C build test_cli_parse_long_only_args— five new tests + four existing (--threads abc, --subsample xyz, --cpumask qqq, --th=foosoxe) must passmeson test -C build test_cli_parse— existing aom_ctc / backend / no_reference tests must be unaffectedvmaf --helpprints help text and exits 0 (production binary only — cli_parse.cpp)vmaf --frame_cnt -1 …printsInvalid argument "-1"and exits 1vmaf --frame_cnt 5000000000 …printsInvalid argument "5000000000"and exits 1Deliverables checklist (ADR-0108)
## Alternatives consideredcore/tools/AGENTS.mdvmaf --frame_cnt -1 -r ref.y4m -d dis.y4m→ exit 1 + "Invalid argument"changelog.d/fixed/1088-cli-parse-unsigned-overflow-negative-help.mddocs/rebase-notes.mdentryno rebase impact: changes confined to
cli_parse.c,cli_parse.cpp, andtest_cli_parse_long_only_args.c. No public API, no header, no model, no upstream-mirrored file is modified.🤖 Generated with Claude Code