Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reject strongly typed no-op #12

Merged
merged 1 commit into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}