Validate replication RDB bulk lengths - #29
Draft
roshkhatri wants to merge 1 commit into
Draft
Conversation
roshkhatri
force-pushed
the
replication-bulk-length
branch
from
August 11, 2026 19:26
36d7edb to
c5a527f
Compare
Signed-off-by: Roshan Khatri <roshanvkhatri@gmail.com>
roshkhatri
force-pushed
the
replication-bulk-length
branch
from
August 11, 2026 20:12
c5a527f to
d0f089e
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
Validates the RDB bulk-length metadata a replica receives from a primary before starting a full synchronization transfer, and keeps the transfer boundary intact on 32-bit builds.
Findings
strtol. A negative value such as$-1, signed overflow, or trailing garbage could reach later replication paths as a transfer size. In diskless loading this could trigger a server assertion and terminate the replica.strlenon a buffer whose real length was already known, so a NUL byte could hide the rest of the line.$1\0garbagewas accepted as$1and the replica proceeded to load an RDB.$0was accepted as a size-based length, but 0 is how this code represents an EOF-delimited transfer. Withusemarkfalse, disk-based sync retries zero-byte reads and diskless sync passes a zero read limit to RIO, which RIO treats as unlimited.off_t(64-bit) but was passed torioInitWithConn()assize_t. On 32-bit builds 2^32 narrows to 0, which again means unlimited, so the declared boundary disappeared. The RIO limit arithmetic could also overflow.Fix
string2llusing the known length, and reject negative, zero, overflowed, and trailing-garbage values.uint64_t, and phrase the limit checks as subtraction so they cannot wrap.Compatibility
No DUMP or RDB format change and no wire protocol change. Real primaries send canonical decimal lengths, so ordinary replication including across versions is unaffected. A custom primary sending
$+1,$01, or a length with stray whitespace will now fail the sync.Validation
integration/replicationsuite: 77 passed.$-1,$0, signed overflow, trailing garbage, embedded NUL, a valid control, and the 2^32 boundary.$0cases fail there, the latter by hanging the replica rather than rejecting.git diff --checkand clang-format 18 source checks passed.build-32bitbut no 32-bit test run, and-m32was unavailable locally.Draft in the fork for manual security review and backport assessment.