Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit f5ec195

Browse files
committed
fix: apply message size limit before decoding message
If we apply the message size limit after decoding the message it's too late as we've already processed the bad message. Instead, if the buffer full of unprocessed messages grows to be large than the max message size (e.g. we have not recieved a complete message under the size limit), throw an error which will cause the stream to be reset.
1 parent 91d2e8c commit f5ec195

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/decode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Uint8ArrayList } from 'uint8arraylist'
33
import type { Source } from 'it-stream-types'
44
import type { Message } from './message-types.js'
55

6-
export const MAX_MSG_SIZE = Math.pow(2, 20)
6+
export const MAX_MSG_SIZE = 1 << 20 // 1MB
77

88
interface MessageHeader {
99
id: number

0 commit comments

Comments
 (0)