@@ -612,30 +612,28 @@ re_parse_char_escape (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context
612612#if ENABLED (JERRY_ES2015 )
613613 if (re_ctx_p -> flags & RE_FLAG_UNICODE )
614614 {
615- if (* re_ctx_p -> input_curr_p == LIT_CHAR_LEFT_BRACE )
615+ if (re_ctx_p -> input_curr_p + 1 < re_ctx_p -> input_end_p
616+ && re_ctx_p -> input_curr_p [0 ] == LIT_CHAR_LEFT_BRACE
617+ && lit_char_is_hex_digit (re_ctx_p -> input_curr_p [1 ]))
616618 {
617- re_ctx_p -> input_curr_p ++ ;
619+ lit_code_point_t cp = lit_char_hex_to_int (re_ctx_p -> input_curr_p [1 ]);
620+ re_ctx_p -> input_curr_p += 2 ;
618621
619- if (re_ctx_p -> input_curr_p < re_ctx_p -> input_end_p && lit_char_is_hex_digit (* re_ctx_p -> input_curr_p ))
622+ while (re_ctx_p -> input_curr_p < re_ctx_p -> input_end_p && lit_char_is_hex_digit (* re_ctx_p -> input_curr_p ))
620623 {
621- lit_code_point_t cp = lit_char_hex_to_int (* re_ctx_p -> input_curr_p ++ );
624+ cp = cp * 16 + lit_char_hex_to_int (* re_ctx_p -> input_curr_p ++ );
622625
623- while ( re_ctx_p -> input_curr_p < re_ctx_p -> input_end_p && lit_char_is_hex_digit ( * re_ctx_p -> input_curr_p ))
626+ if ( JERRY_UNLIKELY ( cp > LIT_UNICODE_CODE_POINT_MAX ))
624627 {
625- cp = cp * 16 + lit_char_hex_to_int (* re_ctx_p -> input_curr_p ++ );
626-
627- if (JERRY_UNLIKELY (cp > LIT_UNICODE_CODE_POINT_MAX ))
628- {
629- return ecma_raise_syntax_error (ECMA_ERR_MSG ("Invalid unicode escape sequence" ));
630- }
628+ return ecma_raise_syntax_error (ECMA_ERR_MSG ("Invalid unicode escape sequence" ));
631629 }
630+ }
632631
633- if (re_ctx_p -> input_curr_p < re_ctx_p -> input_end_p && * re_ctx_p -> input_curr_p == LIT_CHAR_RIGHT_BRACE )
634- {
635- re_ctx_p -> input_curr_p ++ ;
636- re_ctx_p -> token .value = cp ;
637- break ;
638- }
632+ if (re_ctx_p -> input_curr_p < re_ctx_p -> input_end_p && * re_ctx_p -> input_curr_p == LIT_CHAR_RIGHT_BRACE )
633+ {
634+ re_ctx_p -> input_curr_p ++ ;
635+ re_ctx_p -> token .value = cp ;
636+ break ;
639637 }
640638 }
641639
@@ -867,7 +865,8 @@ re_parse_next_token (re_compiler_ctx_t *re_ctx_p) /**< RegExp compiler context *
867865
868866#if ENABLED (JERRY_ES2015 )
869867 if (re_ctx_p -> flags & RE_FLAG_UNICODE
870- && lit_is_code_point_utf16_high_surrogate (ch ))
868+ && lit_is_code_point_utf16_high_surrogate (ch )
869+ && re_ctx_p -> input_curr_p < re_ctx_p -> input_end_p )
871870 {
872871 const ecma_char_t next = lit_cesu8_peek_next (re_ctx_p -> input_curr_p );
873872 if (lit_is_code_point_utf16_low_surrogate (next ))
0 commit comments