[前][次][番号順一覧][スレッド一覧]

ruby-changes:35141

From: nagachika <ko1@a...>
Date: Wed, 20 Aug 2014 00:03:44 +0900 (JST)
Subject: [ruby-changes:35141] nagachika:r47223 (ruby_2_1): merge r46831 partially. extracted commits are as follows.

nagachika	2014-08-20 00:03:26 +0900 (Wed, 20 Aug 2014)

  New Revision: 47223

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47223

  Log:
    merge r46831 partially. extracted commits are as follows.
    https://github.com/k-takata/Onigmo/commit/b9fba1dc63ccb42a86e934011b468e6022fabb74
    https://github.com/k-takata/Onigmo/commit/c1fc76b9bd463948ffc5058bc352bf93732f0314
    https://github.com/k-takata/Onigmo/commit/a0efc0a200f7108ca3d5ac3039c8f952e0051619
    https://github.com/k-takata/Onigmo/commit/c7cda4ed5676167b0d01bb5555724f6164fbdb13
    [Bug #8716]
    
    * include/ruby/oniguruma.h (ONIG_MAX_CAPTURE_GROUP_NUM,
      ONIGERR_TOO_MANY_CAPTURE_GROUPS): add cheking the number of capture
      groups.
    
    * regerror.c (onig_error_code_to_format): ditto.
    
    * regparse.c (scan_env_add_mem_entry): ditto.
    
    * regexec.c (onig_region_copy, match_at): fix: segmation fault occurs
      when many groups are used.

  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/include/ruby/oniguruma.h
    branches/ruby_2_1/regerror.c
    branches/ruby_2_1/regexec.c
    branches/ruby_2_1/regparse.c
    branches/ruby_2_1/version.h
Index: ruby_2_1/regparse.c
===================================================================
--- ruby_2_1/regparse.c	(revision 47222)
+++ ruby_2_1/regparse.c	(revision 47223)
@@ -978,6 +978,8 @@ scan_env_add_mem_entry(ScanEnv* env) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/regparse.c#L978
   Node** p;
 
   need = env->num_mem + 1;
+  if (need > ONIG_MAX_CAPTURE_GROUP_NUM)
+    return ONIGERR_TOO_MANY_CAPTURE_GROUPS;
   if (need >= SCANENV_MEMNODES_SIZE) {
     if (env->mem_alloc <= need) {
       if (IS_NULL(env->mem_nodes_dynamic)) {
Index: ruby_2_1/include/ruby/oniguruma.h
===================================================================
--- ruby_2_1/include/ruby/oniguruma.h	(revision 47222)
+++ ruby_2_1/include/ruby/oniguruma.h	(revision 47223)
@@ -338,6 +338,7 @@ int onigenc_str_bytelen_null P_((OnigEnc https://github.com/ruby/ruby/blob/trunk/ruby_2_1/include/ruby/oniguruma.h#L338
 /* config parameters */
 #define ONIG_NREGION                          10
 #define ONIG_MAX_BACKREF_NUM                1000
+#define ONIG_MAX_CAPTURE_GROUP_NUM         32767
 #define ONIG_MAX_REPEAT_NUM               100000
 #define ONIG_MAX_MULTI_BYTE_RANGES_NUM     10000
 /* constants */
@@ -582,6 +583,7 @@ ONIG_EXTERN const OnigSyntaxType*   Onig https://github.com/ruby/ruby/blob/trunk/ruby_2_1/include/ruby/oniguruma.h#L583
 #define ONIGERR_NEVER_ENDING_RECURSION                       -221
 #define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY        -222
 #define ONIGERR_INVALID_CHAR_PROPERTY_NAME                   -223
+#define ONIGERR_TOO_MANY_CAPTURE_GROUPS                      -224
 #define ONIGERR_INVALID_CODE_POINT_VALUE                     -400
 #define ONIGERR_INVALID_WIDE_CHAR_VALUE                      -400
 #define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE                      -401
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 47222)
+++ ruby_2_1/ChangeLog	(revision 47223)
@@ -1,3 +1,23 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Tue Aug 19 23:31:48 2014  CHIKANAGA Tomoyuki  <nagachika@r...>
+
+	merge r46831 partially. extracted commits are as follows.
+	https://github.com/k-takata/Onigmo/commit/b9fba1dc63ccb42a86e934011b468e6022fabb74
+	https://github.com/k-takata/Onigmo/commit/c1fc76b9bd463948ffc5058bc352bf93732f0314
+	https://github.com/k-takata/Onigmo/commit/a0efc0a200f7108ca3d5ac3039c8f952e0051619
+	https://github.com/k-takata/Onigmo/commit/c7cda4ed5676167b0d01bb5555724f6164fbdb13
+	[Bug #8716]
+
+	* include/ruby/oniguruma.h (ONIG_MAX_CAPTURE_GROUP_NUM,
+	  ONIGERR_TOO_MANY_CAPTURE_GROUPS): add cheking the number of capture
+	  groups.
+
+	* regerror.c (onig_error_code_to_format): ditto.
+
+	* regparse.c (scan_env_add_mem_entry): ditto.
+
+	* regexec.c (onig_region_copy, match_at): fix: segmation fault occurs
+	  when many groups are used.
+
 Mon Aug 18 23:38:21 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* encoding.c (enc_find): [DOC] never accepted a symbol.
Index: ruby_2_1/regerror.c
===================================================================
--- ruby_2_1/regerror.c	(revision 47222)
+++ ruby_2_1/regerror.c	(revision 47223)
@@ -133,6 +133,8 @@ onig_error_code_to_format(OnigPosition c https://github.com/ruby/ruby/blob/trunk/ruby_2_1/regerror.c#L133
     p = "too short multibyte code string"; break;
   case ONIGERR_TOO_BIG_BACKREF_NUMBER:
     p = "too big backref number"; break;
+  case ONIGERR_TOO_MANY_CAPTURE_GROUPS:
+    p = "too many capture groups are specified"; break;
   case ONIGERR_INVALID_BACKREF:
 #ifdef USE_NAMED_GROUP
     p = "invalid backref number/name"; break;
Index: ruby_2_1/regexec.c
===================================================================
--- ruby_2_1/regexec.c	(revision 47222)
+++ ruby_2_1/regexec.c	(revision 47223)
@@ -444,9 +444,26 @@ onig_region_copy(OnigRegion* to, OnigReg https://github.com/ruby/ruby/blob/trunk/ruby_2_1/regexec.c#L444
 
 
 
-#define STACK_INIT(alloc_addr, ptr_num, stack_num)  do {\
-  if (msa->stack_p) {\
+#define MAX_PTR_NUM 100
+
+#define STACK_INIT(alloc_addr, heap_addr, ptr_num, stack_num)  do {\
+  if (ptr_num > MAX_PTR_NUM) {\
+    alloc_addr = (char* )xmalloc(sizeof(OnigStackIndex) * (ptr_num));\
+    heap_addr  = alloc_addr;\
+    if (msa->stack_p) {\
+      stk_alloc = (OnigStackType* )(msa->stack_p);\
+      stk_base  = stk_alloc;\
+      stk       = stk_base;\
+      stk_end   = stk_base + msa->stack_n;\
+    } else {\
+      stk_alloc = (OnigStackType* )xalloca(sizeof(OnigStackType) * (stack_num));\
+      stk_base  = stk_alloc;\
+      stk       = stk_base;\
+      stk_end   = stk_base + (stack_num);\
+    }\
+  } else if (msa->stack_p) {\
     alloc_addr = (char* )xalloca(sizeof(OnigStackIndex) * (ptr_num));\
+    heap_addr  = NULL;\
     stk_alloc  = (OnigStackType* )(msa->stack_p);\
     stk_base   = stk_alloc;\
     stk        = stk_base;\
@@ -455,6 +472,7 @@ onig_region_copy(OnigRegion* to, OnigReg https://github.com/ruby/ruby/blob/trunk/ruby_2_1/regexec.c#L472
   else {\
     alloc_addr = (char* )xalloca(sizeof(OnigStackIndex) * (ptr_num)\
 		       + sizeof(OnigStackType) * (stack_num));\
+    heap_addr  = NULL;\
     stk_alloc  = (OnigStackType* )(alloc_addr + sizeof(OnigStackIndex) * (ptr_num));\
     stk_base   = stk_alloc;\
     stk        = stk_base;\
@@ -529,7 +547,11 @@ stack_double(OnigStackType** arg_stk_bas https://github.com/ruby/ruby/blob/trunk/ruby_2_1/regexec.c#L547
 #define STACK_ENSURE(n)	do {\
   if (stk_end - stk < (n)) {\
     int r = stack_double(&stk_base, &stk_end, &stk, stk_alloc, msa);\
-    if (r != 0) { STACK_SAVE; return r; } \
+    if (r != 0) {\
+      STACK_SAVE;\
+      if (xmalloc_base) xfree(xmalloc_base);\
+      return r;\
+    }\
   }\
 } while(0)
 
@@ -1325,6 +1347,7 @@ match_at(regex_t* reg, const UChar* str, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/regexec.c#L1347
   UChar *p = reg->p;
   UChar *pkeep;
   char *alloca_base;
+  char *xmalloc_base = NULL;
   OnigStackType *stk_alloc, *stk_base, *stk, *stk_end;
   OnigStackType *stkp; /* used as any purpose. */
   OnigStackIndex si;
@@ -1340,7 +1363,7 @@ match_at(regex_t* reg, const UChar* str, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/regexec.c#L1363
   /* Stack #0 is used to store the pattern itself and used for (?R), \g<0>, etc. */
   n = reg->num_repeat + (reg->num_mem + 1) * 2;
 
-  STACK_INIT(alloca_base, n, INIT_MATCH_STACK_SIZE);
+  STACK_INIT(alloca_base, xmalloc_base, n, INIT_MATCH_STACK_SIZE);
   pop_level = reg->stack_pop_level;
   num_mem = reg->num_mem;
   repeat_stk = (OnigStackIndex* )alloca_base;
@@ -1354,7 +1377,7 @@ match_at(regex_t* reg, const UChar* str, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/regexec.c#L1377
   /* Stack #0 not is used. */
   n = reg->num_repeat + reg->num_mem * 2;
 
-  STACK_INIT(alloca_base, n, INIT_MATCH_STACK_SIZE);
+  STACK_INIT(alloca_base, xmalloc_base, n, INIT_MATCH_STACK_SIZE);
   pop_level = reg->stack_pop_level;
   num_mem = reg->num_mem;
   repeat_stk = (OnigStackIndex* )alloca_base;
@@ -2916,20 +2939,24 @@ match_at(regex_t* reg, const UChar* str, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/regexec.c#L2939
 
  finish:
   STACK_SAVE;
+  if (xmalloc_base) xfree(xmalloc_base);
   return best_len;
 
 #ifdef ONIG_DEBUG
  stack_error:
   STACK_SAVE;
+  if (xmalloc_base) xfree(xmalloc_base);
   return ONIGERR_STACK_BUG;
 #endif
 
  bytecode_error:
   STACK_SAVE;
+  if (xmalloc_base) xfree(xmalloc_base);
   return ONIGERR_UNDEFINED_BYTECODE;
 
  unexpected_bytecode_error:
   STACK_SAVE;
+  if (xmalloc_base) xfree(xmalloc_base);
   return ONIGERR_UNEXPECTED_BYTECODE;
 }
 
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 47222)
+++ ruby_2_1/version.h	(revision 47223)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
-#define RUBY_RELEASE_DATE "2014-08-18"
-#define RUBY_PATCHLEVEL 202
+#define RUBY_RELEASE_DATE "2014-08-20"
+#define RUBY_PATCHLEVEL 203
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 8
-#define RUBY_RELEASE_DAY 18
+#define RUBY_RELEASE_DAY 20
 
 #include "ruby/version.h"
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]