Skip to content

Commit 4d01922

Browse files
mdempskyrobpike
authored andcommitted
encoding/gob: fix hang from skipping large slices
Change-Id: I4e59b5b1702e08d7c6191d0a70fb0a555f3340c8 Reviewed-on: https://go-review.googlesource.com/9061 Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Rob Pike <[email protected]>
1 parent 223ab4d commit 4d01922

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/encoding/gob/decode.go

+3
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,9 @@ func (dec *Decoder) decodeMap(mtyp reflect.Type, state *decoderState, value refl
575575
func (dec *Decoder) ignoreArrayHelper(state *decoderState, elemOp decOp, length int) {
576576
instr := &decInstr{elemOp, 0, nil, errors.New("no error")}
577577
for i := 0; i < length; i++ {
578+
if state.b.Len() == 0 {
579+
errorf("decoding array or slice: length exceeds input size (%d elements)", length)
580+
}
578581
elemOp(instr, state, noValue)
579582
}
580583
}

src/encoding/gob/encoder_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,8 @@ var badDataTests = []badDataTest{
953953
{"130a00fb5dad0bf8ff020263e70002fa28020202a89859", "slice length too large", nil},
954954
{"0f1000fb285d003316020735ff023a65c5", "interface encoding", nil},
955955
{"03fffb0616fffc00f902ff02ff03bf005d02885802a311a8120228022c028ee7", "GobDecoder", nil},
956+
// Issue 10491.
957+
{"10fe010f020102fe01100001fe010e000016fe010d030102fe010e00010101015801fe01100000000bfe011000f85555555555555555", "length exceeds input size", nil},
956958
}
957959

958960
// TestBadData tests that various problems caused by malformed input

0 commit comments

Comments
 (0)