Skip to content

Commit

Permalink
fix(decoder): panic raised on fuzzer inputs.
Browse files Browse the repository at this point in the history
Handle yaml_NO_EVENT event type to raise a parsing
error vs panic.

ref go-yaml#833

Signed-off-by: Thibault Normand <me@zenithar.org>
  • Loading branch information
Zenithar committed May 23, 2022
1 parent 00bbc09 commit 1dfc095
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
5 changes: 5 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -1436,6 +1438,7 @@ func (s *S) TestMergeStruct(c *C) {
}
}

<<<<<<< HEAD
var mergeTestsNested = `
mergeouter1: &mergeouter1
d: 40
Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit 1dfc095

Please sign in to comment.