ruby-changes:32730
From: tenderlove <ko1@a...>
Date: Wed, 5 Feb 2014 04:18:08 +0900 (JST)
Subject: [ruby-changes:32730] tenderlove:r44809 (trunk): * ext/psych/yaml/emitter.c: merge libyaml 0.1.5
tenderlove 2014-02-05 04:18:01 +0900 (Wed, 05 Feb 2014) New Revision: 44809 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44809 Log: * ext/psych/yaml/emitter.c: merge libyaml 0.1.5 * ext/psych/yaml/loader.c: ditto * ext/psych/yaml/parser.c: ditto * ext/psych/yaml/reader.c: ditto * ext/psych/yaml/scanner.c: ditto * ext/psych/yaml/writer.c: ditto * ext/psych/yaml/yaml_private.h: ditto Modified files: trunk/ChangeLog trunk/ext/psych/yaml/emitter.c trunk/ext/psych/yaml/loader.c trunk/ext/psych/yaml/parser.c trunk/ext/psych/yaml/reader.c trunk/ext/psych/yaml/scanner.c trunk/ext/psych/yaml/writer.c trunk/ext/psych/yaml/yaml_private.h Index: ChangeLog =================================================================== --- ChangeLog (revision 44808) +++ ChangeLog (revision 44809) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Feb 5 04:16:41 2014 Aaron Patterson <aaron@t...> + + * ext/psych/yaml/emitter.c: merge libyaml 0.1.5 + * ext/psych/yaml/loader.c: ditto + * ext/psych/yaml/parser.c: ditto + * ext/psych/yaml/reader.c: ditto + * ext/psych/yaml/scanner.c: ditto + * ext/psych/yaml/writer.c: ditto + * ext/psych/yaml/yaml_private.h: ditto + Tue Feb 4 19:10:29 2014 Koichi Sasada <ko1@a...> * string.c: use long allocator names instead of numbered Index: ext/psych/yaml/yaml_private.h =================================================================== --- ext/psych/yaml/yaml_private.h (revision 44808) +++ ext/psych/yaml/yaml_private.h (revision 44809) @@ -1,6 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/yaml_private.h#L1 -#ifdef RUBY_EXTCONF_H -#include RUBY_EXTCONF_H -#endif #if HAVE_CONFIG_H #include <config.h> @@ -10,6 +7,17 @@ https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/yaml_private.h#L7 #include <assert.h> #include <limits.h> +#include <stddef.h> + +#ifndef _MSC_VER +#include <stdint.h> +#else +#ifdef _WIN64 +#define PTRDIFF_MAX _I64_MAX +#else +#define PTRDIFF_MAX INT_MAX +#endif +#endif /* * Memory management. @@ -231,9 +239,9 @@ yaml_string_join( https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/yaml_private.h#L239 (string).pointer[offset] <= (yaml_char_t) 'f') ? \ ((string).pointer[offset] - (yaml_char_t) 'a' + 10) : \ ((string).pointer[offset] - (yaml_char_t) '0')) - + #define AS_HEX(string) AS_HEX_AT((string),0) - + /* * Check if the character is ASCII. */ @@ -424,6 +432,12 @@ yaml_queue_extend(void **start, void **h https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/yaml_private.h#L432 #define STACK_EMPTY(context,stack) \ ((stack).start == (stack).top) +#define STACK_LIMIT(context,stack,size) \ + ((stack).top - (stack).start < (size) ? \ + 1 : \ + ((context)->error = YAML_MEMORY_ERROR, \ + 0)) + #define PUSH(context,stack,value) \ (((stack).top != (stack).end \ || yaml_stack_extend((void **)&(stack).start, \ Index: ext/psych/yaml/reader.c =================================================================== --- ext/psych/yaml/reader.c (revision 44808) +++ ext/psych/yaml/reader.c (revision 44809) @@ -52,7 +52,7 @@ yaml_parser_determine_encoding(yaml_pars https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/reader.c#L52 { /* Ensure that we had enough bytes in the raw buffer. */ - while (!parser->eof + while (!parser->eof && parser->raw_buffer.last - parser->raw_buffer.pointer < 3) { if (!yaml_parser_update_raw_buffer(parser)) { return 0; @@ -295,7 +295,7 @@ yaml_parser_update_buffer(yaml_parser_t https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/reader.c#L295 parser->offset, value); break; - + case YAML_UTF16LE_ENCODING: case YAML_UTF16BE_ENCODING: @@ -318,7 +318,7 @@ yaml_parser_update_buffer(yaml_parser_t https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/reader.c#L318 * * The following formulas are used for decoding * and encoding characters using surrogate pairs: - * + * * U = U' + 0x10000 (0x01 00 00 <= U <= 0x10 FF FF) * U' = yyyyyyyyyyxxxxxxxxxx (0 <= U' <= 0x0F FF FF) * W1 = 110110yyyyyyyyyy @@ -460,6 +460,10 @@ yaml_parser_update_buffer(yaml_parser_t https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/reader.c#L460 } + if (parser->offset >= PTRDIFF_MAX) + return yaml_parser_set_reader_error(parser, "input is too long", + PTRDIFF_MAX, -1); + return 1; } Index: ext/psych/yaml/loader.c =================================================================== --- ext/psych/yaml/loader.c (revision 44808) +++ ext/psych/yaml/loader.c (revision 44809) @@ -286,6 +286,8 @@ yaml_parser_load_scalar(yaml_parser_t *p https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/loader.c#L286 int index; yaml_char_t *tag = first_event->data.scalar.tag; + if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error; + if (!tag || strcmp((char *)tag, "!") == 0) { yaml_free(tag); tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SCALAR_TAG); @@ -329,6 +331,8 @@ yaml_parser_load_sequence(yaml_parser_t https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/loader.c#L331 int index, item_index; yaml_char_t *tag = first_event->data.sequence_start.tag; + if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error; + if (!tag || strcmp((char *)tag, "!") == 0) { yaml_free(tag); tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG); @@ -351,6 +355,9 @@ yaml_parser_load_sequence(yaml_parser_t https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/loader.c#L355 if (!yaml_parser_parse(parser, &event)) return 0; while (event.type != YAML_SEQUENCE_END_EVENT) { + if (!STACK_LIMIT(parser, + parser->document->nodes.start[index-1].data.sequence.items, + INT_MAX-1)) return 0; item_index = yaml_parser_load_node(parser, &event); if (!item_index) return 0; if (!PUSH(parser, @@ -387,6 +394,8 @@ yaml_parser_load_mapping(yaml_parser_t * https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/loader.c#L394 yaml_node_pair_t pair; yaml_char_t *tag = first_event->data.mapping_start.tag; + if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error; + if (!tag || strcmp((char *)tag, "!") == 0) { yaml_free(tag); tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_MAPPING_TAG); @@ -409,6 +418,9 @@ yaml_parser_load_mapping(yaml_parser_t * https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/loader.c#L418 if (!yaml_parser_parse(parser, &event)) return 0; while (event.type != YAML_MAPPING_END_EVENT) { + if (!STACK_LIMIT(parser, + parser->document->nodes.start[index-1].data.mapping.pairs, + INT_MAX-1)) return 0; pair.key = yaml_parser_load_node(parser, &event); if (!pair.key) return 0; if (!yaml_parser_parse(parser, &event)) return 0; Index: ext/psych/yaml/emitter.c =================================================================== --- ext/psych/yaml/emitter.c (revision 44808) +++ ext/psych/yaml/emitter.c (revision 44809) @@ -221,7 +221,7 @@ yaml_emitter_write_indent(yaml_emitter_t https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L221 static int yaml_emitter_write_indicator(yaml_emitter_t *emitter, - const char *indicator, int need_whitespace, + char *indicator, int need_whitespace, int is_whitespace, int is_indention); static int @@ -517,7 +517,7 @@ yaml_emitter_emit_stream_start(yaml_emit https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L517 if (emitter->best_width < 0) { emitter->best_width = INT_MAX; } - + if (!emitter->line_break) { emitter->line_break = YAML_LN_BREAK; } @@ -607,7 +607,7 @@ yaml_emitter_emit_document_start(yaml_em https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L607 if (!yaml_emitter_write_indent(emitter)) return 0; } - + if (event->data.document_start.tag_directives.start != event->data.document_start.tag_directives.end) { implicit = 0; @@ -721,7 +721,7 @@ yaml_emitter_emit_document_end(yaml_emit https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L721 } /* - * + * * Expect a flow item node. */ @@ -1402,7 +1402,7 @@ yaml_emitter_analyze_anchor(yaml_emitter https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L1402 { size_t anchor_length; yaml_string_t string; - + anchor_length = strlen((char *)anchor); STRING_ASSIGN(string, anchor, anchor_length); @@ -1493,7 +1493,7 @@ yaml_emitter_analyze_scalar(yaml_emitter https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L1493 int break_space = 0; int space_break = 0; - int preceded_by_whitespace = 0; + int preceeded_by_whitespace = 0; int followed_by_whitespace = 0; int previous_space = 0; int previous_break = 0; @@ -1524,7 +1524,7 @@ yaml_emitter_analyze_scalar(yaml_emitter https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L1524 flow_indicators = 1; } - preceded_by_whitespace = 1; + preceeded_by_whitespace = 1; followed_by_whitespace = IS_BLANKZ_AT(string, WIDTH(string)); while (string.pointer != string.end) @@ -1570,7 +1570,7 @@ yaml_emitter_analyze_scalar(yaml_emitter https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L1570 } } - if (CHECK(string, '#') && preceded_by_whitespace) { + if (CHECK(string, '#') && preceeded_by_whitespace) { flow_indicators = 1; block_indicators = 1; } @@ -1619,7 +1619,7 @@ yaml_emitter_analyze_scalar(yaml_emitter https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L1619 previous_break = 0; } - preceded_by_whitespace = IS_BLANKZ(string); + preceeded_by_whitespace = IS_BLANKZ(string); MOVE(string); if (string.pointer != string.end) { followed_by_whitespace = IS_BLANKZ_AT(string, WIDTH(string)); @@ -1784,7 +1784,7 @@ yaml_emitter_write_indent(yaml_emitter_t https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L1784 static int yaml_emitter_write_indicator(yaml_emitter_t *emitter, - const char *indicator, int need_whitespace, + char *indicator, int need_whitespace, int is_whitespace, int is_indention) { size_t indicator_length; @@ -2178,7 +2178,7 @@ yaml_emitter_write_block_scalar_hints(ya https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/emitter.c#L2178 yaml_string_t string) { char indent_hint[2]; - const char *chomp_hint = NULL; + char *chomp_hint = NULL; if (IS_SPACE(string) || IS_BREAK(string)) { Index: ext/psych/yaml/scanner.c =================================================================== --- ext/psych/yaml/scanner.c (revision 44808) +++ ext/psych/yaml/scanner.c (revision 44809) @@ -615,11 +615,11 @@ yaml_parser_decrease_flow_level(yaml_par https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L615 */ static int -yaml_parser_roll_indent(yaml_parser_t *parser, int column, - int number, yaml_token_type_t type, yaml_mark_t mark); +yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column, + ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark); static int -yaml_parser_unroll_indent(yaml_parser_t *parser, int column); +yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column); /* * Token fetchers. @@ -762,7 +762,7 @@ yaml_parser_scan(yaml_parser_t *parser, https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L762 } /* Fetch the next token from the queue. */ - + *token = DEQUEUE(parser, parser->tokens); parser->token_available = 0; parser->tokens_parsed ++; @@ -1103,7 +1103,7 @@ yaml_parser_save_simple_key(yaml_parser_ https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L1103 */ int required = (!parser->flow_level - && parser->indent == (int)parser->mark.column); + && parser->indent == (ptrdiff_t)parser->mark.column); /* * A simple key is required only when it is the first token in the current @@ -1121,7 +1121,7 @@ yaml_parser_save_simple_key(yaml_parser_ https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L1121 yaml_simple_key_t simple_key; simple_key.possible = 1; simple_key.required = required; - simple_key.token_number = + simple_key.token_number = parser->tokens_parsed + (parser->tokens.tail - parser->tokens.head); simple_key.mark = parser->mark; @@ -1176,6 +1176,11 @@ yaml_parser_increase_flow_level(yaml_par https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L1176 /* Increase the flow level. */ + if (parser->flow_level == INT_MAX) { + parser->error = YAML_MEMORY_ERROR; + return 0; + } + parser->flow_level++; return 1; @@ -1202,12 +1207,12 @@ yaml_parser_decrease_flow_level(yaml_par https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L1207 * Push the current indentation level to the stack and set the new level * the current column is greater than the indentation level. In this case, * append or insert the specified token into the token queue. - * + * */ static int -yaml_parser_roll_indent(yaml_parser_t *parser, int column, - int number, yaml_token_type_t type, yaml_mark_t mark) +yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column, + ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark) { yaml_token_t token; @@ -1226,6 +1231,11 @@ yaml_parser_roll_indent(yaml_parser_t *p https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L1231 if (!PUSH(parser, parser->indents, parser->indent)) return 0; + if (column > INT_MAX) { + parser->error = YAML_MEMORY_ERROR; + return 0; + } + parser->indent = column; /* Create a token and insert it into the queue. */ @@ -1248,13 +1258,13 @@ yaml_parser_roll_indent(yaml_parser_t *p https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L1258 /* * Pop indentation levels from the indents stack until the current level - * becomes less or equal to the column. For each indentation level, append + * becomes less or equal to the column. For each intendation level, append * the BLOCK-END token. */ static int -yaml_parser_unroll_indent(yaml_parser_t *parser, int column) +yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column) { yaml_token_t token; @@ -1263,7 +1273,7 @@ yaml_parser_unroll_indent(yaml_parser_t https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L1273 if (parser->flow_level) return 1; - /* Loop through the indentation levels in the stack. */ + /* Loop through the intendation levels in the stack. */ while (parser->indent > column) { @@ -1935,7 +1945,7 @@ yaml_parser_scan_to_next_token(yaml_pars https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L1945 * * - in the flow context; * - in the block context, but not at the beginning of the line or - * after '-', '?', or ':' (complex value). + * after '-', '?', or ':' (complex value). */ if (!CACHE(parser, 1)) return 0; @@ -2574,7 +2584,7 @@ yaml_parser_scan_tag_uri(yaml_parser_t * https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L2584 /* Resize the string to include the head. */ - while (string.end - string.start <= (int)length) { + while ((size_t)(string.end - string.start) <= length) { if (!yaml_string_extend(&string.start, &string.pointer, &string.end)) { parser->error = YAML_MEMORY_ERROR; goto error; @@ -2769,15 +2779,15 @@ yaml_parser_scan_block_scalar(yaml_parse https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L2779 if (IS_DIGIT(parser->buffer)) { - /* Check that the indentation is greater than 0. */ + /* Check that the intendation is greater than 0. */ if (CHECK(parser->buffer, '0')) { yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found an indentation indicator equal to 0"); + start_mark, "found an intendation indicator equal to 0"); goto error; } - /* Get the indentation level and eat the indicator. */ + /* Get the intendation level and eat the indicator. */ increment = AS_DIGIT(parser->buffer); @@ -2791,7 +2801,7 @@ yaml_parser_scan_block_scalar(yaml_parse https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L2801 { if (CHECK(parser->buffer, '0')) { yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found an indentation indicator equal to 0"); + start_mark, "found an intendation indicator equal to 0"); goto error; } @@ -2841,7 +2851,7 @@ yaml_parser_scan_block_scalar(yaml_parse https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L2851 end_mark = parser->mark; - /* Set the indentation level if it was specified. */ + /* Set the intendation level if it was specified. */ if (increment) { indent = parser->indent >= 0 ? parser->indent+increment : increment; @@ -2907,7 +2917,7 @@ yaml_parser_scan_block_scalar(yaml_parse https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L2917 if (!READ_LINE(parser, leading_break)) goto error; - /* Eat the following indentation spaces and line breaks. */ + /* Eat the following intendation spaces and line breaks. */ if (!yaml_parser_scan_block_scalar_breaks(parser, &indent, &trailing_breaks, start_mark, &end_mark)) goto error; @@ -2942,8 +2952,8 @@ error: https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L2952 } /* - * Scan indentation spaces and line breaks for a block scalar. Determine the - * indentation level if needed. + * Scan intendation spaces and line breaks for a block scalar. Determine the + * intendation level if needed. */ static int @@ -2955,11 +2965,11 @@ yaml_parser_scan_block_scalar_breaks(yam https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L2965 *end_mark = parser->mark; - /* Eat the indentation spaces and line breaks. */ + /* Eat the intendation spaces and line breaks. */ while (1) { - /* Eat the indentation spaces. */ + /* Eat the intendation spaces. */ if (!CACHE(parser, 1)) return 0; @@ -2972,12 +2982,12 @@ yaml_parser_scan_block_scalar_breaks(yam https://github.com/ruby/ruby/blob/trunk/ext/psych/yaml/scanner.c#L2982 if ((int)parser->mark.column > max_indent) max_indent = (int)parser->mark.column; - /* Check for a tab character messing the indentation. */ + /* Check for a tab character messing the intendation. */ if ((!*indent || (int)parser->mark.column < *indent) && IS_TAB(parser->buffer)) { return yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found a tab character where an indentation space is expected"); + start_mark, "found a tab character where an intendation space is expected"); } /* Have we found a (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/