|
5 | 5 | type Document, |
6 | 6 | type Long, |
7 | 7 | NumberUtils, |
8 | | - readInt32LE |
| 8 | + readInt32LE, |
| 9 | + setUint32LE |
9 | 10 | } from '../bson'; |
10 | 11 | import { MongoInvalidArgumentError, MongoRuntimeError } from '../error'; |
11 | 12 | import { type ReadPreference } from '../read_preference'; |
@@ -577,8 +578,7 @@ export class OpMsgRequest { |
577 | 578 | NumberUtils.setInt32LE(header, 12, OP_MSG); // opCode |
578 | 579 | // The OP_MSG spec calls out that flags is uint32: |
579 | 580 | // 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. |
581 | | - NumberUtils.setInt32LE(header, 16, flags); // flags |
| 581 | + setUint32LE(header, 16, flags); // flags |
582 | 582 | return buffers; |
583 | 583 | } |
584 | 584 |
|
@@ -719,7 +719,8 @@ export class OpMsgResponse { |
719 | 719 | const payloadType = this.data[this.index++]; |
720 | 720 | if (payloadType === 0) { |
721 | 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 |
| 722 | + // While allowing negative sizes seems odd, in practice we never expect a negative size. Also, the server's 16mb limit for BSON documents leaves plenty |
| 723 | + // of room in an int32 to store a document of the max BSON size that the server supports |
723 | 724 | const bsonSize = readInt32LE(this.data, this.index); |
724 | 725 | const bin = this.data.subarray(this.index, this.index + bsonSize); |
725 | 726 |
|
|
0 commit comments