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

Commit

Permalink
fix: apply message size limit before decoding message
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
achingbrain committed Nov 23, 2022
1 parent 91d2e8c commit f5ec195
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Uint8ArrayList } from 'uint8arraylist'
import type { Source } from 'it-stream-types'
import type { Message } from './message-types.js'

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

interface MessageHeader {
id: number
Expand Down

0 comments on commit f5ec195

Please sign in to comment.