|
5 | 5 | type Document, |
6 | 6 | type Long, |
7 | 7 | NumberUtils, |
8 | | - readInt32LE, |
9 | | - readUint32LE |
| 8 | + readInt32LE |
10 | 9 | } from '../bson'; |
11 | 10 | import { MongoInvalidArgumentError, MongoRuntimeError } from '../error'; |
12 | 11 | import { type ReadPreference } from '../read_preference'; |
@@ -576,6 +575,9 @@ export class OpMsgRequest { |
576 | 575 | NumberUtils.setInt32LE(header, 4, this.requestId); // requestID |
577 | 576 | NumberUtils.setInt32LE(header, 8, 0); // responseTo |
578 | 577 | NumberUtils.setInt32LE(header, 12, OP_MSG); // opCode |
| 578 | + // The OP_MSG spec calls out that flags is uint32: |
| 579 | + // https://github.com/mongodb/specifications/blob/master/source/message/OP_MSG.md#op_msg-1 |
| 580 | + // Flags are limited to only 16 bits, so it does not matter that we are using setInt32LE method. |
579 | 581 | NumberUtils.setInt32LE(header, 16, flags); // flags |
580 | 582 | return buffers; |
581 | 583 | } |
@@ -716,7 +718,9 @@ export class OpMsgResponse { |
716 | 718 | while (this.index < this.data.length) { |
717 | 719 | const payloadType = this.data[this.index++]; |
718 | 720 | if (payloadType === 0) { |
719 | | - const bsonSize = readUint32LE(this.data, this.index); |
| 721 | + // BSON spec specifies that this is a 32-bit signed integer: https://bsonspec.org/spec.html#:~:text=%3A%3A%3D-,int32,-e_list%20unsigned_byte(0 |
| 722 | + // Max BSON size is 16MB, which is well below 32-bit signed or unsigned limits, so we are choosing to read the value as Uint32 |
| 723 | + const bsonSize = readInt32LE(this.data, this.index); |
720 | 724 | const bin = this.data.subarray(this.index, this.index + bsonSize); |
721 | 725 |
|
722 | 726 | this.sections.push(bin); |
|
0 commit comments