File tree 2 files changed +18
-1
lines changed
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 27
27
function generateMask ( ) {
28
28
if ( bufIdx === BUFFER_SIZE ) {
29
29
bufIdx = 0
30
- crypto . randomFillSync ( ( buffer ??= Buffer . allocUnsafe ( BUFFER_SIZE ) ) , 0 , BUFFER_SIZE )
30
+ crypto . randomFillSync ( ( buffer ??= Buffer . allocUnsafeSlow ( BUFFER_SIZE ) ) , 0 , BUFFER_SIZE )
31
31
}
32
32
return [ buffer [ bufIdx ++ ] , buffer [ bufIdx ++ ] , buffer [ bufIdx ++ ] , buffer [ bufIdx ++ ] ]
33
33
}
Original file line number Diff line number Diff line change @@ -5,6 +5,23 @@ const assert = require('node:assert')
5
5
const { WebsocketFrameSend } = require ( '../../lib/web/websocket/frame' )
6
6
const { opcodes } = require ( '../../lib/web/websocket/constants' )
7
7
8
+ // Always be above all tests.
9
+ test ( 'Don not use pooled buffer in mask pool' , ( ) => {
10
+ const allocUnsafe = Buffer . allocUnsafe
11
+ let counter = 0
12
+ try {
13
+ Buffer . allocUnsafe = ( n ) => {
14
+ counter ++
15
+ return allocUnsafe ( n )
16
+ }
17
+ // create mask pool
18
+ new WebsocketFrameSend ( Buffer . alloc ( 0 ) ) . createFrame ( opcodes . BINARY )
19
+ assert . strictEqual ( counter , 1 )
20
+ } finally {
21
+ Buffer . allocUnsafe = allocUnsafe
22
+ }
23
+ } )
24
+
8
25
test ( 'Writing 16-bit frame length value at correct offset when buffer has a non-zero byteOffset' , ( ) => {
9
26
/*
10
27
When writing 16-bit frame lengths, a `DataView` was being used without setting a `byteOffset` into the buffer:
You can’t perform that action at this time.
0 commit comments