Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit e0df39f

Browse files
committed
fix #206, do not allow nil pointer as unmarshal input
1 parent 13f8643 commit e0df39f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

feature_reflect.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ func (iter *Iterator) ReadVal(obj interface{}) {
233233
return
234234
}
235235
e := (*emptyInterface)(unsafe.Pointer(&obj))
236+
if e.word == nil {
237+
iter.ReportError("ReadVal", "can not read into nil pointer")
238+
return
239+
}
236240
decoder.Decode(e.word, iter)
237241
}
238242

jsoniter_invalid_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,14 @@ func Test_valid(t *testing.T) {
136136
should.True(Valid([]byte(`{}`)))
137137
should.False(Valid([]byte(`{`)))
138138
}
139+
140+
func Test_nil_pointer(t *testing.T) {
141+
should := require.New(t)
142+
data := []byte(`{"A":0}`)
143+
type T struct {
144+
X int
145+
}
146+
var obj *T
147+
err := Unmarshal(data, obj)
148+
should.NotNil(err)
149+
}

0 commit comments

Comments
 (0)