Skip to content

Commit c201bf6

Browse files
committed
Guard against overflows in indent and flow_level.
1 parent bb8ab82 commit c201bf6

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/scanner.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,11 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser);
615615
*/
616616

617617
static int
618-
yaml_parser_roll_indent(yaml_parser_t *parser, int column,
619-
int number, yaml_token_type_t type, yaml_mark_t mark);
618+
yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column,
619+
ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark);
620620

621621
static int
622-
yaml_parser_unroll_indent(yaml_parser_t *parser, int column);
622+
yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column);
623623

624624
/*
625625
* Token fetchers.
@@ -1103,7 +1103,7 @@ yaml_parser_save_simple_key(yaml_parser_t *parser)
11031103
*/
11041104

11051105
int required = (!parser->flow_level
1106-
&& parser->indent == (int)parser->mark.column);
1106+
&& parser->indent == (ptrdiff_t)parser->mark.column);
11071107

11081108
/*
11091109
* A simple key is required only when it is the first token in the current
@@ -1176,6 +1176,9 @@ yaml_parser_increase_flow_level(yaml_parser_t *parser)
11761176

11771177
/* Increase the flow level. */
11781178

1179+
if (parser->flow_level == INT_MAX)
1180+
return 0;
1181+
11791182
parser->flow_level++;
11801183

11811184
return 1;
@@ -1206,8 +1209,8 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser)
12061209
*/
12071210

12081211
static int
1209-
yaml_parser_roll_indent(yaml_parser_t *parser, int column,
1210-
int number, yaml_token_type_t type, yaml_mark_t mark)
1212+
yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column,
1213+
ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark)
12111214
{
12121215
yaml_token_t token;
12131216

@@ -1226,6 +1229,9 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column,
12261229
if (!PUSH(parser, parser->indents, parser->indent))
12271230
return 0;
12281231

1232+
if (column > INT_MAX)
1233+
return 0;
1234+
12291235
parser->indent = column;
12301236

12311237
/* Create a token and insert it into the queue. */
@@ -1254,7 +1260,7 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column,
12541260

12551261

12561262
static int
1257-
yaml_parser_unroll_indent(yaml_parser_t *parser, int column)
1263+
yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column)
12581264
{
12591265
yaml_token_t token;
12601266

src/yaml_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <assert.h>
99
#include <limits.h>
10+
#include <stddef.h>
1011

1112
/*
1213
* Memory management.

0 commit comments

Comments
 (0)