-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: harden listpack checks in t_stream code #6440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR renames and enhances the listpack validation function in the Redis stream implementation, adding more comprehensive checks to detect corrupted listpacks earlier in stream operations.
Changes:
- Renamed
checkListPackNotEmptytocheckListPackValidto better reflect expanded validation scope - Added validation for corrupted listpack headers (zero-byte listpacks)
- Added validation using
lpValidateFirstandlpValidateNextto check listpack integrity - Applied the enhanced validation at three call sites in stream trimming and entry removal operations
src/redis/t_stream.c
Outdated
| fprintf(stderr, "Error: corrupted listpack header found."); | ||
| abort(); | ||
| } | ||
| p = lpValidateFirst(lp); | ||
| if(p[0] == 0xFF) { | ||
| fprintf(stderr, "Error: empty listpack found."); | ||
| abort(); | ||
| } | ||
|
|
||
| if (lpValidateNext(lp, &p, lpBytes(lp)) == 0) { | ||
| lpRepr(lp); | ||
| fprintf(stderr, "Error: corrupted listpack found."); |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline character in error message. The error messages should end with '\n' to ensure proper formatting when written to stderr. This applies to the error messages on lines 284, 289, and 295.
| fprintf(stderr, "Error: corrupted listpack header found."); | |
| abort(); | |
| } | |
| p = lpValidateFirst(lp); | |
| if(p[0] == 0xFF) { | |
| fprintf(stderr, "Error: empty listpack found."); | |
| abort(); | |
| } | |
| if (lpValidateNext(lp, &p, lpBytes(lp)) == 0) { | |
| lpRepr(lp); | |
| fprintf(stderr, "Error: corrupted listpack found."); | |
| fprintf(stderr, "Error: corrupted listpack header found.\n"); | |
| abort(); | |
| } | |
| p = lpValidateFirst(lp); | |
| if(p[0] == 0xFF) { | |
| fprintf(stderr, "Error: empty listpack found.\n"); | |
| abort(); | |
| } | |
| if (lpValidateNext(lp, &p, lpBytes(lp)) == 0) { | |
| lpRepr(lp); | |
| fprintf(stderr, "Error: corrupted listpack found.\n"); |
| if(lpBytes(lp) == 0) { | ||
| fprintf(stderr, "Error: corrupted listpack header found."); | ||
| abort(); | ||
| } | ||
| p = lpValidateFirst(lp); | ||
| if(p[0] == 0xFF) { | ||
| fprintf(stderr, "Error: empty listpack found."); | ||
| abort(); | ||
| } | ||
|
|
||
| if (lpValidateNext(lp, &p, lpBytes(lp)) == 0) { |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent code style: missing spaces after 'if' keyword. The code should follow consistent formatting with space after 'if', like 'if (' instead of 'if(' as seen on lines 283, 288, and 293.
🤖 Augment PR SummarySummary: Hardens stream listpack validation in 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Roman Gershman <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
| void checkListPackValid(unsigned char* lp) { | ||
| unsigned char* p = NULL; | ||
| if(lpBytes(lp) == 0) { | ||
| fprintf(stderr, "Error: corrupted listpack found."); | ||
| fprintf(stderr, "Error: corrupted listpack header found.\n"); | ||
| abort(); | ||
| } | ||
| p = lpValidateFirst(lp); | ||
| if(p == NULL) { | ||
| fprintf(stderr, "Error: empty listpack found.\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| if (lpValidateNext(lp, &p, lpBytes(lp)) == 0) { | ||
| lpRepr(lp); | ||
| fprintf(stderr, "Error: corrupted listpack found.\n"); | ||
| abort(); | ||
| } | ||
| } |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation logic only checks the first entry of the listpack, not the entire structure. After lpValidateFirst returns a pointer to the first element, lpValidateNext validates that element and advances the pointer to the next one, but doesn't continue validating subsequent entries. This means corrupted data in entries after the first one would not be detected. Consider validating all entries or at least a representative sample, similar to how streamValidateListpackIntegrity does it.
| void checkListPackValid(unsigned char* lp) { | ||
| unsigned char* p = NULL; | ||
| if(lpBytes(lp) == 0) { | ||
| fprintf(stderr, "Error: corrupted listpack found."); | ||
| fprintf(stderr, "Error: corrupted listpack header found.\n"); | ||
| abort(); | ||
| } | ||
| p = lpValidateFirst(lp); | ||
| if(p == NULL) { | ||
| fprintf(stderr, "Error: empty listpack found.\n"); | ||
| abort(); | ||
| } | ||
|
|
||
| if (lpValidateNext(lp, &p, lpBytes(lp)) == 0) { | ||
| lpRepr(lp); | ||
| fprintf(stderr, "Error: corrupted listpack found.\n"); | ||
| abort(); | ||
| } |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent code formatting: the function body uses 2-space indentation while the surrounding code uses 4-space indentation. Missing space after if keywords on lines 283 and 288 (should be if ( not if().
|
|
||
| void checkListPackNotEmpty(unsigned char* lp) { | ||
| void checkListPackValid(unsigned char* lp) { | ||
| unsigned char* p = NULL; |
Copilot
AI
Jan 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable p is initialized to NULL on line 282 but this initialization is unnecessary since it's immediately reassigned on line 287. Consider removing the initialization or declaring the variable where it's first assigned.
| unsigned char* p = NULL; | |
| unsigned char* p; |
|
I do not think we will need this PR |
No description provided.