Skip to content

Commit 28adf07

Browse files
committed
Fix panic when string field occurs more than once
Also add test Thanks to `cargo fuzz` which revealed this problem
1 parent bb517a6 commit 28adf07

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Test when two messages are concatenated, singular fields are taken from the last one.
2+
3+
use super::test_singular_concat_pb::*;
4+
5+
use protobuf_test_common::*;
6+
7+
#[test]
8+
fn test_concat_bytes() {
9+
let mut m = TestSingularConcat::new();
10+
m.set_b(b"\xdd\xee".to_vec());
11+
12+
test_deserialize("12 03 aa bb cc 12 02 dd ee", &m);
13+
}
14+
15+
#[test]
16+
fn test_concat_string() {
17+
let mut m = TestSingularConcat::new();
18+
m.set_s("\x61\x62".to_string());
19+
20+
test_deserialize("0a 03 21 22 23 0a 02 61 62", &m);
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
syntax = "proto2";
2+
3+
package test_singular_concar;
4+
5+
message TestSingularConcat {
6+
optional string s = 1;
7+
optional bytes b = 2;
8+
}

protobuf/src/stream.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,7 @@ impl<'a> CodedInputStream<'a> {
701701
}
702702

703703
pub fn read_string_into(&mut self, target: &mut String) -> ProtobufResult<()> {
704-
// assert string is empty, otherwize UTF-8 validation is too expensive
705-
assert!(target.is_empty());
704+
target.clear();
706705
// take target's buffer
707706
let mut vec = mem::replace(target, String::new()).into_bytes();
708707
self.read_bytes_into(&mut vec)?;

0 commit comments

Comments
 (0)