From 70636703d776a8c0f29fb7b4a16ab8a905874034 Mon Sep 17 00:00:00 2001 From: jthomson04 Date: Thu, 14 Aug 2025 11:16:36 -0700 Subject: [PATCH 1/2] only do checksums on debug builds Signed-off-by: jthomson04 --- .../src/pipeline/network/codec/two_part.rs | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/runtime/src/pipeline/network/codec/two_part.rs b/lib/runtime/src/pipeline/network/codec/two_part.rs index e51819c392..bb99768dff 100644 --- a/lib/runtime/src/pipeline/network/codec/two_part.rs +++ b/lib/runtime/src/pipeline/network/codec/two_part.rs @@ -84,13 +84,20 @@ impl Decoder for TwoPartCodec { // Advance the buffer past the lengths and checksum src.advance(24); - let bytes_to_hash = header_len + body_len; - let data_to_hash = &src[..bytes_to_hash]; - let computed_checksum = xxh3_64(data_to_hash); - - // Compare checksums - if checksum != computed_checksum { - return Err(TwoPartCodecError::ChecksumMismatch); + #[cfg(debug_assertions)] + { + // If the server sent a dummy checksum, skip it. + if checksum != 0 { + let bytes_to_hash = header_len + body_len; + let data_to_hash = &src[..bytes_to_hash]; + + let computed_checksum = xxh3_64(data_to_hash); + + // Compare checksums + if checksum != computed_checksum { + return Err(TwoPartCodecError::ChecksumMismatch); + } + } } // Read header and body data @@ -117,16 +124,25 @@ impl Encoder for TwoPartCodec { } } - // Compute checksum of the data - let mut data_to_hash = BytesMut::with_capacity(header_len + body_len); - data_to_hash.extend_from_slice(&item.header); - data_to_hash.extend_from_slice(&item.data); - let checksum = xxh3_64(&data_to_hash); - - // Write header and body sizes and checksum dst.put_u64(header_len as u64); dst.put_u64(body_len as u64); - dst.put_u64(checksum); + + // Only compute the checksum in debug mode. + // If we're in release mode, put a dummy value. + #[cfg(debug_assertions)] + { + // Compute checksum of the data + let mut data_to_hash = BytesMut::with_capacity(header_len + body_len); + data_to_hash.extend_from_slice(&item.header); + data_to_hash.extend_from_slice(&item.data); + let checksum = xxh3_64(&data_to_hash); + + dst.put_u64(checksum); + } + #[cfg(not(debug_assertions))] + { + dst.put_u64(0); + } // Write header and body dst.put_slice(&item.header); From d91c1f02b2cb14d3d375036fffe6878bcd30a7e8 Mon Sep 17 00:00:00 2001 From: jthomson04 Date: Thu, 14 Aug 2025 13:11:03 -0700 Subject: [PATCH 2/2] Appease the coderabbit Signed-off-by: jthomson04 --- lib/runtime/src/pipeline/network/codec/two_part.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/runtime/src/pipeline/network/codec/two_part.rs b/lib/runtime/src/pipeline/network/codec/two_part.rs index bb99768dff..2ef7996c5d 100644 --- a/lib/runtime/src/pipeline/network/codec/two_part.rs +++ b/lib/runtime/src/pipeline/network/codec/two_part.rs @@ -88,7 +88,13 @@ impl Decoder for TwoPartCodec { { // If the server sent a dummy checksum, skip it. if checksum != 0 { - let bytes_to_hash = header_len + body_len; + let bytes_to_hash = + header_len + .checked_add(body_len) + .ok_or(TwoPartCodecError::InvalidMessage( + "Message exceeds max allowed length.".to_string(), + ))?; + let data_to_hash = &src[..bytes_to_hash]; let computed_checksum = xxh3_64(data_to_hash);