@@ -12,6 +12,7 @@ import (
1212 "net/rpc"
1313 "os/exec"
1414 "strconv"
15+ "strings"
1516 "testing"
1617 "time"
1718)
@@ -108,6 +109,50 @@ func doTestMsgpackDecodeMapAndExtSizeMismatch(t *testing.T, h Handle) {
108109 // fn(t, b, &s)
109110}
110111
112+ func doTestMsgpackIntOverflow (t * testing.T , h Handle ) {
113+ defer testSetup (t , & h )()
114+ if cpu32Bit {
115+ t .Skip ("test skipped on 32-bit machine" )
116+ }
117+ if testing .Short () {
118+ t .Skip ("skipping test in short mode" )
119+ }
120+ overflowString := "\xa7 input_b\xd9 \x12 HACKER OVERWRITTEN"
121+ var sb = make ([]byte , (1 << 32 )+ len (overflowString )+ 64 )
122+ copy (sb , overflowString )
123+ overflowString = stringView (sb )
124+ // sb.Grow((1 << 32) + len(overflowString) + 64)
125+ // sb.WriteString(overflowString)
126+ // overflowString = sb.String()
127+
128+ type sampleT struct {
129+ A string
130+ B string
131+ }
132+
133+ var v0 , v1 sampleT
134+ var b []byte
135+ var err error
136+
137+ v0 = sampleT {"normal" , "normal value" }
138+ b = testMarshalErr (v0 , h , t , "encode-normal" )
139+ testUnmarshalErr (& v1 , b , h , t , "decode" )
140+ testDeepEqualErr (v0 , v1 , t , "compare" )
141+
142+ v0 = sampleT {"hacker" , overflowString }
143+ b , err = testMarshal (v0 , h )
144+ if err == nil || ! strings .Contains (err .Error (), mpMaxLenOverflowErrorMsgPrefix ) {
145+ t .Fatalf ("expected error that len exceeds maximum" )
146+ }
147+ // v1 = sampleT{}
148+ // testUnmarshalErr(&v1, b, h, t, "decode")
149+ // testDeepEqualErr(v0, v1, t, "compare")
150+ }
151+
152+ func TestMsgpackIntOverflow (t * testing.T ) {
153+ doTestMsgpackIntOverflow (t , testMsgpackH )
154+ }
155+
111156func TestMsgpackCodecsTable (t * testing.T ) {
112157 doTestCodecTableOne (t , testMsgpackH )
113158}
0 commit comments