Prevent ERR_OUT_OF_RANGE errors when reading messageSize from buffer #571
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi 👋 , this is a follow up to this PR from last year. We ran into an issue today where the
const messageSize = buf.readUInt32BE(bufferOffset);
line would cause anERR_OUT_OF_RANGE
error in about 1/5 executions ofpgtyped
. The error would always occur when parsing a file which referenced a large enum. The error began occurring when a change was merged to add two values to this enum.My suspicion is that the additional enum value has caused the boundary of the TCP packet splitting to land in the middle of the bytes making up the
messageSize
integer. The fix that I have implemented is to first check that the buffer has enough data to read the indicator and messageSize, before attempting to do so.I attempted to create a minimal reproduction, but was unable to. Running just the affected file resulted in the error occurring only about 1/20 executions, and I wasn't able to reproduce the error at all when I attempted to simplify the DB schema to just the large enum and associated tables.