Skip to content
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

Fix string verbatim reply to work correctly. #315

Merged
merged 11 commits into from
Apr 27, 2023

Conversation

MeirShpilraien
Copy link
Collaborator

Current behaviour is to append to format to the data. This is wrong because the format need to pass separately to Redis. Also, a wrong RedisModuleAPI was used, we need to use the API that allows to pass the format (otherwise Redis uses the default txt format).

src/context/mod.rs Outdated Show resolved Hide resolved
src/context/mod.rs Outdated Show resolved Hide resolved
src/redisvalue.rs Outdated Show resolved Hide resolved
Comment on lines 543 to 550
let mut res = VerbatimStringFormat::default();
value
.chars()
.into_iter()
.take(3)
.enumerate()
.for_each(|(i, c)| res.0[i] = c as c_char);
res
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few doubts about this. So, the value is guaranteed to be a valid UTF-8 string, which means it also may contain some ASCII symbols inside. However, when we do c as c_char within the for_each, we don't check if the symbol converted was an ASCII symbol. The "valid" symbol table for ASCII ends at the 127th (half-byte) symbol, and after that, there is the extended table which varies, and we shouldn't rely on it. As we convert a char of variable byte-width to a c_char of the constant length of 1 byte, we don't check that the actual value is correct. What should we do if the format string contains a non-valid ASCII-table symbol (the symbol with code > 127)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do you suggested to change the From into TryFrom and verify that the value is less eq 127?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice, yes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vityafx done

iddm
iddm previously approved these changes Apr 27, 2023
fn try_from(value: &str) -> Result<Self, Self::Error> {
if value.len() != 3 {
return Err(RedisError::String(
"Verbatim format len must be 3".to_owned(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is already a String, it can as well be a formatted string with the value we have:

format!("Verbatim format length must be {VERBATIM_FORMAT_LENGTH}.")

@MeirShpilraien MeirShpilraien merged commit 6c0ad12 into master Apr 27, 2023
@MeirShpilraien MeirShpilraien deleted the fix_verbatim_string_reply branch April 27, 2023 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants