-
Notifications
You must be signed in to change notification settings - Fork 382
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 compute_size(value: &i32) for negative number #372
Conversation
005159f
to
8f13250
Compare
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.
Wow! That is a significant bug. Thank you for pinning it down!
I've requested a couple of minor fixes inline, can you please do it, or I will do them myself a bit later.
@@ -22,6 +22,19 @@ fn test_map() { | |||
test_serialize_deserialize_no_hex(&map); | |||
} | |||
|
|||
#[test] | |||
fn test_map_negative_int() { |
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.
test_map_negative_i32_value
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.
updated
fn test_map_negative_int() { | ||
let mut map = TestMap::new(); | ||
let mut entry = TestMapEntry::new(); | ||
entry.set_v(10); |
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.
Seems to be not used anywhere.
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.
cleaned up
// See also: https://github.com/protocolbuffers/protobuf/blob/bd00671b924310c0353a730bf8fa77c44e0a9c72/src/google/protobuf/io/coded_stream.h#L1300-L1306 | ||
if *value < 0 { | ||
return 10 | ||
} |
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.
A side note: length computation logic is duplicated between this function and call to i32::len_varint()
. That code needs clean up (deduplication), but it may be not trivial, and I will do it later.
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.
👌
protobuf/src/stream.rs
Outdated
@@ -790,14 +790,14 @@ impl<'a> CodedOutputStream<'a> { | |||
self.position = 0; | |||
}, | |||
OutputTarget::Bytes => { | |||
panic!("refresh_buffer must not be called on CodedOutputStream create from slice"); |
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 you please split the patch into changes of logic and typo fixes? I appreciate doc fixes, and if you can't do it, I'll split the patch myself.
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.
changes moved here: #375
Updated 😄 |
Published versions 2.2.4, 2.1.5, 2.0.6 with fixes. Thank you! |
See also: https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/io/coded_stream.h#L1300-L1306
Output verified by