From 32d8fb641f4862534ba10fb9de90a24a29a7ac33 Mon Sep 17 00:00:00 2001 From: Evgeny Malygin Date: Thu, 30 Nov 2023 13:22:19 +0000 Subject: [PATCH] Update rmqamqpt_frame.cpp Signed-off-by: Evgeny Malygin --- src/rmq/rmqamqpt/rmqamqpt_frame.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/rmq/rmqamqpt/rmqamqpt_frame.cpp b/src/rmq/rmqamqpt/rmqamqpt_frame.cpp index 8fd7f74..55ce6a8 100644 --- a/src/rmq/rmqamqpt/rmqamqpt_frame.cpp +++ b/src/rmq/rmqamqpt/rmqamqpt_frame.cpp @@ -66,19 +66,21 @@ Frame::ReturnCode Frame::decode(Frame* frame, return Frame::PARTIAL; } - bsl::memcpy(&frame->d_type, &buffer[0], sizeof(frame->d_type)); - - bdlb::BigEndianUint16 channel; - bsl::memcpy(&channel, &buffer[1], sizeof(channel)); - frame->d_channel = channel; - + // Decode payload length first to return early if Frame is not full. bdlb::BigEndianUint32 payloadLength; bsl::memcpy(&payloadLength, &buffer[3], sizeof(payloadLength)); - if ((frameOverhead() + payloadLength) > bufferLen) { + if (bufferLen < (frameOverhead() + payloadLength)) { return Frame::PARTIAL; } + // Finally decode the skipped parts of the header. + bsl::memcpy(&frame->d_type, &buffer[0], sizeof(frame->d_type)); + + bdlb::BigEndianUint16 channel; + bsl::memcpy(&channel, &buffer[1], sizeof(channel)); + frame->d_channel = channel; + bsl::size_t buffer_len = frameHeaderSize() + payloadLength; if (buffer[buffer_len] != Constants::FRAME_END) { BALL_LOG_ERROR << "Decode error: expected Frame End marker. Frame: "