Fix LLP64 bulk length truncation in processBulkItem (#1333) - #1334
Open
LL-V wants to merge 1 commit into
Open
Conversation
On Windows x64, unsigned long is 32-bit while bulk length is long long. Adding len into unsigned long bytelen could wrap so an incomplete bulk was treated as complete (see redis#1333). Use size_t for header/item lengths, reject lengths that cannot fit in size_t, and check overflow before the completeness test.
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
Fixes #1333.
On LLP64 (Windows x64),
processBulkItemaccumulated bulk size inunsigned long, which can wrap when adding a largelong longlength so an incomplete bulk is treated as complete.Changes
size_tfor header/item lengthssize_ton all platformsTest plan
$4294967296\r\nABno longer calls createString with len=2^32Note
Medium Risk
Touches core RESP bulk parsing used for every
$reply; fixes a real truncation/early-parse issue but behavior changes for out-of-range lengths (now protocol errors instead of silent wrap).Overview
Fixes a protocol parsing bug in
processBulkItemwhere bulk sizes were accumulated inunsigned long, which on LLP64 (Windows x64) could wrap for large declared lengths and treat an incomplete bulk as fully received (e.g. wrongcreateStringlength).The reader now tracks header and total item size in
size_t, rejects bulk lengths that cannot fit insize_ton all platforms (replacing a guard that failed whensize_tis 64-bit), overflow-checkshdrlen + len + CRLFbefore testing buffer completeness, and advancesr->posvia the computeditemlen. Nil bulks setitemlenfrom the header only;createStringgets(size_t)len.Reviewed by Cursor Bugbot for commit 48ad634. Bugbot is set up for automated code reviews on this repo. Configure here.