mirror of
https://github.com/ii64/sonic.git
synced 2026-06-23 01:46:44 +08:00
fix:(encoder) insufficient buffer size check for OP_i32 (#269)
This commit is contained in:
parent
2eae594741
commit
8b51e75241
3 changed files with 35 additions and 15 deletions
|
|
@ -819,7 +819,7 @@ func (self *_Assembler) _asm_OP_i16(_ *_Instr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Assembler) _asm_OP_i32(_ *_Instr) {
|
func (self *_Assembler) _asm_OP_i32(_ *_Instr) {
|
||||||
self.store_int(11, _F_i64toa, "MOVLQSX")
|
self.store_int(17, _F_i64toa, "MOVLQSX")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Assembler) _asm_OP_i64(_ *_Instr) {
|
func (self *_Assembler) _asm_OP_i64(_ *_Instr) {
|
||||||
|
|
@ -835,7 +835,7 @@ func (self *_Assembler) _asm_OP_u16(_ *_Instr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Assembler) _asm_OP_u32(_ *_Instr) {
|
func (self *_Assembler) _asm_OP_u32(_ *_Instr) {
|
||||||
self.store_int(10, _F_u64toa, "MOVLQZX")
|
self.store_int(16, _F_u64toa, "MOVLQZX")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Assembler) _asm_OP_u64(_ *_Instr) {
|
func (self *_Assembler) _asm_OP_u64(_ *_Instr) {
|
||||||
|
|
|
||||||
|
|
@ -832,7 +832,7 @@ func (self *_Assembler) _asm_OP_i16(_ *_Instr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Assembler) _asm_OP_i32(_ *_Instr) {
|
func (self *_Assembler) _asm_OP_i32(_ *_Instr) {
|
||||||
self.store_int(11, _F_i64toa, "MOVLQSX")
|
self.store_int(17, _F_i64toa, "MOVLQSX")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Assembler) _asm_OP_i64(_ *_Instr) {
|
func (self *_Assembler) _asm_OP_i64(_ *_Instr) {
|
||||||
|
|
@ -848,7 +848,7 @@ func (self *_Assembler) _asm_OP_u16(_ *_Instr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Assembler) _asm_OP_u32(_ *_Instr) {
|
func (self *_Assembler) _asm_OP_u32(_ *_Instr) {
|
||||||
self.store_int(10, _F_u64toa, "MOVLQZX")
|
self.store_int(16, _F_u64toa, "MOVLQZX")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Assembler) _asm_OP_u64(_ *_Instr) {
|
func (self *_Assembler) _asm_OP_u64(_ *_Instr) {
|
||||||
|
|
|
||||||
|
|
@ -17,20 +17,40 @@
|
||||||
package encoder
|
package encoder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
`encoding/hex`
|
||||||
"encoding/json"
|
`encoding/json`
|
||||||
"math"
|
`math`
|
||||||
"reflect"
|
`reflect`
|
||||||
"runtime"
|
`runtime`
|
||||||
"strings"
|
`strings`
|
||||||
"testing"
|
`testing`
|
||||||
"unsafe"
|
`unsafe`
|
||||||
|
|
||||||
"github.com/bytedance/sonic/internal/rt"
|
`github.com/bytedance/sonic/internal/rt`
|
||||||
"github.com/davecgh/go-spew/spew"
|
`github.com/davecgh/go-spew/spew`
|
||||||
"github.com/stretchr/testify/assert"
|
`github.com/stretchr/testify/assert`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestEncoderMemoryCorruption(t *testing.T) {
|
||||||
|
println("TestEncoderMemoryCorruption")
|
||||||
|
var m = map[string]interface{}{
|
||||||
|
"1": map[string]interface{} {
|
||||||
|
`"`+strings.Repeat("a", _MaxBuffer - 38)+`"`: "b",
|
||||||
|
"1": map[string]int32{
|
||||||
|
"b": 1658219785,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
out, err := Encode(m, SortMapKeys)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
println(len(out))
|
||||||
|
if err := json.Unmarshal(out, &m); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAssembler_CompileAndLoad(t *testing.T) {
|
func TestAssembler_CompileAndLoad(t *testing.T) {
|
||||||
p, err := newCompiler().compile(reflect.TypeOf((*bool)(nil)))
|
p, err := newCompiler().compile(reflect.TypeOf((*bool)(nil)))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue