diff --git a/third-party/thrift/src/thrift/lib/rust/Cargo.toml b/third-party/thrift/src/thrift/lib/rust/Cargo.toml index 1e9e619b66252a..3e85328b5b0e73 100644 --- a/third-party/thrift/src/thrift/lib/rust/Cargo.toml +++ b/third-party/thrift/src/thrift/lib/rust/Cargo.toml @@ -12,7 +12,7 @@ publish = false [dependencies] anyhow = "1.0.86" async-trait = "0.1.71" -base64 = "0.13" +base64 = "0.21" bufsize = "1.0.5" bytes = { version = "1.6.0", features = ["serde"] } futures = { version = "0.3.30", features = ["async-await", "compat"] } diff --git a/third-party/thrift/src/thrift/lib/rust/any/src/deserialize.rs b/third-party/thrift/src/thrift/lib/rust/any/src/deserialize.rs index 5ead3ef8819dc9..58f2e4b240e783 100644 --- a/third-party/thrift/src/thrift/lib/rust/any/src/deserialize.rs +++ b/third-party/thrift/src/thrift/lib/rust/any/src/deserialize.rs @@ -107,6 +107,11 @@ mod tests { use any::Any; use anyhow::anyhow; use anyhow::Result; + use base64::alphabet::STANDARD; + use base64::engine::general_purpose::GeneralPurpose; + use base64::engine::general_purpose::GeneralPurposeConfig; + use base64::engine::DecodePaddingMode; + use base64::Engine; use standard::StandardProtocol; use standard::TypeName; use standard::TypeUri; @@ -116,17 +121,23 @@ mod tests { use super::deserialize; use crate::AnyError; + // Bring back the pre 0.20 bevahiour and allow either padded or un-padded base64 strings at decode time. + const STANDARD_INDIFFERENT: GeneralPurpose = GeneralPurpose::new( + &STANDARD, + GeneralPurposeConfig::new().with_decode_padding_mode(DecodePaddingMode::Indifferent), + ); + fn make_test_any() -> Result { Ok(Any { r#type: Type { name: TypeName::structType(TypeUri::typeHashPrefixSha2_256( - base64::decode("e3AbYkUAP8FICiPtbGYI6w").unwrap(), + STANDARD_INDIFFERENT.decode("e3AbYkUAP8FICiPtbGYI6w").unwrap(), )), params: Vec::new(), ..Default::default() }, protocol: Protocol::standard(StandardProtocol::Compact), - data: base64::decode( + data: STANDARD_INDIFFERENT.decode( "GAozNjAwNjUwNzQ0GA5jb2d3aGVlbF90ZXN0cxwcHLwoENBU+E6zAHkpmP0Y3JboyaMAABkMABwVBAAYlgMZHBgNY29nd2hlZWxfdGVzdBkcGBIvbG9ncy90aHJpZnRfbW9ja3MYDHRocmlmdF9tb2NrczbAmgwAABwYjAJ7ImFsbF9zaWRlcyI6IFsiYSJdLCAicnBtX21hcCI6IHt9LCAiYnVuZGxlX3BhY2thZ2VfbWFwIjogeyJyY2VzZXJ2aWNlIjogImY4NDZjZjczNGM2YjQ3NDI5OTdiNDBjNTA2MWI1NmJhIiwgInR1cHBlcndhcmUuaW1hZ2Uud2ViZm91bmRhdGlvbi5jOS5yY2VzZXJ2aWNlIjogImZkNDZmN2VmMzQ0ZDYxNTIzMTdhODJlMzE4ZjZkMjk4In0sICJzZmlkIjogInJjZXNlcnZpY2Uvd3d3X2dlbmVyaWMiLCAiYnVuZGxlX2lkIjogODE4OCwgIm1pbm9yX2J1bmRsZV9pZCI6IDF9HBwSEgAcIRISHBIWAAAAHAAcJAIAHBglY29nd2hlZWxfcmNlc2VydmljZV90ZXN0X3Rlc3RfaGFybmVzcwAcAAAcGwAAABgAGwAAABIbABwAAA", )?, ..Default::default() diff --git a/third-party/thrift/src/thrift/lib/rust/any/src/thrift_any_type.rs b/third-party/thrift/src/thrift/lib/rust/any/src/thrift_any_type.rs index 4ee7f689d699c8..1d89beba757115 100644 --- a/third-party/thrift/src/thrift/lib/rust/any/src/thrift_any_type.rs +++ b/third-party/thrift/src/thrift/lib/rust/any/src/thrift_any_type.rs @@ -109,6 +109,11 @@ mod tests { use any::Any; use anyhow::anyhow; use anyhow::Result; + use base64::alphabet::STANDARD; + use base64::engine::general_purpose::GeneralPurpose; + use base64::engine::general_purpose::GeneralPurposeConfig; + use base64::engine::DecodePaddingMode; + use base64::Engine; use standard::TypeName; use standard::TypeUri; use type_::Type; @@ -118,13 +123,21 @@ mod tests { use crate::AnyError; use crate::AnyTypeExpectationViolated; + // Bring back the pre 0.20 bevahiour and allow either padded or un-padded base64 strings at decode time. + const STANDARD_INDIFFERENT: GeneralPurpose = GeneralPurpose::new( + &STANDARD, + GeneralPurposeConfig::new().with_decode_padding_mode(DecodePaddingMode::Indifferent), + ); + #[test] fn test_ensure_thrift_any_type_0() -> Result<()> { use artifact_builder_override::ExperimentOverrideRequestContext; let val = Any { r#type: Type { name: TypeName::structType(TypeUri::typeHashPrefixSha2_256( - base64::decode("e3AbYkUAP8FICiPtbGYI6w").unwrap(), + STANDARD_INDIFFERENT + .decode("e3AbYkUAP8FICiPtbGYI6w") + .unwrap(), )), ..Default::default() }, diff --git a/third-party/thrift/src/thrift/lib/rust/src/simplejson_protocol.rs b/third-party/thrift/src/thrift/lib/rust/src/simplejson_protocol.rs index d71d6ccf1ada3a..c963764149cf5c 100644 --- a/third-party/thrift/src/thrift/lib/rust/src/simplejson_protocol.rs +++ b/third-party/thrift/src/thrift/lib/rust/src/simplejson_protocol.rs @@ -20,6 +20,11 @@ use anyhow::anyhow; use anyhow::bail; use anyhow::Context; use anyhow::Result; +use base64::alphabet::STANDARD; +use base64::engine::general_purpose::GeneralPurpose; +use base64::engine::general_purpose::NO_PAD; +use base64::engine::DecodePaddingMode; +use base64::Engine; use bufsize::SizeCounter; use bytes::buf::Writer; use bytes::Buf; @@ -48,6 +53,12 @@ use crate::thrift_protocol::MessageType; use crate::thrift_protocol::ProtocolID; use crate::ttype::TType; +// Bring back the pre 0.20 bevahiour and allow either padded or un-padded base64 strings at decode time. +const STANDARD_NO_PAD_INDIFFERENT: GeneralPurpose = GeneralPurpose::new( + &STANDARD, + NO_PAD.with_decode_padding_mode(DecodePaddingMode::Indifferent), +); + #[phantom] #[derive(Copy, Clone)] pub struct SimpleJsonProtocol; @@ -349,10 +360,7 @@ impl ProtocolWriter for SimpleJsonProtocolSerializer { .begin_string(&mut self.buffer) .expect("Somehow failed to do \"io\" on a buffer"); CompactFormatter - .write_raw_fragment( - &mut self.buffer, - &base64::encode_config(value, base64::STANDARD_NO_PAD), - ) + .write_raw_fragment(&mut self.buffer, &STANDARD_NO_PAD_INDIFFERENT.encode(value)) .expect("Somehow failed to do \"io\" on a buffer"); CompactFormatter .end_string(&mut self.buffer) @@ -923,7 +931,8 @@ impl ProtocolReader for SimpleJsonProtocolDeserializer { None => bail!("Expected the string to continue"), } } - let bin = base64::decode_config(&ret, base64::STANDARD_NO_PAD) + let bin = STANDARD_NO_PAD_INDIFFERENT + .decode(&ret) .context("The `binary` data in JSON string does not contain valid base64")?; Ok(V::from_vec(bin)) }