From 1dfc095ba0b8366ff95f2cd3e04119412cdf8041 Mon Sep 17 00:00:00 2001 From: Thibault Normand Date: Tue, 10 May 2022 17:56:50 +0200 Subject: [PATCH] fix(decoder): panic raised on fuzzer inputs. Handle yaml_NO_EVENT event type to raise a parsing error vs panic. ref #833 Signed-off-by: Thibault Normand --- decode.go | 3 +++ decode_test.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/decode.go b/decode.go index 0173b698..9936989f 100644 --- a/decode.go +++ b/decode.go @@ -162,6 +162,9 @@ func (p *parser) parse() *Node { return nil case yaml_TAIL_COMMENT_EVENT: panic("internal error: unexpected tail comment event (please report)") + case yaml_NO_EVENT: + failf("unable to build a node from none event") + return nil default: panic("internal error: attempted to parse unknown event (please report): " + p.event.typ.String()) } diff --git a/decode_test.go b/decode_test.go index 72a8e465..446be0c4 100644 --- a/decode_test.go +++ b/decode_test.go @@ -933,6 +933,8 @@ func (s *S) TestUnmarshalDurationInt(c *C) { var unmarshalErrorTests = []struct { data, error string }{ + {"! !00 \xf6", "yaml: unable to build a node from none event"}, + {"! !!0 \xf7", "yaml: unable to build a node from none event"}, {"v: !!float 'error'", "yaml: cannot decode !!str `error` as a !!float"}, {"v: [A,", "yaml: line 1: did not find expected node content"}, {"v:\n- [A,", "yaml: line 2: did not find expected node content"}, @@ -1436,6 +1438,7 @@ func (s *S) TestMergeStruct(c *C) { } } +<<<<<<< HEAD var mergeTestsNested = ` mergeouter1: &mergeouter1 d: 40 @@ -1529,6 +1532,8 @@ func (s *S) TestMergeNestedStruct(c *C) { c.Assert(testm["outer"], DeepEquals, wantm) } +======= +>>>>>>> bd18f34 (fix(decoder): panic raised on fuzzer inputs.) var unmarshalNullTests = []struct { input string pristine, expected func() interface{}