Repository navigation
fix(opts): validate --pipeline / --data-size / --data-size-list size (Refs #426 phase 2b) - #428
Conversation
…(Refs redis#426 phase 2b) Reject at argv-parse time three size-related flag values that previously hung or crashed deep in the run loop: * --pipeline -1 (item 6) -- negative cast to unsigned passed the zero-check and drove an underflow / retry loop that ignored --test-time. * --data-size -1 (item 7) -- same underflow; first SET tripped the value_len > 0 assert in protocol.cpp:309. * --data-size-list 0:50 (item 9) -- size=0 entry triggered the same assert at first SET. Caps: --pipeline <= 1024 (saturates most NICs; tighter than UINT_MAX) --data-size <= 512 MiB (matches Redis default proto-max-bulk-len) --data-size-list entry size: same 512 MiB cap, must be > 0 A leading '-' in optarg is now detected explicitly before strtoul so the caller sees a readable error tied to the offending flag instead of an abort or hang. --data-size-list 8:0 (zero WEIGHT, item 10) is intentionally NOT caught here: that needs sampler-construction safety in phase 3. Regression tests in tests/test_cli_validation_size.py cover all three repros, the cap boundaries, the zero cases, and a known-good value. Refs redis#426 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Review: performance (haiku 4.5) verdict: parse-time validation, zero request-loop impact ✓ • Validation scope: --pipeline, --data-size, --data-size-list validation runs once during argv parsing. All checks are integer comparisons and magnitude bounds (strtoul, range caps PIPELINE_MAX=1024, DATA_SIZE_MAX=512MiB). Zero hot-loop involvement. ✓ • optarg_is_negative() helper: Three branch-free pointer comparisons per flag (while *s isspace, then *s=='-'). Called once per invocation. Negligible cost that prevents silent unsigned-underflow hangs. ✓ • Data-size-list iteration: Iterates once at parse time over the entry list (not per-request). Each entry checks size bounds; O(n) where n = number of size buckets (typically <10). No request-loop overhead. ✓ • Zero allocations added: All validation uses stack temporaries and existing config structures. No new heap churn in the benchmark run. ✓ Summary: Pure parse-time hardening. The cap checks (pipeline<=1024, data-size<=512MiB) prevent configs that would either hang (pipeline too large causing backpressure loops) or crash (data-size causing OOM). Zero steady-state CPU, memory, or lock overhead. |
|
Review: docs & commit message (haiku 4.5)
Verdict: Commits clean; DEVELOPMENT.md needs comprehensive CLI bounds documentation. |
|
Review: design & API (sonnet 4.6) Verdict: The fixes are correct and the caps are well-motivated, but the constant placement and naming deserve attention before the series is done.
|
fcostaoliveira
left a comment
There was a problem hiding this comment.
Review: security (opus 4.7)
- LOAD-BEARING:
optarg_is_negative()correctly catches the-1-wrap path for--pipelineand--data-size, but--data-size-liststill has the same bug at a lower layer:config_weight_list::config_weight_list(const char *str)at config_types.cpp:140 callsstrtoul(str, &p, 10)on eachsize:weightsegment with no-pre-check.--data-size-list=-1:50parses as size=ULONG_MAX-> narrows toUINT_MAX, then PASSES the newit->size > MEMTIER_DATA_SIZE_MAXcheck… wait, no —UINT_MAX > 512 MiB, so it actually trips the upper bound here. But--data-size-list=-1:50,8:50producesUINT_MAXfor the first entry and is correctly caught. Worth pinning down with a regression test for-1:50explicitly. strtoulerrno = ERANGEis not checked for--pipeline/--data-size—"99999999999999999999"returnsULONG_MAXand is then rejected by the> 1024/> 512 MiBcap, so the security outcome is correct, but the expliciterrno = 0+errno == ERANGEcheck would make the intent clear and protect future maintainers who might raise the caps.unsigned long->unsigned intnarrow atcfg->pipeline = (unsigned int) pipeline_val;is safe because the cap is 1024; same fordata_size(cap 512 MiB fits in unsigned int). Good.- The 512 MiB cap matching
proto-max-bulk-lenis a sensible defense against DoS via giantevbuffer_addallocations downstream (each thread × client × pipeline holds a value-sized buffer; with the old unbounded cast,data_size=-1would have tried to allocate ~4 GiB per buffer × N clients). optarg_is_negativeonly strips space/tab, not vertical whitespace — fine for argv but inconsistent with theisspace((unsigned char) *first)loop in PR #427'sset_ratio. Cosmetic.- No format-string / credential risk in the new error paths.
Verdict: LGTM with one optional tightening (explicit errno == ERANGE reject for strtoul) and a request for an explicit regression test on --data-size-list=-1:50. The phase 2b scope is correctly delivered.
fcostaoliveira
left a comment
There was a problem hiding this comment.
Review: correctness & latent bugs (opus 4.7)
memtier_benchmark.cpp:780-786optarg_is_negativeonly skips' 'and'\t'.strtoul()per C also accepts\n\v\f\ras leading whitespace, sooptarg = "\n-1"(yes, contrived via env/script edge cases) would slip through this check and underflow intostrtoul. Cheap fix: useisspace((unsigned char) *s)(and#include <ctype.h>).memtier_benchmark.cpp:1167-1183no check that the parsed value fits inunsigned int.--pipeline 4294967297on 64-bit truncates via(unsigned int)to 1 silently — caught accidentally by the> MEMTIER_PIPELINE_MAX (1024)cap, so user-visible behavior is fine, but worth a comment that the cap is what guards truncation. Same applies to--data-size.memtier_benchmark.cpp:1208-1228the new per-entry size validation only runs afterconfig_weight_listhas already parsed and stored every entry.config_weight_list(optarg)itself usesstrtoulon eachsize:weighttoken; a hostile entry like--data-size-list=99999999999:1,8:50will silently truncate the first size tounsigned intand may end up passing the> 512 MiBcap depending on truncation. Recommend either (a) capturing original strings for re-validation, or (b) tighteningconfig_weight_listitself to reject overflows.memtier_benchmark.cpp:1208-1227overlaps with PR #430 — both add afor (... item_list)loop in the samecase 'a':arm (one checkssize==0, the otherweight==0). Merging order matters: whichever lands first will leave the other PR with a non-trivial conflict in thecase 'a':block. Suggest pre-merging the loops in one of the PRs.tests/test_cli_validation_size.py:90-99the "valid passes parse" tests connect to port 1 and assert"pipeline must be" not in stderr. memtier's connect-failure path also prints to stderr; if a future error path ever includes the substringpipeline must befor a different reason the test would silently mis-pass. Tighten to an exit-code check or a positive "parsed --pipeline=2" assertion.- The 512 MiB cap on
--data-sizeisunsigned.cfg->data_sizeisunsigned int; on a platform whereunsigned intis 16-bit (none we ship, but worth astatic_assert) this overflows. Trivial belt-and-suspenders.
Verdict: Comment
fcostaoliveira
left a comment
There was a problem hiding this comment.
Review: edge cases & failure modes (opus 4.7)
Verdict: LGTM with cap-boundary and per-entry-negative gaps.
- Invocation paths:
parse_uri()does not handle--pipeline/--data-size/--data-size-list, and there's no config-file feature — long-option is the only entry, validation correctly catches every path. - Cap-boundary tests missing: the test suite covers
1025rejected and2accepted but not1024(cap) and1023(cap-1). Same for--data-size:512*1024*1024(cap, accepted) and512*1024*1024+1(cap+1, rejected) are not exercised. The>comparison is correct for the cap-as-inclusive-upper-bound intent, but a regression to>=would silently break the documented boundary. Add at least one cap-value-accepted test. --data-size-listper-entry negatives bypassoptarg_is_negative: the helper is only called for--pipelineand--data-size.--data-size-list=-1:50flows throughconfig_weight_listwherestrtoulwraps the-1to ULONG_MAX, then truncation tounsigned intyieldsUINT_MAX. The newit->size > MEMTIER_DATA_SIZE_MAXcheck catches it — good — but the error message ("entry size must be <= 512 MiB") misleads the user about what they actually typed. Consider applyingoptarg_is_negativeto the whole--data-size-listoptarg, or scanning for-in any entry before the cap check.strtoulERANGE not consulted:--pipeline=99999999999999999999overflows ULONG_MAX →strtoulreturns ULONG_MAX and sets errno=ERANGE; the code doesn'terrno = 0before the call and doesn't check ERANGE. It's saved by the> 1024cap, but the error message ("must be <= 1024") is again misleading on truly out-of-range input. The neighboring--run-countPR (#429) does this correctly (errno = 0; ... errno == ERANGE).optarg_is_negativewhitespace skip is narrower thanisspace: only skips' 'and'\t'.--pipeline=\v-1or\n-1wouldn't trip the negative check. Unlikely from a CLI in practice, butisspace((unsigned char) *s)matches the convention used inset_ratio()in PR #427.- Cast safety:
pipeline_val(unsigned long) is bounded to 1024 before the cast tounsigned int— safe.data_size_valsimilarly bounded to 512 MiB before the cast — safe. Per-entryit->sizeis alreadyunsigned intfromconfig_weight_list, so the cap check is on the post-truncation value —it->size > MEMTIER_DATA_SIZE_MAXcorrectly catchesUINT_MAXfrom the negative-wrap case.
fcostaoliveira
left a comment
There was a problem hiding this comment.
Review: style & readability (sonnet 4.6)
Verdict: clean; two notes on the new helper.
-
optarg_is_negativeskips only space and tab;set_ratioin the companion PR #427 usesisspace()(memtier_benchmark.cpp): both helpers serve the same purpose (strip leading whitespace before inspecting the first character) but use different whitespace definitions.isspace((unsigned char))is the C idiom and covers all locale whitespace; the manual' ' || '\t'is narrower. Aligning the two before the series merges avoids a "which one is the intended contract?" question for later readers. -
optarg_is_negativecomment explains what it detects, not why it's needed alongsidestrtoul(memtier_benchmark.cpp): the comment correctly names the underflow root cause (strtoulsilently wraps), but the why it must be a separate pre-check — rather than just adding a post-check on the parsed value — is thatstrtoul("−1", ...)on some platforms returnsULONG_MAXand setserrno=ERANGE, while on others it wraps silently with no error. The pre-check is the platform-portable solution; saying so makes the guard obviously non-redundant. -
Error message
"data-size must be <= %u bytes (512 MiB)."embeds the literal unit — the companiondata-size-listmessage in PR #430 will say "weight greater than zero" (words, no symbol). Using> 0for size and words for weight in adjacent error messages is a minor inconsistency; words throughout would read more uniformly. -
#define MEMTIER_PIPELINE_MAX 1024u/MEMTIER_DATA_SIZE_MAXplaced after a function definition (memtier_benchmark.cpp): project convention groups#defineconstants near the top of the file with other globals (see line 90 area). Moving these up avoids them being read as local-to-optarg_is_negative. -
Commit message headline truncated (
fix(opts): validate --pipeline / --data-size / --data-size-list size …): subject line was cut by GitHub at 72 chars. Suggest: "fix(opts): validate --pipeline / --data-size / --data-size-list (#426)".
Resolves the case 'o_data_size_list' overlap with PR redis#428: combine both validations into one pass over data_size_list.item_list: * size == 0 -> error: zero-size trips protocol.cpp:309 assert (item 9 from redis#426) * size > 512 MiB -> error: exceeds proto-max-bulk-len cap (PR redis#428) * weight == 0 -> error: zero-weight makes the sampler loop forever picking nothing (item 10 from redis#426, phase 3)
…/0 (#436) * fix(opts): reject negative -c/-t/-n/--test-time; guard Hits/sec from /0 Same crash class as merged phases #428/#429 (--pipeline, --data-size, --run-count): strtoul("-1") wraps to UINT_MAX and -c -1 then tries to spawn ~4B clients. The four count flags missed the phase-2 sweep. Also adds a > 0 guard to run_stats.cpp summarize() for the legacy GET Hits/sec / Misses/sec computation (the only summarize site without one); sub-microsecond runs were emitting +Inf / nan into the JSON. Refs: 2.4 review findings #24 + #19 Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * fix(stats): guard all summarize() rate computations from /0; standardize error wording Reviewers R3+R4 flagged that the prior commit only guarded m_hits_sec and m_misses_sec in summarize(); six sibling rate computations (m_ops_sec, m_bytes_sec, m_bytes_sec_rx, m_bytes_sec_tx, m_moved_sec, m_ask_sec, m_connection_errors_sec) still divided by test_duration_usec with no guard. All now use the (test_duration_usec > 0 ? ... : 0.0) ternary, consistent with sites at lines 1300, 1311, 1317, 1344, 1354, 1360, 1627, 1629. R5 also flagged that the four new error messages mixed "must be a positive integer" and "must be greater than zero". Standardized to match the phase-2 convention. Refs: 2.4 review of PR #436 (R3/R4/R5). Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]>
…445) The fuzzer excluded flags/inputs (--cluster-mode against standalone, --authenticate empty, --wait-ratio, G:G degenerate, --data-size-list zero-weight/zero-size, negative count flags) because they used to crash or hang. The phase-1-3 parser fixes (#427/#428/#429/#430) plus the connection-stage-timeout supervisor (#431) now bound all of those. Removed the exclusions and wired the fuzzer into CI so it runs nightly. Also fix .githooks/pre-commit to work from linked worktrees: locate the Makefile via git-common-dir and export GIT_INDEX_FILE so that `git diff --cached` inside the Makefile rule sees the worktree-local index rather than the main worktree's index. Refs: 2.4 review #20 (Review 8 + Review 17). Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Summary
Phase 2b of #426: reject three size-related CLI values at argv-parse time so the binary errors out cleanly instead of hanging or aborting deep in the run loop.
--pipelinemust be > 0 and <= 1024 (saturates most NICs; tighter than UINT_MAX).--data-sizemust be > 0 and <= 512 MiB (matches Redis defaultproto-max-bulk-len).--data-size-listentry sizes must be > 0 (same 512 MiB cap per entry).optarg(leading-) is now detected explicitly beforestrtoul, which previously cast-1to a huge unsigned value and sailed past every downstream check.Items closed (from #426)
--pipeline -1no longer hangs (negative passed through unsigned, underflow loop).--data-size -1no longer SIGABRTs atprotocol.cpp:309 assert value_len > 0.--data-size-list 0:50(zero SIZE) no longer SIGABRTs withvalue_len=0.Explicitly NOT in scope:
--data-size-list 8:0(zero WEIGHT, item 10) is left for phase 3 (sampler safety). The zero-weight case is a sampler/loop issue, not an argv-range issue — fixing it cleanly belongs with the rest of the sampler-construction safety work.Caps chosen
--pipeline--data-sizeproto-max-bulk-len = 512mb; larger sizes the server would refuse anyway.--data-size-listentry sizeTest plan
Regression tests live in
tests/test_cli_validation_size.py. They invoke the binary directly viasubprocess— no Redis server needed — and check for non-zero exit + the expected error substring on stderr.--pipeline=-1rejected--pipeline=0rejected--pipeline=1025rejected (cap)--pipeline=2accepted (parses cleanly)--data-size=-1rejected--data-size=0rejected--data-size-list=0:50rejected--data-size-list=8:50,16:50accepted (parses cleanly)Run locally:
All 8 cases pass on this branch.
Refs #426
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Note
Low Risk
Changes are limited to argument validation and new CLI tests; no benchmark runtime or network behavior changes for valid inputs.
Overview
Phase 2b of #426 hardens argv parsing for size-related flags so bad values fail immediately with clear stderr messages instead of hanging or aborting during a run.
--pipelineand--data-sizenow reject leading-minus values viaoptarg_is_negative()(beforestrtoulcan turn-1into a huge unsigned), enforce > 0, and cap at 1024 and 512 MiB respectively.--data-size-listrejects entries with size 0 and applies the same per-entry size cap.New subprocess tests in
tests/test_cli_validation_size.pycover the three original #426 repros plus cap and “valid value parses” cases, with no Redis server required.Reviewed by Cursor Bugbot for commit 855c543. Bugbot is set up for automated code reviews on this repo. Configure here.