Skip to content

Commit

Permalink
Update rmqamqpt_frame.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Evgeny Malygin <[email protected]>
  • Loading branch information
678098 authored and willhoy committed May 10, 2024
1 parent 33b39ce commit 32d8fb6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/rmq/rmqamqpt/rmqamqpt_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down

0 comments on commit 32d8fb6

Please sign in to comment.