From 67bf8183e4bfcd92feca363498bc9b0fe67437da Mon Sep 17 00:00:00 2001 From: Jinpeng Date: Thu, 12 Dec 2024 17:31:29 -0500 Subject: [PATCH] check overflow on reading field id --- lib/rs/src/protocol/compact.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rs/src/protocol/compact.rs b/lib/rs/src/protocol/compact.rs index c0c43722ed..1f597a4c72 100644 --- a/lib/rs/src/protocol/compact.rs +++ b/lib/rs/src/protocol/compact.rs @@ -186,7 +186,16 @@ where ), _ => { if field_delta != 0 { - self.last_read_field_id += field_delta as i16; + self.last_read_field_id = self + .last_read_field_id + .checked_add(field_delta as i16) + .ok_or(crate::Error::Protocol(crate::ProtocolError { + kind: crate::ProtocolErrorKind::InvalidData, + message: format!( + "invalid field delta {} for last field id {}", + field_delta, self.last_read_field_id + ), + }))?; } else { self.last_read_field_id = self.read_i16()?; };