Skip to content

armor: bound line length when reading - #757

Open
deadcaf3 wants to merge 1 commit into
FiloSottile:mainfrom
deadcaf3:armor-bounded-line
Open

deadcaf3 wants to merge 1 commit into
FiloSottile:mainfrom
deadcaf3:armor-bounded-line

Conversation

@deadcaf3

Copy link
Copy Markdown

armor.NewReader buffered each line in full with ReadBytes before the 64 column check, so input with no newline could exhaust memory. This reads with ReadSlice instead, which stops at the bufio buffer (at least 4096 bytes), and rejects the line when the buffer fills.

TestLongLine feeds a 64 MiB line before and after the header and checks that the reader fails after reading less than 1 MiB. go test ./... passes, including the CCTV vectors.

Fixes #756

The armored reader used bufio.Reader.ReadBytes, which keeps reading
until it finds a newline. An input with no newline was buffered in
full before the 64 column check ran, so a large armored input could
exhaust memory.

Use ReadSlice instead, which stops at the bufio buffer size (at least
4096 bytes, well above any valid line), and reject the line when the
buffer fills.

Fixes FiloSottile#756

@pcarinhas pcarinhas left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG.

  • Tests pass on go version go1.27.0 linux/amd64

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

armor: NewReader buffers unbounded lines before the column check

2 participants