Copy buffer to decode of UnmarshalJSON

This commit is contained in:
Masaaki Goshima 2021-01-22 14:01:01 +09:00
parent 305e858ea1
commit 3682ec0cf3
1 changed files with 4 additions and 1 deletions

View File

@ -57,11 +57,14 @@ func (d *unmarshalJSONDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer
return 0, err
}
src := buf[start:end]
dst := make([]byte, len(src))
copy(dst, src)
v := *(*interface{})(unsafe.Pointer(&interfaceHeader{
typ: d.typ,
ptr: p,
}))
if err := v.(Unmarshaler).UnmarshalJSON(src); err != nil {
if err := v.(Unmarshaler).UnmarshalJSON(dst); err != nil {
d.annotateError(cursor, err)
return 0, err
}