From cbfb25d36823708cecbcbc9c681557b88feb5fba Mon Sep 17 00:00:00 2001 From: Katherine Walker Date: Thu, 17 May 2018 15:23:06 -0400 Subject: [PATCH] fix(binary): add type checking for buffer --- lib/bson/binary.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/bson/binary.js b/lib/bson/binary.js index b1ccccef..26351917 100644 --- a/lib/bson/binary.js +++ b/lib/bson/binary.js @@ -30,6 +30,16 @@ if (typeof global !== 'undefined') { function Binary(buffer, subType) { if (!(this instanceof Binary)) return new Binary(buffer, subType); + if ( + buffer != null && + !(typeof buffer === 'string') && + !Buffer.isBuffer(buffer) && + !(buffer instanceof Uint8Array) && + !Array.isArray(buffer) + ) { + throw new Error('only String, Buffer, Uint8Array or Array accepted'); + } + this._bsontype = 'Binary'; if (buffer instanceof Number) {