Skip to content

Commit cbfb25d

Browse files
kvwalkerdaprahamian
authored andcommitted
fix(binary): add type checking for buffer
1 parent 00a7f57 commit cbfb25d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/bson/binary.js

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ if (typeof global !== 'undefined') {
3030
function Binary(buffer, subType) {
3131
if (!(this instanceof Binary)) return new Binary(buffer, subType);
3232

33+
if (
34+
buffer != null &&
35+
!(typeof buffer === 'string') &&
36+
!Buffer.isBuffer(buffer) &&
37+
!(buffer instanceof Uint8Array) &&
38+
!Array.isArray(buffer)
39+
) {
40+
throw new Error('only String, Buffer, Uint8Array or Array accepted');
41+
}
42+
3343
this._bsontype = 'Binary';
3444

3545
if (buffer instanceof Number) {

0 commit comments

Comments
 (0)