Skip to content

Commit

Permalink
THRIFT-5131: Require >= 1.1.4 of integer-encoding dependency
Browse files Browse the repository at this point in the history
Client: Rust
Patch: Nik Clayton

This closes apache#2045

Versions 1.1.0 - 1.1.3 of the integer-encoding crate had a bug where
numbers larger than 0x4000_0000_0000_0000 would cause a panic during
decoding.

Add a test to be sure that numbers up to i64::maxvalue() encode and
decode successfully.
  • Loading branch information
nikclayton-dfinity authored and Jens-G committed Mar 7, 2020
1 parent 1b7b00c commit e791760
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ keywords = ["thrift"]
[dependencies]
ordered-float = "1.0"
byteorder = "1.3"
integer-encoding = "1.0"
integer-encoding = ">=1.1.4" # https://issues.apache.org/jira/browse/THRIFT-5131
log = "0.4"
threadpool = "1.7"
25 changes: 25 additions & 0 deletions lib/rs/src/protocol/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,31 @@ mod tests {
assert_eq_written_bytes!(o_prot, expected);
}

#[test]
fn must_round_trip_upto_i64_maxvalue() {
// See https://issues.apache.org/jira/browse/THRIFT-5131
for i in 0..64 {
let (mut i_prot, mut o_prot) = test_objects();
let val: i64 = ((1u64 << i) - 1) as i64;

o_prot
.write_field_begin(&TFieldIdentifier::new(
"val",
TType::I64,
1
))
.unwrap();
o_prot.write_i64(val).unwrap();
o_prot.write_field_end().unwrap();
o_prot.flush().unwrap();

copy_write_buffer_to_read_buffer!(o_prot);

i_prot.read_field_begin().unwrap();
assert_eq!(val, i_prot.read_i64().unwrap());
}
}

#[test]
fn must_round_trip_message_begin() {
let (mut i_prot, mut o_prot) = test_objects();
Expand Down

0 comments on commit e791760

Please sign in to comment.