Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix delimited proto reader silently dropping messages that exceed the…
… default bufio.Scanner buffer max size
  • Loading branch information
jmatth committed Dec 8, 2025
commit f9c641078e8647fd68c100b90cad3adf28a0981a
7 changes: 7 additions & 0 deletions protoutils/delimited_protos.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ func (o *DelimitedProtoReader[T, M]) allWithMessageProvider(getMessage func() M)
// yielded may be overwritten on subsequent iterations. If you need to use the
// yieded []byte outside an iteration you must copy it somewhere else.
func (o *RawDelimitedProtoReader) All() iter.Seq[[]byte] {
// 2 GiB, as defined by the protobuf spec
const protoMaxBytes = 1024 * 1024 * 1024 * 2
// Max message size + 4 bytes for the length header
const bufferMaxSize = protoMaxBytes + 4
return func(yield func([]byte) bool) {
scanner := bufio.NewScanner(o.reader)
// Start with no buffer and let bufio figure out the initial allocation +
// when it needs to be resized.
scanner.Buffer(nil, bufferMaxSize)
scanner.Split(splitMessages)

for scanner.Scan() {
Expand Down