Skip to content

Commit

Permalink
Merge pull request #62 from zchee/fix-decode-checkptr
Browse files Browse the repository at this point in the history
Fix checkptr validation error on decode
  • Loading branch information
goccy authored Nov 23, 2020
2 parents eee16e8 + 2b40975 commit 73ba041
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
6 changes: 2 additions & 4 deletions decode_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func (d *arrayDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
idx := 0
for {
s.cursor++
addr := uintptr(p) + uintptr(idx)*d.size
if err := d.valueDecoder.decodeStream(s, unsafe.Pointer(addr)); err != nil {
if err := d.valueDecoder.decodeStream(s, unsafe.Pointer(uintptr(p)+uintptr(idx)*d.size)); err != nil {
return err
}
s.skipWhiteSpace()
Expand Down Expand Up @@ -91,8 +90,7 @@ func (d *arrayDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64
idx := 0
for {
cursor++
addr := uintptr(p) + uintptr(idx)*d.size
c, err := d.valueDecoder.decode(buf, cursor, unsafe.Pointer(addr))
c, err := d.valueDecoder.decode(buf, cursor, unsafe.Pointer(uintptr(p)+uintptr(idx)*d.size))
if err != nil {
return 0, err
}
Expand Down
6 changes: 2 additions & 4 deletions decode_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ func (d *sliceDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
dst := sliceHeader{data: data, len: idx, cap: cap}
copySlice(d.elemType, dst, src)
}
addr := uintptr(data) + uintptr(idx)*d.size
if err := d.valueDecoder.decodeStream(s, unsafe.Pointer(addr)); err != nil {
if err := d.valueDecoder.decodeStream(s, unsafe.Pointer(uintptr(data)+uintptr(idx)*d.size)); err != nil {
return err
}
s.skipWhiteSpace()
Expand Down Expand Up @@ -191,8 +190,7 @@ func (d *sliceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64
dst := sliceHeader{data: data, len: idx, cap: cap}
copySlice(d.elemType, dst, src)
}
addr := uintptr(data) + uintptr(idx)*d.size
c, err := d.valueDecoder.decode(buf, cursor, unsafe.Pointer(addr))
c, err := d.valueDecoder.decode(buf, cursor, unsafe.Pointer(uintptr(data)+uintptr(idx)*d.size))
if err != nil {
return 0, err
}
Expand Down
6 changes: 2 additions & 4 deletions decode_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func (d *structDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
k := *(*string)(unsafe.Pointer(&key))
field, exists := d.fieldMap[k]
if exists {
addr := uintptr(p) + field.offset
if err := field.dec.decodeStream(s, unsafe.Pointer(addr)); err != nil {
if err := field.dec.decodeStream(s, unsafe.Pointer(uintptr(p)+field.offset)); err != nil {
return err
}
} else if s.disallowUnknownFields {
Expand Down Expand Up @@ -109,8 +108,7 @@ func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int6
k := *(*string)(unsafe.Pointer(&key))
field, exists := d.fieldMap[k]
if exists {
addr := uintptr(p) + field.offset
c, err := field.dec.decode(buf, cursor, unsafe.Pointer(addr))
c, err := field.dec.decode(buf, cursor, unsafe.Pointer(uintptr(p)+field.offset))
if err != nil {
return 0, err
}
Expand Down

0 comments on commit 73ba041

Please sign in to comment.