File tree 1 file changed +13
-0
lines changed
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ const debug = require('debug')('abci')
6
6
const { varint } = require ( 'protocol-buffers-encodings' )
7
7
const { Request, Response } = require ( '../types.js' ) . abci
8
8
9
+ const MAX_MESSAGE_SIZE = 104857600 // 100mb
10
+
9
11
class Connection extends EventEmitter {
10
12
constructor ( stream , onMessage ) {
11
13
super ( )
@@ -16,6 +18,12 @@ class Connection extends EventEmitter {
16
18
this . waiting = false
17
19
18
20
stream . on ( 'data' , this . onData . bind ( this ) )
21
+ stream . on ( 'error' , this . error . bind ( this ) )
22
+ }
23
+
24
+ error ( err ) {
25
+ this . close ( )
26
+ this . emit ( 'error' , err )
19
27
}
20
28
21
29
async onData ( data ) {
@@ -28,6 +36,11 @@ class Connection extends EventEmitter {
28
36
let length = varint . decode ( this . recvBuf . slice ( 0 , 8 ) ) >> 1
29
37
let lengthLength = varint . decode . bytes
30
38
39
+ if ( length > MAX_MESSAGE_SIZE ) {
40
+ this . error ( Error ( 'message is longer than maximum size' ) )
41
+ return
42
+ }
43
+
31
44
if ( lengthLength + length > this . recvBuf . length ) {
32
45
// buffering message, don't read yet
33
46
return
You can’t perform that action at this time.
0 commit comments