@@ -3388,10 +3388,24 @@ _mongoc_cluster_run_opmsg_recv (
3388
3388
_mongoc_buffer_init (& buffer , decompressed_data , decompressed_data_len , NULL , NULL );
3389
3389
}
3390
3390
3391
- bson_t body ;
3391
+ // CDRIVER-5584
3392
+ {
3393
+ const int32_t op_code = mcd_rpc_header_get_op_code (rpc );
3392
3394
3393
- uint32_t op_msg_flags = mcd_rpc_op_msg_get_flag_bits (rpc );
3394
- cluster -> client -> in_exhaust = op_msg_flags & MONGOC_OP_MSG_FLAG_MORE_TO_COME ;
3395
+ if (op_code != MONGOC_OP_CODE_MSG ) {
3396
+ RUN_CMD_ERR (MONGOC_ERROR_PROTOCOL ,
3397
+ MONGOC_ERROR_PROTOCOL_INVALID_REPLY ,
3398
+ "malformed message from server: expected opCode %" PRId32 ", got %" PRId32 ,
3399
+ MONGOC_OP_CODE_MSG ,
3400
+ op_code );
3401
+ _handle_network_error (cluster , server_stream , error );
3402
+ server_stream -> stream = NULL ;
3403
+ network_error_reply (reply , cmd );
3404
+ goto done ;
3405
+ }
3406
+ }
3407
+
3408
+ bson_t body ;
3395
3409
3396
3410
if (!mcd_rpc_message_get_body (rpc , & body )) {
3397
3411
RUN_CMD_ERR (MONGOC_ERROR_PROTOCOL , MONGOC_ERROR_PROTOCOL_INVALID_REPLY , "malformed message from server" );
@@ -3401,6 +3415,7 @@ _mongoc_cluster_run_opmsg_recv (
3401
3415
goto done ;
3402
3416
}
3403
3417
3418
+ cluster -> client -> in_exhaust = (mcd_rpc_op_msg_get_flag_bits (rpc ) & MONGOC_OP_MSG_FLAG_MORE_TO_COME ) != 0u ;
3404
3419
_mongoc_topology_update_cluster_time (cluster -> client -> topology , & body );
3405
3420
3406
3421
ret = _mongoc_cmd_check_ok (& body , cluster -> client -> error_api_version , error );
0 commit comments