Skip to content

Commit ad9e2aa

Browse files
committed
pr feedback
1 parent 58739b6 commit ad9e2aa

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

src/bson.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ export const readInt32LE = (buffer: Uint8Array, offset: number): number => {
5555
return NumberUtils.getInt32LE(buffer, offset);
5656
};
5757

58-
// readUint32LE, reads a 32-bit unsigned integer from buffer at given offset
59-
// throws if offset is out of bounds
60-
export const readUint32LE = (buffer: Uint8Array, offset: number): number => {
61-
validateBufferInputs(buffer, offset, 4);
62-
return NumberUtils.getUint32LE(buffer, offset);
63-
};
64-
6558
/**
6659
* BSON Serialization options.
6760
* @public

src/cmap/commands.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55
type Document,
66
type Long,
77
NumberUtils,
8-
readInt32LE,
9-
readUint32LE
8+
readInt32LE
109
} from '../bson';
1110
import { MongoInvalidArgumentError, MongoRuntimeError } from '../error';
1211
import { type ReadPreference } from '../read_preference';
@@ -576,6 +575,9 @@ export class OpMsgRequest {
576575
NumberUtils.setInt32LE(header, 4, this.requestId); // requestID
577576
NumberUtils.setInt32LE(header, 8, 0); // responseTo
578577
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.
579581
NumberUtils.setInt32LE(header, 16, flags); // flags
580582
return buffers;
581583
}
@@ -716,7 +718,9 @@ export class OpMsgResponse {
716718
while (this.index < this.data.length) {
717719
const payloadType = this.data[this.index++];
718720
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);
720724
const bin = this.data.subarray(this.index, this.index + bsonSize);
721725

722726
this.sections.push(bin);

0 commit comments

Comments
 (0)