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 compute_size(value: &i32) for negative number #372

Merged
merged 1 commit into from Jan 13, 2019

Conversation

king6cong
Copy link
Contributor

@king6cong king6cong commented Jan 8, 2019

See also: https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/io/coded_stream.h#L1300-L1306

Output verified by

protoc -I proto -I protobuf-test/src/common/v2 --decode TestMap < output.bin

@king6cong king6cong changed the title Fix compute_size(value: &i32) and add test for negtive value Fix compute_size(value: &i32) for negtive values Jan 8, 2019
@king6cong king6cong changed the title Fix compute_size(value: &i32) for negtive values Fix compute_size(value: &i32) for negative number Jan 8, 2019
@king6cong king6cong force-pushed the master branch 2 times, most recently from 005159f to 8f13250 Compare January 9, 2019 02:58
Copy link
Owner

@stepancheg stepancheg left a 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() {
Copy link
Owner

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

Copy link
Contributor Author

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);
Copy link
Owner

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.

Copy link
Contributor Author

@king6cong king6cong Jan 9, 2019

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
}
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌

@@ -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");
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changes moved here: #375

@king6cong
Copy link
Contributor Author

Updated 😄

@stepancheg stepancheg merged commit c023b9a into stepancheg:master Jan 13, 2019
@stepancheg
Copy link
Owner

stepancheg commented Jan 13, 2019

Published versions 2.2.4, 2.1.5, 2.0.6 with fixes.

Thank you!

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.

None yet

2 participants