-
Notifications
You must be signed in to change notification settings - Fork 77
Fix crash on dump command #440
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
base: master
Are you sure you want to change the base?
Fix crash on dump command #440
Conversation
Handle non-UTF-8 binary data by using StringBuffer variant instead of panicking on unwrap. Co-authored-by: gkorland <[email protected]>
…ions Apply the same graceful error handling pattern to BigNumber and VerbatimString to prevent potential panics. Co-authored-by: gkorland <[email protected]>
| ctx.call("SET", &["test_dump_key", "test_value"])?; | ||
|
|
||
| // Call DUMP which returns binary data (may not be valid UTF-8) | ||
| let dump_result = ctx.call("DUMP", &["test_dump_key"])?; |
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.
Which cases does this cover? Seems valid UTF-8 String. What about the other cases, e.g., BigNumber, etc.
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.
DUMP is always on key name which is string.
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.
OK, although "test_value" is valid UTF-8, the dumped serialized value is handled as String and when containing invalid UTF-8 content it was failing unwrap and is now properly handled as StringBuffer.
The BigNumber and VerbatimString cases are just defensive against currently unreachable code (or need some mock to reach it)
| fn test_call_dump() -> Result<()> { | ||
| let mut con = TestConnection::new("call"); | ||
|
|
||
| let res: String = redis::cmd("call.dump_test") |
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.
maybe we should pass a string we want it to send to us back?
I just would like to get coverage on the RedisValue::StaticError case.
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.
I wouldn't abuse this test to test and cover the StaticError and other error
| RedisValue::StringBuffer(data) => { | ||
| if data.is_empty() { | ||
| return Err(RedisError::Str("DUMP returned empty data")); | ||
| } |
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.
Can also assert that data is invalid UTF-8 (otherwise should be a SimpleString), e.g.,
assert!(std::str::from_utf8(&data).is_err(), "DUMP should return invalid UTF-8 data");
fix #439