Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8dbcce3

Browse files
authoredMar 14, 2023
fix: decimal map key may be truncated and populated unexpectedly (bytedance#382)
* fix:(StreamDecoder) Integer map key may be truncated and populated unexpectedly * feat: expose option `DefaultBufferSize` * test adjust * test adjust * feat: add options to make default buffer size adjustable
1 parent 8f1e08c commit 8dbcce3

10 files changed

+139
-60
lines changed
 

‎decoder/assembler_amd64_go116.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -1487,18 +1487,21 @@ func (self *_Assembler) _asm_OP_map_init(_ *_Instr) {
14871487
func (self *_Assembler) _asm_OP_map_key_i8(p *_Instr) {
14881488
self.parse_signed(int8Type, "", p.vi()) // PARSE int8
14891489
self.range_signed(_I_int8, _T_int8, math.MinInt8, math.MaxInt8) // RANGE int8
1490+
self.match_char('"')
14901491
self.mapassign_std(p.vt(), _VAR_st_Iv) // MAPASSIGN int8, mapassign, st.Iv
14911492
}
14921493

14931494
func (self *_Assembler) _asm_OP_map_key_i16(p *_Instr) {
14941495
self.parse_signed(int16Type, "", p.vi()) // PARSE int16
14951496
self.range_signed(_I_int16, _T_int16, math.MinInt16, math.MaxInt16) // RANGE int16
1497+
self.match_char('"')
14961498
self.mapassign_std(p.vt(), _VAR_st_Iv) // MAPASSIGN int16, mapassign, st.Iv
14971499
}
14981500

14991501
func (self *_Assembler) _asm_OP_map_key_i32(p *_Instr) {
15001502
self.parse_signed(int32Type, "", p.vi()) // PARSE int32
15011503
self.range_signed(_I_int32, _T_int32, math.MinInt32, math.MaxInt32) // RANGE int32
1504+
self.match_char('"')
15021505
if vt := p.vt(); !mapfast(vt) {
15031506
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN int32, mapassign, st.Iv
15041507
} else {
@@ -1508,6 +1511,7 @@ func (self *_Assembler) _asm_OP_map_key_i32(p *_Instr) {
15081511

15091512
func (self *_Assembler) _asm_OP_map_key_i64(p *_Instr) {
15101513
self.parse_signed(int64Type, "", p.vi()) // PARSE int64
1514+
self.match_char('"')
15111515
if vt := p.vt(); !mapfast(vt) {
15121516
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN int64, mapassign, st.Iv
15131517
} else {
@@ -1519,18 +1523,21 @@ func (self *_Assembler) _asm_OP_map_key_i64(p *_Instr) {
15191523
func (self *_Assembler) _asm_OP_map_key_u8(p *_Instr) {
15201524
self.parse_unsigned(uint8Type, "", p.vi()) // PARSE uint8
15211525
self.range_unsigned(_I_uint8, _T_uint8, math.MaxUint8) // RANGE uint8
1526+
self.match_char('"')
15221527
self.mapassign_std(p.vt(), _VAR_st_Iv) // MAPASSIGN uint8, vt.Iv
15231528
}
15241529

15251530
func (self *_Assembler) _asm_OP_map_key_u16(p *_Instr) {
15261531
self.parse_unsigned(uint16Type, "", p.vi()) // PARSE uint16
15271532
self.range_unsigned(_I_uint16, _T_uint16, math.MaxUint16) // RANGE uint16
1533+
self.match_char('"')
15281534
self.mapassign_std(p.vt(), _VAR_st_Iv) // MAPASSIGN uint16, vt.Iv
15291535
}
15301536

15311537
func (self *_Assembler) _asm_OP_map_key_u32(p *_Instr) {
15321538
self.parse_unsigned(uint32Type, "", p.vi()) // PARSE uint32
15331539
self.range_unsigned(_I_uint32, _T_uint32, math.MaxUint32) // RANGE uint32
1540+
self.match_char('"')
15341541
if vt := p.vt(); !mapfast(vt) {
15351542
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN uint32, vt.Iv
15361543
} else {
@@ -1540,6 +1547,7 @@ func (self *_Assembler) _asm_OP_map_key_u32(p *_Instr) {
15401547

15411548
func (self *_Assembler) _asm_OP_map_key_u64(p *_Instr) {
15421549
self.parse_unsigned(uint64Type, "", p.vi()) // PARSE uint64
1550+
self.match_char('"')
15431551
if vt := p.vt(); !mapfast(vt) {
15441552
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN uint64, vt.Iv
15451553
} else {
@@ -1552,11 +1560,13 @@ func (self *_Assembler) _asm_OP_map_key_f32(p *_Instr) {
15521560
self.parse_number(float32Type, "", p.vi()) // PARSE NUMBER
15531561
self.range_single() // RANGE float32
15541562
self.Emit("MOVSS", _X0, _VAR_st_Dv) // MOVSS X0, st.Dv
1563+
self.match_char('"')
15551564
self.mapassign_std(p.vt(), _VAR_st_Dv) // MAPASSIGN ${p.vt()}, mapassign, st.Dv
15561565
}
15571566

15581567
func (self *_Assembler) _asm_OP_map_key_f64(p *_Instr) {
15591568
self.parse_number(float64Type, "", p.vi()) // PARSE NUMBER
1569+
self.match_char('"')
15601570
self.mapassign_std(p.vt(), _VAR_st_Dv) // MAPASSIGN ${p.vt()}, mapassign, st.Dv
15611571
}
15621572

@@ -1787,10 +1797,14 @@ func (self *_Assembler) lspace(subfix string) {
17871797
}
17881798

17891799
func (self *_Assembler) _asm_OP_match_char(p *_Instr) {
1800+
self.match_char(p.vb())
1801+
}
1802+
1803+
func (self *_Assembler) match_char(char byte) {
17901804
self.check_eof(1)
1791-
self.Emit("CMPB", jit.Sib(_IP, _IC, 1, 0), jit.Imm(int64(p.vb()))) // CMPB (IP)(IC), ${p.vb()}
1792-
self.Sjmp("JNE" , _LB_char_0_error) // JNE _char_0_error
1793-
self.Emit("ADDQ", jit.Imm(1), _IC) // ADDQ $1, IC
1805+
self.Emit("CMPB", jit.Sib(_IP, _IC, 1, 0), jit.Imm(int64(char))) // CMPB (IP)(IC), ${p.vb()}
1806+
self.Sjmp("JNE" , _LB_char_0_error) // JNE _char_0_error
1807+
self.Emit("ADDQ", jit.Imm(1), _IC) // ADDQ $1, IC
17941808
}
17951809

17961810
func (self *_Assembler) _asm_OP_check_char(p *_Instr) {

‎decoder/assembler_amd64_go117.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -1482,18 +1482,21 @@ func (self *_Assembler) _asm_OP_map_init(_ *_Instr) {
14821482
func (self *_Assembler) _asm_OP_map_key_i8(p *_Instr) {
14831483
self.parse_signed(int8Type, "", p.vi()) // PARSE int8
14841484
self.range_signed_CX(_I_int8, _T_int8, math.MinInt8, math.MaxInt8) // RANGE int8
1485+
self.match_char('"')
14851486
self.mapassign_std(p.vt(), _VAR_st_Iv) // MAPASSIGN int8, mapassign, st.Iv
14861487
}
14871488

14881489
func (self *_Assembler) _asm_OP_map_key_i16(p *_Instr) {
14891490
self.parse_signed(int16Type, "", p.vi()) // PARSE int16
14901491
self.range_signed_CX(_I_int16, _T_int16, math.MinInt16, math.MaxInt16) // RANGE int16
1492+
self.match_char('"')
14911493
self.mapassign_std(p.vt(), _VAR_st_Iv) // MAPASSIGN int16, mapassign, st.Iv
14921494
}
14931495

14941496
func (self *_Assembler) _asm_OP_map_key_i32(p *_Instr) {
14951497
self.parse_signed(int32Type, "", p.vi()) // PARSE int32
14961498
self.range_signed_CX(_I_int32, _T_int32, math.MinInt32, math.MaxInt32) // RANGE int32
1499+
self.match_char('"')
14971500
if vt := p.vt(); !mapfast(vt) {
14981501
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN int32, mapassign, st.Iv
14991502
} else {
@@ -1504,6 +1507,7 @@ func (self *_Assembler) _asm_OP_map_key_i32(p *_Instr) {
15041507

15051508
func (self *_Assembler) _asm_OP_map_key_i64(p *_Instr) {
15061509
self.parse_signed(int64Type, "", p.vi()) // PARSE int64
1510+
self.match_char('"')
15071511
if vt := p.vt(); !mapfast(vt) {
15081512
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN int64, mapassign, st.Iv
15091513
} else {
@@ -1515,18 +1519,21 @@ func (self *_Assembler) _asm_OP_map_key_i64(p *_Instr) {
15151519
func (self *_Assembler) _asm_OP_map_key_u8(p *_Instr) {
15161520
self.parse_unsigned(uint8Type, "", p.vi()) // PARSE uint8
15171521
self.range_unsigned_CX(_I_uint8, _T_uint8, math.MaxUint8) // RANGE uint8
1518-
self.mapassign_std(p.vt(), _VAR_st_Iv) // MAPASSIGN uint8, vt.Iv
1522+
self.match_char('"')
1523+
self.mapassign_std(p.vt(), _VAR_st_Iv) // MAPASSIGN uint8, vt.Iv
15191524
}
15201525

15211526
func (self *_Assembler) _asm_OP_map_key_u16(p *_Instr) {
15221527
self.parse_unsigned(uint16Type, "", p.vi()) // PARSE uint16
15231528
self.range_unsigned_CX(_I_uint16, _T_uint16, math.MaxUint16) // RANGE uint16
1529+
self.match_char('"')
15241530
self.mapassign_std(p.vt(), _VAR_st_Iv) // MAPASSIGN uint16, vt.Iv
15251531
}
15261532

15271533
func (self *_Assembler) _asm_OP_map_key_u32(p *_Instr) {
15281534
self.parse_unsigned(uint32Type, "", p.vi()) // PARSE uint32
15291535
self.range_unsigned_CX(_I_uint32, _T_uint32, math.MaxUint32) // RANGE uint32
1536+
self.match_char('"')
15301537
if vt := p.vt(); !mapfast(vt) {
15311538
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN uint32, vt.Iv
15321539
} else {
@@ -1537,6 +1544,7 @@ func (self *_Assembler) _asm_OP_map_key_u32(p *_Instr) {
15371544

15381545
func (self *_Assembler) _asm_OP_map_key_u64(p *_Instr) {
15391546
self.parse_unsigned(uint64Type, "", p.vi()) // PARSE uint64
1547+
self.match_char('"')
15401548
if vt := p.vt(); !mapfast(vt) {
15411549
self.mapassign_std(vt, _VAR_st_Iv) // MAPASSIGN uint64, vt.Iv
15421550
} else {
@@ -1549,11 +1557,13 @@ func (self *_Assembler) _asm_OP_map_key_f32(p *_Instr) {
15491557
self.parse_number(float32Type, "", p.vi()) // PARSE NUMBER
15501558
self.range_single_X0() // RANGE float32
15511559
self.Emit("MOVSS", _X0, _VAR_st_Dv) // MOVSS X0, st.Dv
1560+
self.match_char('"')
15521561
self.mapassign_std(p.vt(), _VAR_st_Dv) // MAPASSIGN ${p.vt()}, mapassign, st.Dv
15531562
}
15541563

15551564
func (self *_Assembler) _asm_OP_map_key_f64(p *_Instr) {
15561565
self.parse_number(float64Type, "", p.vi()) // PARSE NUMBER
1566+
self.match_char('"')
15571567
self.mapassign_std(p.vt(), _VAR_st_Dv) // MAPASSIGN ${p.vt()}, mapassign, st.Dv
15581568
}
15591569

@@ -1767,8 +1777,12 @@ func (self *_Assembler) lspace(subfix string) {
17671777
}
17681778

17691779
func (self *_Assembler) _asm_OP_match_char(p *_Instr) {
1780+
self.match_char(p.vb())
1781+
}
1782+
1783+
func (self *_Assembler) match_char(char byte) {
17701784
self.check_eof(1)
1771-
self.Emit("CMPB", jit.Sib(_IP, _IC, 1, 0), jit.Imm(int64(p.vb()))) // CMPB (IP)(IC), ${p.vb()}
1785+
self.Emit("CMPB", jit.Sib(_IP, _IC, 1, 0), jit.Imm(int64(char))) // CMPB (IP)(IC), ${p.vb()}
17721786
self.Sjmp("JNE" , _LB_char_0_error) // JNE _char_0_error
17731787
self.Emit("ADDQ", jit.Imm(1), _IC) // ADDQ $1, IC
17741788
}

‎decoder/assembler_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -418,49 +418,49 @@ func TestAssembler_OpCode(t *testing.T) {
418418
}, {
419419
key: "_OP_map_key_i8",
420420
ins: []_Instr{newInsVt(_OP_map_key_i8, reflect.TypeOf(map[int8]int{}))},
421-
src: `123`,
421+
src: `123"`,
422422
exp: map[int8]int{123: 0},
423423
val: map[int8]int{},
424424
}, {
425425
key: "_OP_map_key_i32",
426426
ins: []_Instr{newInsVt(_OP_map_key_i32, reflect.TypeOf(map[int32]int{}))},
427-
src: `123456789`,
427+
src: `123456789"`,
428428
exp: map[int32]int{123456789: 0},
429429
val: map[int32]int{},
430430
}, {
431431
key: "_OP_map_key_i64",
432432
ins: []_Instr{newInsVt(_OP_map_key_i64, reflect.TypeOf(map[int64]int{}))},
433-
src: `123456789123456789`,
433+
src: `123456789123456789"`,
434434
exp: map[int64]int{123456789123456789: 0},
435435
val: map[int64]int{},
436436
}, {
437437
key: "_OP_map_key_u8",
438438
ins: []_Instr{newInsVt(_OP_map_key_u8, reflect.TypeOf(map[uint8]int{}))},
439-
src: `123`,
439+
src: `123"`,
440440
exp: map[uint8]int{123: 0},
441441
val: map[uint8]int{},
442442
}, {
443443
key: "_OP_map_key_u32",
444444
ins: []_Instr{newInsVt(_OP_map_key_u32, reflect.TypeOf(map[uint32]int{}))},
445-
src: `123456789`,
445+
src: `123456789"`,
446446
exp: map[uint32]int{123456789: 0},
447447
val: map[uint32]int{},
448448
}, {
449449
key: "_OP_map_key_u64",
450450
ins: []_Instr{newInsVt(_OP_map_key_u64, reflect.TypeOf(map[uint64]int{}))},
451-
src: `123456789123456789`,
451+
src: `123456789123456789"`,
452452
exp: map[uint64]int{123456789123456789: 0},
453453
val: map[uint64]int{},
454454
}, {
455455
key: "_OP_map_key_f32",
456456
ins: []_Instr{newInsVt(_OP_map_key_f32, reflect.TypeOf(map[float32]int{}))},
457-
src: `1.25`,
457+
src: `1.25"`,
458458
exp: map[float32]int{1.25: 0},
459459
val: map[float32]int{},
460460
}, {
461461
key: "_OP_map_key_f64",
462462
ins: []_Instr{newInsVt(_OP_map_key_f64, reflect.TypeOf(map[float64]int{}))},
463-
src: `1.25`,
463+
src: `1.25"`,
464464
exp: map[float64]int{1.25: 0},
465465
val: map[float64]int{},
466466
}, {

‎decoder/compiler.go

-10
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,6 @@ func (self *_Compiler) compileMapOp(p *_Program, sp int, vt reflect.Type, op _Op
639639
skip2 := p.pc()
640640
p.rtt(op, vt)
641641

642-
/* match the closing quote if needed */
643-
if op != _OP_map_key_str && op != _OP_map_key_utext && op != _OP_map_key_utext_p {
644-
p.chr(_OP_match_char, '"')
645-
}
646-
647642
/* match the value separator */
648643
p.add(_OP_lspace)
649644
p.chr(_OP_match_char, ':')
@@ -660,11 +655,6 @@ func (self *_Compiler) compileMapOp(p *_Program, sp int, vt reflect.Type, op _Op
660655
skip3 := p.pc()
661656
p.rtt(op, vt)
662657

663-
/* match the closing quote if needed */
664-
if op != _OP_map_key_str && op != _OP_map_key_utext && op != _OP_map_key_utext_p {
665-
p.chr(_OP_match_char, '"')
666-
}
667-
668658
/* match the value separator */
669659
p.add(_OP_lspace)
670660
p.chr(_OP_match_char, ':')

‎decoder/stream.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ import (
2121
`io`
2222
`sync`
2323

24+
`github.com/bytedance/sonic/option`
2425
`github.com/bytedance/sonic/internal/native/types`
2526
)
2627

2728
var (
28-
defaultBufferSize uint = 4096
29-
growSliceFactorShift uint = 1
30-
minLeftBufferShift uint = 2
29+
minLeftBufferShift uint = 1
3130
)
3231

3332
type StreamDecoder struct {
@@ -41,7 +40,7 @@ type StreamDecoder struct {
4140

4241
var bufPool = sync.Pool{
4342
New: func () interface{} {
44-
return make([]byte, 0, defaultBufferSize)
43+
return make([]byte, 0, option.DefaultDecoderBufferSize)
4544
},
4645
}
4746

@@ -206,8 +205,8 @@ func realloc(buf *[]byte) {
206205
c := uint(cap(*buf))
207206
if c - l <= c >> minLeftBufferShift {
208207
e := l+(l>>minLeftBufferShift)
209-
if e < defaultBufferSize {
210-
e = defaultBufferSize
208+
if e < option.DefaultDecoderBufferSize {
209+
e = option.DefaultDecoderBufferSize
211210
}
212211
tmp := make([]byte, l, e)
213212
copy(tmp, *buf)

‎decoder/stream_test.go

+29-27
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,47 @@ import (
2424
`strings`
2525
`testing`
2626

27+
`github.com/bytedance/sonic/option`
2728
`github.com/stretchr/testify/assert`
2829
`github.com/stretchr/testify/require`
2930
)
3031

3132
var (
32-
_Single_JSON = `{"aaaaa":"` + strings.Repeat("b", int(defaultBufferSize)) + `"} { `
33-
_Double_JSON = `{"aaaaa":"` + strings.Repeat("b", int(defaultBufferSize)) + `"} {"11111":"` + strings.Repeat("2", int(defaultBufferSize)) + `"}`
34-
_Triple_JSON = `{"aaaaa":"` + strings.Repeat("b", int(defaultBufferSize)) + `"}{ } {"11111":"` +
35-
strings.Repeat("2", int(defaultBufferSize))+`"} b {}`
33+
DefaultBufferSize = option.DefaultDecoderBufferSize
34+
_Single_JSON = `{"aaaaa":"` + strings.Repeat("b", int(DefaultBufferSize)) + `"} { `
35+
_Double_JSON = `{"aaaaa":"` + strings.Repeat("b", int(DefaultBufferSize)) + `"} {"11111":"` + strings.Repeat("2", int(DefaultBufferSize)) + `"}`
36+
_Triple_JSON = `{"aaaaa":"` + strings.Repeat("b", int(DefaultBufferSize)) + `"}{ } {"11111":"` +
37+
strings.Repeat("2", int(DefaultBufferSize))+`"} b {}`
3638
)
3739

3840
func TestStreamError(t *testing.T) {
3941
var qs = []string{
40-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"`,
41-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"}`,
42-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`""}`,
43-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":}`,
44-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":]`,
45-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":1x`,
46-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":1x}`,
47-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":1x]`,
48-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":t`,
49-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":t}`,
50-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":true]`,
51-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":f`,
52-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":f}`,
53-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":false]`,
54-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":n`,
55-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":n}`,
56-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":null]`,
57-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":"`,
58-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":"a`,
59-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":"a}`,
60-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":"a"`,
61-
`{`+strings.Repeat(" ", int(defaultBufferSize))+`"":"a"]`,
42+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"`,
43+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"}`,
44+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`""}`,
45+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":}`,
46+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":]`,
47+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":1x`,
48+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":1x}`,
49+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":1x]`,
50+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":t`,
51+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":t}`,
52+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":true]`,
53+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":f`,
54+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":f}`,
55+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":false]`,
56+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":n`,
57+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":n}`,
58+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":null]`,
59+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":"`,
60+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":"a`,
61+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":"a}`,
62+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":"a"`,
63+
`{`+strings.Repeat(" ", int(DefaultBufferSize))+`"":"a"]`,
6264
}
6365

6466
for i, q := range qs {
65-
var qq = []byte(q[:int(defaultBufferSize)]+strings.Repeat(" ", i*100)+q[int(defaultBufferSize):])
67+
var qq = []byte(q[:int(DefaultBufferSize)]+strings.Repeat(" ", i*100)+q[int(DefaultBufferSize):])
6668
var obj interface{}
6769
require.NotNil(t, NewStreamDecoder(bytes.NewReader(qq)).Decode(&obj))
6870
}

‎encoder/assembler_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
`testing`
2727
`unsafe`
2828

29+
`github.com/bytedance/sonic/option`
2930
`github.com/bytedance/sonic/internal/rt`
3031
`github.com/davecgh/go-spew/spew`
3132
`github.com/stretchr/testify/assert`
@@ -35,7 +36,7 @@ func TestEncoderMemoryCorruption(t *testing.T) {
3536
println("TestEncoderMemoryCorruption")
3637
var m = map[string]interface{}{
3738
"1": map[string]interface{} {
38-
`"`+strings.Repeat("a", _MaxBuffer - 38)+`"`: "b",
39+
`"`+strings.Repeat("a", int(option.DefaultEncoderBufferSize) - 38)+`"`: "b",
3940
"1": map[string]int32{
4041
"b": 1658219785,
4142
},

0 commit comments

Comments
 (0)
Please sign in to comment.