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

Commit 21a8f59

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 c813bae commit 21a8f59

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/decode.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ 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 = 1 << 20 // 1MB
7+
68
interface MessageHeader {
79
id: number
810
type: keyof typeof MessageTypeNames

0 commit comments

Comments
 (0)