Repository navigation
fix(monitor-input): preserve byte count past NUL; handle CR-only line endings - #434
Merged
Merged
Conversation
… endings load_from_file built std::string from the line via the C-string ctor, silently truncating at the first embedded \0 byte in binary blobs. getline used \n only, so classic-Mac \r-only files collapsed into one giant line and dropped commands silently. Neither path crashed; both lost data without surfacing. - std::string ctor takes (first_quote, line+line_len-first_quote) - Replace strchr with memchr so NUL bytes before the first '"' are skipped correctly when locating the command start - Normalise \r-only line endings before tokenising Refs: 2.4 review finding #30 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
fcostaoliveira
added a commit
to filipecosta90/memtier_benchmark
that referenced
this pull request
Jun 2, 2026
Resolve conflicts after redis#432/redis#434/redis#435 landed on master. Conflict in memtier_benchmark.cpp: adopt master's "must be a positive integer" wording (standardized by redis#432) for the four negative-value guard fprintf() calls added by this branch; both sides trigger on the same code path and the test assertions only check the prefix, so either wording is functionally correct.
fcostaoliveira
added a commit
that referenced
this pull request
Jun 2, 2026
…ownstream NUL issue) (#441) * docs(monitor-input): code comment + README note on NUL/CR-only fixes Follow-up to PR #434: add an inline comment explaining the memchr choice, README paragraphs documenting the 2.4 capability changes (binary payloads preserved, CR-only line endings supported), and a code comment near the arbitrary_command ctor flagging that downstream c_str() still truncates at embedded NULs (filed as separate follow-up issue for the load-bearing fix). Refs: 2.4 review #38 (Review 14 R3 + R6). Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * docs(monitor-input): qualify "end-to-end" claim; trim ctor comment Reviewers caught that the README's "preserved end-to-end" wording overstated the fix -- the code comments in the same PR document that downstream c_str() re-truncates at the first NUL. Re-worded the README to match the actual scope (loader preserves; dispatch re-truncates, tracked as #439). Also trimmed the verbose ctor comment. Refs: PR #441 reviewers R1+R4+R6. --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]>
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
Two silent data-loss bugs in
monitor_command_list::load_from_file(config_types.cpp), found during 2.4 release review (finding #30).Bug F1 — NUL truncation (strchr → memchr)
strchr(line, '"')stops at the first\0byte. A MONITOR capture whose metadata prefix contains an embedded NUL causes the line to be silently skipped —first_quotebecomes NULL even though getline returned the full byte count with the"CMD"portion intact. Fix: replacestrchrwithmemchr(seg_start, '"', seg_len)so the search spans exactly the bytes returned bygetline.Additionally,
std::string command_str(first_quote)used the C-string constructor which truncates at the first\0in the command part. Fix: usestd::string command_str(first_quote, cmd_len)with the explicit byte count.Bug F2 — CR-only line endings
getlineuses\nas its sole delimiter. A file with pure\rseparators (classic Mac / some Windows exports) is read as one giant line; the metadata of every line after the first is appended as extra tokens to the first command — most commands are silently dropped. Fix: a pre-pass normalises bare\r→\nwithin the buffer before segment processing.Neither path crashed; both lost data without surfacing.
Changes
config_types.cpp(load_from_file): CR normalisation pass + inner segment loop +memchr+ explicitstd::string(ptr, len)constructor.tests/test_monitor_input.py: two new regression tests:test_monitor_input_nul_byte_in_prefix_not_truncated— binary monitor file with\x00in line 2's metadata prefix; asserts all 3 commands are loaded.test_monitor_input_cr_only_line_endings— binary monitor file with\r-only separators; asserts all 3 commands are loaded and all 3 keys land in Redis.Test plan
make -j$(nproc)— clean build, no new warnings.make format-check-staged— clang-format clean (verified locally).tests/test_monitor_input.pytests pass unmodified (no behaviour change on normal\n-delimited files).test_monitor_input_nul_byte_in_prefix_not_truncated— fails on old code (count = 2), passes on fixed code (count = 3).test_monitor_input_cr_only_line_endings— fails on old code (count = 1 or parse error), passes on fixed code (count = 3, all 3 keys in Redis).Refs: 2.4 review finding #30
🤖 Generated with Claude Code
Note
Low Risk
Scoped to monitor capture parsing in config_types.cpp with targeted regression tests; normal newline-delimited files should behave the same.
Overview
Fixes silent data loss when loading
--monitor-inputcapture files inmonitor_command_list::load_from_file(config_types.cpp).NUL in metadata: Locating the command with
strchrand buildingstd::stringfrom a C string could stop at embedded\0bytes in the prefix, so valid lines were skipped. The loader now splits eachgetlinebuffer into segments, finds"withmemchrover a bounded length, and copies commands withstd::string(ptr, len)so NULs in the payload are preserved.CR-only line endings: Bare
\rseparators (no\n) used to be one physical line; the code normalizes internal\r→\nand processes each segment so every MONITOR record becomes its own command.tests/test_monitor_input.pyadds regression tests for NUL-in-prefix (expects 3 loaded commands) and CR-only files (3 commands + keys in Redis).Reviewed by Cursor Bugbot for commit b65c605. Bugbot is set up for automated code reviews on this repo. Configure here.