[Groonga-commit] groonga/groonga-normalizer-mysql at e461388 [master] Fix a crash bug when weight is 0

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jul 31 22:33:09 JST 2014


Kouhei Sutou	2014-07-31 22:33:09 +0900 (Thu, 31 Jul 2014)

  New Revision: e4613880566cc47d994030b2c9b9efb543bc012f
  https://github.com/groonga/groonga-normalizer-mysql/commit/e4613880566cc47d994030b2c9b9efb543bc012f

  Message:
    Fix a crash bug when weight is 0
    
    [groonga-dev,02534]
    
    Reported by GMO Media, Inc.. Thanks!!!

  Added files:
    test/suite/unicode_ci/zero_weight.expected
    test/suite/unicode_ci/zero_weight.test
    test/suite/unicode_ci_except_kana_ci_kana_with_voiced_sound_mark/zero_weight.expected
    test/suite/unicode_ci_except_kana_ci_kana_with_voiced_sound_mark/zero_weight.test
  Modified files:
    normalizers/mysql.c

  Modified: normalizers/mysql.c (+13 -8)
===================================================================
--- normalizers/mysql.c    2014-07-31 22:10:08 +0900 (db0d000)
+++ normalizers/mysql.c    2014-07-31 22:33:09 +0900 (94acfb1)
@@ -191,11 +191,14 @@ normalize_character(const char *utf8, int character_length,
     uint32_t normalized_code;
     unsigned int n_bytes;
     normalized_code = normalize_table[page][low_code];
-    if (normalized_code != 0) {
+    if (normalized_code == 0x00000) {
+      *normalized_character_length = 0;
+    } else {
       n_bytes = unichar_to_utf8(normalized_code,
                                 normalized + *normalized_length_in_bytes);
       *normalized_character_length = n_bytes;
       *normalized_length_in_bytes += n_bytes;
+      (*normalized_n_characters)++;
     }
   } else {
     int i;
@@ -204,8 +207,8 @@ normalize_character(const char *utf8, int character_length,
     }
     *normalized_character_length = character_length;
     *normalized_length_in_bytes += character_length;
+    (*normalized_n_characters)++;
   }
-  (*normalized_n_characters)++;
 }
 
 static void
@@ -366,7 +369,7 @@ normalize(grn_ctx *ctx, grn_obj *string,
                             &normalized_length_in_bytes,
                             &normalized_n_characters);
       }
-      if (current_type) {
+      if (current_type && normalized_character_length > 0) {
         char *current_normalized;
         current_normalized =
           normalized + normalized_length_in_bytes - normalized_character_length;
@@ -375,14 +378,16 @@ normalize(grn_ctx *ctx, grn_obj *string,
         current_type++;
       }
       if (current_check) {
-        unsigned int i;
         current_check[0] += character_length;
-        current_check++;
-        for (i = 1; i < normalized_character_length; i++) {
-          current_check[0] = 0;
+        if (normalized_character_length > 0) {
+          unsigned int i;
           current_check++;
+          for (i = 1; i < normalized_character_length; i++) {
+            current_check[0] = 0;
+            current_check++;
+          }
+          current_check[0] = 0;
         }
-        current_check[0] = 0;
       }
     }
 

  Added: test/suite/unicode_ci/zero_weight.expected (+25 -0) 100644
===================================================================
--- /dev/null
+++ test/suite/unicode_ci/zero_weight.expected    2014-07-31 22:33:09 +0900 (b9125a3)
@@ -0,0 +1,25 @@
+register normalizers/mysql
+[[0,0.0,0.0],true]
+normalize NormalizerMySQLUnicodeCI "a゙あ゙z" WITH_CHECKS|WITH_TYPES
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  {
+    "normalized": "AあZ",
+    "types": [
+      "alpha",
+      "hiragana",
+      "alpha"
+    ],
+    "checks": [
+      1,
+      6,
+      0,
+      0,
+      4
+    ]
+  }
+]

  Added: test/suite/unicode_ci/zero_weight.test (+3 -0) 100644
===================================================================
--- /dev/null
+++ test/suite/unicode_ci/zero_weight.test    2014-07-31 22:33:09 +0900 (5e3b2e3)
@@ -0,0 +1,3 @@
+register normalizers/mysql
+
+normalize NormalizerMySQLUnicodeCI "a゙あ゙z" WITH_CHECKS|WITH_TYPES

  Added: test/suite/unicode_ci_except_kana_ci_kana_with_voiced_sound_mark/zero_weight.expected (+25 -0) 100644
===================================================================
--- /dev/null
+++ test/suite/unicode_ci_except_kana_ci_kana_with_voiced_sound_mark/zero_weight.expected    2014-07-31 22:33:09 +0900 (62472be)
@@ -0,0 +1,25 @@
+register normalizers/mysql
+[[0,0.0,0.0],true]
+normalize NormalizerMySQLUnicodeCIExceptKanaCIKanaWithVoicedSoundMark   "a゙あ゙z" WITH_CHECKS|WITH_TYPES
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  {
+    "normalized": "AあZ",
+    "types": [
+      "alpha",
+      "hiragana",
+      "alpha"
+    ],
+    "checks": [
+      1,
+      6,
+      0,
+      0,
+      4
+    ]
+  }
+]

  Added: test/suite/unicode_ci_except_kana_ci_kana_with_voiced_sound_mark/zero_weight.test (+4 -0) 100644
===================================================================
--- /dev/null
+++ test/suite/unicode_ci_except_kana_ci_kana_with_voiced_sound_mark/zero_weight.test    2014-07-31 22:33:09 +0900 (1ca2089)
@@ -0,0 +1,4 @@
+register normalizers/mysql
+
+normalize NormalizerMySQLUnicodeCIExceptKanaCIKanaWithVoicedSoundMark \
+  "a゙あ゙z" WITH_CHECKS|WITH_TYPES
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index