Skip to content

Commit

Permalink
Merge pull request #12 from jmank88/reject_noop
Browse files Browse the repository at this point in the history
reject strongly typed no-op
  • Loading branch information
jmank88 authored Feb 19, 2018
2 parents 5294958 + eacc176 commit ac2a339
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ func objectAsInterface(o *ObjectDecoder) (interface{}, error) {
if o.Len > o.MaxCollectionAlloc {
return nil, errors.Errorf("collection exceeds max allocation limit of %d: %d", o.MaxCollectionAlloc, o.Len)
}
if o.ValType == NoOpMarker {
return nil, errors.New("No-Op (N) is not a legal strong type")
}
valType := elementTypeFor(o.ValType)
mapType := reflect.MapOf(stringType, valType)
mapValue := makeMap(mapType, o.Len)
Expand All @@ -755,6 +758,9 @@ func objectAsInterface(o *ObjectDecoder) (interface{}, error) {
// be strongly typed, or an interface{} in the general case.
func arrayAsInterface(a *ArrayDecoder) (interface{}, error) {
var sliceValue reflect.Value
if a.ElemType == NoOpMarker {
return nil, errors.New("No-Op (N) is not a legal strong type")
}
elemType := elementTypeFor(a.ElemType)
sliceType := reflect.SliceOf(elemType)

Expand Down
14 changes: 14 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,17 @@ func TestDecoder_maxCollectionAlloc(t *testing.T) {
t.Error("expected error")
}
}

func TestFuzzUnmarshalBlock_strong_type_NoOp_array(t *testing.T) {
var i interface{}
if UnmarshalBlock([]byte("[[][$][N][#][I][512]"), &i) == nil {
t.Errorf("expected failure but got: %v", i)
}
}

func TestFuzzUnmarshalBlock_strong_type_NoOp_object(t *testing.T) {
var i interface{}
if UnmarshalBlock([]byte("[{][$][N][#][i][1][i][4][name]"), &i) == nil {
t.Errorf("expected failure but got: %v", i)
}
}

0 comments on commit ac2a339

Please sign in to comment.