From eacc176f53bc09244ee5d7d4b272d9c4fc248abd Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Mon, 19 Feb 2018 10:20:55 -0600 Subject: [PATCH] reject strongly typed no-op --- decode.go | 6 ++++++ decode_test.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/decode.go b/decode.go index 0664c5a..33ea47d 100644 --- a/decode.go +++ b/decode.go @@ -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) @@ -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) diff --git a/decode_test.go b/decode_test.go index 00f3090..ed517eb 100644 --- a/decode_test.go +++ b/decode_test.go @@ -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) + } +}