Skip to content

Commit 8f96da9

Browse files
committed
Explicitly check the parser for errors on peek
It's curious choice from the underlying API to generally return a positive result on success, but on this case return true in an error scenario. Fixes go-yaml#666
1 parent 539c8e7 commit 8f96da9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

decode.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ func (p *parser) peek() yaml_event_type_t {
100100
if p.event.typ != yaml_NO_EVENT {
101101
return p.event.typ
102102
}
103-
if !yaml_parser_parse(&p.parser, &p.event) {
103+
// It's curious choice from the underlying API to generally return a
104+
// positive result on success, but on this case return true in an error
105+
// scenario. This was the source of bugs in the past (issue #666).
106+
if !yaml_parser_parse(&p.parser, &p.event) || p.parser.error != yaml_NO_ERROR {
104107
p.fail()
105108
}
106109
return p.event.typ

decode_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ var unmarshalErrorTests = []struct {
947947
{"%TAG !%79! tag:yaml.org,2002:\n---\nv: !%79!int '1'", "yaml: did not find expected whitespace"},
948948
{"a:\n 1:\nb\n 2:", ".*could not find expected ':'"},
949949
{"a: 1\nb: 2\nc 2\nd: 3\n", "^yaml: line 3: could not find expected ':'$"},
950+
{"0: [:!00 \xef", "yaml: incomplete UTF-8 octet sequence"}, // Issue #666
950951
{
951952
"a: &a [00,00,00,00,00,00,00,00,00]\n" +
952953
"b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]\n" +

0 commit comments

Comments
 (0)