Skip to content

Commit

Permalink
Update buffer position when returning kIgnored (#1760)
Browse files Browse the repository at this point in the history
Summary: This PR removes the frame's contents from the buffer in the
case we return `kIgnored` when the frame is a type (opcode) we do not
parse. When running the BPF test we noticed that the program would stall
when the parser encountered a frame with an opcode it does not support.
This was due to to the parser returning `kIgnored` to `ParseFramesLoop`
and it not moving the buffer forward before calling `ParseFrame` again.
This change will update the buffer position before returning `kIgnored`
to `ParseFramesLoop` so that the remaining frames in the buffer can be
parsed.

Related issues: #640

Type of change: /kind bug

Test Plan: Modified the existing test checking for the unsupported
opcode type.


Signed-off-by: Kartik Pattaswamy <[email protected]>
  • Loading branch information
kpattaswamy authored Nov 6, 2023
1 parent e6bfab7 commit 62b8080
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ ParseState ParseFrame(message_type_t type, std::string_view* buf, Frame* frame,
return ParseState::kInvalid;
}

// Parser will ignore Op Codes that have been deprecated/removed from version 5.0 onwards.
if (!(frame_type == Type::kOPMsg || frame_type == Type::kOPCompressed ||
frame_type == Type::kReserved)) {
// Parser will ignore Op Codes that have been deprecated/removed from version 5.0 onwards as well
// as kOPCompressed and kReserved which are not supported by the parser yet.
if (frame_type != Type::kOPMsg) {
buf->remove_prefix(frame->length);
return ParseState::kIgnored;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ TEST_F(MongoDBParserTest, ParseFrameWhenUnsupportedType) {
ParseState state = ParseFrame(message_type_t::kRequest, &frame_view, &frame, &state_order);

EXPECT_EQ(state, ParseState::kIgnored);
EXPECT_EQ(frame_view.length(), 0);
}

TEST_F(MongoDBParserTest, ParseFrameInvalidFlagBits) {
Expand Down

0 comments on commit 62b8080

Please sign in to comment.