diff --git a/lib/bson/binary.js b/lib/bson/binary.js index 279423e0..f3f695da 100644 --- a/lib/bson/binary.js +++ b/lib/bson/binary.js @@ -28,6 +28,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) {