You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2020/03/07 10:15:45 UTC

[thrift] 01/02: THRIFT-5131: Require >= 1.1.4 of integer-encoding dependency Client: Rust Patch: Nik Clayton

This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git

commit e791760098b6a9490e19af2b18a3e002f561973b
Author: Nik Clayton <ni...@dfinity.org>
AuthorDate: Thu Mar 5 11:51:15 2020 +0100

    THRIFT-5131: Require >= 1.1.4 of integer-encoding dependency
    Client: Rust
    Patch: Nik Clayton
    
    This closes #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.
---
 lib/rs/Cargo.toml              |  2 +-
 lib/rs/src/protocol/compact.rs | 25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/lib/rs/Cargo.toml b/lib/rs/Cargo.toml
index 0c71bab..0626da8 100644
--- a/lib/rs/Cargo.toml
+++ b/lib/rs/Cargo.toml
@@ -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"
diff --git a/lib/rs/src/protocol/compact.rs b/lib/rs/src/protocol/compact.rs
index 3e17398..029f850 100644
--- a/lib/rs/src/protocol/compact.rs
+++ b/lib/rs/src/protocol/compact.rs
@@ -715,6 +715,31 @@ mod tests {
     }
 
     #[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();