From 6439010e52610650f8aa048173832f94006ebdbd Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 12 May 2015 10:29:53 -0700 Subject: encoding/gob: add "too big" check when writing a message Messages that are too big are rejected when read, so they should be rejected when written too. Fixes #10518. Change-Id: I96678fbe2d94f51b957fe26faef33cd8df3823dd Reviewed-on: https://go-review.googlesource.com/9965 Reviewed-by: Brad Fitzpatrick --- src/encoding/gob/encoder.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/encoding/gob/encoder.go') diff --git a/src/encoding/gob/encoder.go b/src/encoding/gob/encoder.go index a340e47b5e..62d0f42e81 100644 --- a/src/encoding/gob/encoder.go +++ b/src/encoding/gob/encoder.go @@ -5,6 +5,7 @@ package gob import ( + "errors" "io" "reflect" "sync" @@ -65,6 +66,11 @@ func (enc *Encoder) writeMessage(w io.Writer, b *encBuffer) { // it by hand. message := b.Bytes() messageLen := len(message) - maxLength + // Length cannot be bigger than the decoder can handle. + if messageLen >= tooBig { + enc.setError(errors.New("gob: encoder: message too big")) + return + } // Encode the length. enc.countState.b.Reset() enc.countState.encodeUint(uint64(messageLen)) -- cgit v1.3