Skip to content

Commit f6f7691

Browse files
committed
The Billion Dollar Mistake
To be fair, it only happens here because this is a C-style API that was converted to Go but keeping its general shape. The proper fix, to be done eventually, is to replace all these boolean error flags by proper error types. Fixes go-yaml#665
1 parent 00bbc09 commit f6f7691

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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+
{"#\n-\n{", "yaml: line 3: could not find expected ':'"}, // Issue #665
950951
{"0: [:!00 \xef", "yaml: incomplete UTF-8 octet sequence"}, // Issue #666
951952
{
952953
"a: &a [00,00,00,00,00,00,00,00,00]\n" +

parserc.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,9 @@ func yaml_parser_parse_node(parser *yaml_parser_t, event *yaml_event_t, block, i
687687
func yaml_parser_parse_block_sequence_entry(parser *yaml_parser_t, event *yaml_event_t, first bool) bool {
688688
if first {
689689
token := peek_token(parser)
690+
if token == nil {
691+
return false
692+
}
690693
parser.marks = append(parser.marks, token.start_mark)
691694
skip_token(parser)
692695
}
@@ -786,7 +789,7 @@ func yaml_parser_split_stem_comment(parser *yaml_parser_t, stem_len int) {
786789
}
787790

788791
token := peek_token(parser)
789-
if token.typ != yaml_BLOCK_SEQUENCE_START_TOKEN && token.typ != yaml_BLOCK_MAPPING_START_TOKEN {
792+
if token == nil || token.typ != yaml_BLOCK_SEQUENCE_START_TOKEN && token.typ != yaml_BLOCK_MAPPING_START_TOKEN {
790793
return
791794
}
792795

@@ -813,6 +816,9 @@ func yaml_parser_split_stem_comment(parser *yaml_parser_t, stem_len int) {
813816
func yaml_parser_parse_block_mapping_key(parser *yaml_parser_t, event *yaml_event_t, first bool) bool {
814817
if first {
815818
token := peek_token(parser)
819+
if token == nil {
820+
return false
821+
}
816822
parser.marks = append(parser.marks, token.start_mark)
817823
skip_token(parser)
818824
}
@@ -922,6 +928,9 @@ func yaml_parser_parse_block_mapping_value(parser *yaml_parser_t, event *yaml_ev
922928
func yaml_parser_parse_flow_sequence_entry(parser *yaml_parser_t, event *yaml_event_t, first bool) bool {
923929
if first {
924930
token := peek_token(parser)
931+
if token == nil {
932+
return false
933+
}
925934
parser.marks = append(parser.marks, token.start_mark)
926935
skip_token(parser)
927936
}

0 commit comments

Comments
 (0)