@@ -264,8 +264,8 @@ function deserializeObject(
264
264
value = ByteUtils . toUTF8 ( buffer , index , index + stringSize - 1 , shouldValidateKey ) ;
265
265
index = index + stringSize ;
266
266
} else if ( elementType === constants . BSON_DATA_OID ) {
267
- const oid = ByteUtils . allocate ( 12 ) ;
268
- oid . set ( buffer . subarray ( index , index + 12 ) ) ;
267
+ const oid = ByteUtils . allocateUnsafe ( 12 ) ;
268
+ for ( let i = 0 ; i < 12 ; i ++ ) oid [ i ] = buffer [ index + i ] ;
269
269
value = new ObjectId ( oid ) ;
270
270
index = index + 12 ;
271
271
} else if ( elementType === constants . BSON_DATA_INT && promoteValues === false ) {
@@ -355,9 +355,9 @@ function deserializeObject(
355
355
}
356
356
} else if ( elementType === constants . BSON_DATA_DECIMAL128 ) {
357
357
// Buffer to contain the decimal bytes
358
- const bytes = ByteUtils . allocate ( 16 ) ;
358
+ const bytes = ByteUtils . allocateUnsafe ( 16 ) ;
359
359
// Copy the next 16 bytes into the bytes buffer
360
- bytes . set ( buffer . subarray ( index , index + 16 ) , 0 ) ;
360
+ for ( let i = 0 ; i < 16 ; i ++ ) bytes [ i ] = buffer [ index + i ] ;
361
361
// Update index
362
362
index = index + 16 ;
363
363
// Assign the new Decimal128 value
@@ -398,7 +398,6 @@ function deserializeObject(
398
398
}
399
399
}
400
400
} else {
401
- const _buffer = ByteUtils . allocate ( binarySize ) ;
402
401
// If we have subtype 2 skip the 4 bytes for the size
403
402
if ( subType === Binary . SUBTYPE_BYTE_ARRAY ) {
404
403
binarySize = NumberUtils . getInt32LE ( buffer , index ) ;
@@ -411,13 +410,12 @@ function deserializeObject(
411
410
throw new BSONError ( 'Binary type with subtype 0x02 contains too short binary size' ) ;
412
411
}
413
412
414
- // Copy the data
415
- for ( i = 0 ; i < binarySize ; i ++ ) {
416
- _buffer [ i ] = buffer [ index + i ] ;
417
- }
418
-
419
413
if ( promoteBuffers && promoteValues ) {
420
- value = _buffer ;
414
+ value = ByteUtils . allocateUnsafe ( binarySize ) ;
415
+ // Copy the data
416
+ for ( i = 0 ; i < binarySize ; i ++ ) {
417
+ value [ i ] = buffer [ index + i ] ;
418
+ }
421
419
} else {
422
420
value = new Binary ( buffer . slice ( index , index + binarySize ) , subType ) ;
423
421
if ( subType === constants . BSON_BINARY_SUBTYPE_UUID_NEW && UUID . isValid ( value ) ) {
@@ -616,8 +614,8 @@ function deserializeObject(
616
614
index = index + stringSize ;
617
615
618
616
// Read the oid
619
- const oidBuffer = ByteUtils . allocate ( 12 ) ;
620
- oidBuffer . set ( buffer . subarray ( index , index + 12 ) , 0 ) ;
617
+ const oidBuffer = ByteUtils . allocateUnsafe ( 12 ) ;
618
+ for ( let i = 0 ; i < 12 ; i ++ ) oidBuffer [ i ] = buffer [ index + i ] ;
621
619
const oid = new ObjectId ( oidBuffer ) ;
622
620
623
621
// Update the index
0 commit comments