فهرست منبع

Merge pull request #7558 from emuharemagic/hpcc13883

HPCC-13883 ulUnicodeLocaleEditDistanceWithinRadius can access uninitialized data

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 10 سال پیش
والد
کامیت
8fb2a6a266
1فایلهای تغییر یافته به همراه5 افزوده شده و 8 حذف شده
  1. 5 8
      plugins/unicodelib/unicodelib.cpp

+ 5 - 8
plugins/unicodelib/unicodelib.cpp

@@ -614,14 +614,6 @@ unsigned unicodeEditDistanceV4(UnicodeString & left, UnicodeString & right, unsi
     unsigned leftLen = left.length();
     unsigned rightLen = right.length();
 
-    // this shortcut is not applicable in the bi mode because unicode characters could take more than 2 UChars
-    if (!bi)
-    {
-        unsigned minED = (leftLen < rightLen)? rightLen - leftLen: leftLen - rightLen;
-        if (minED > radius)
-            return minED>255?255:minED;
-    }
-
     if (leftLen > 255)
         leftLen = 255;
 
@@ -640,9 +632,14 @@ unsigned unicodeEditDistanceV4(UnicodeString & left, UnicodeString & right, unsi
     if (leftCs.isInvalid() || rightCs.isInvalid())
         return DISTANCE_ON_ERROR;
 
+    // get Unicode character lengths
     leftLen = leftCs.length();
     rightLen = rightCs.length();
 
+    unsigned minED = (leftLen < rightLen)? rightLen - leftLen: leftLen - rightLen;
+    if (minED > radius)
+        return minED;
+
     /*
     This function applies two optimizations over the function above.
     a) Adding a character (next row) can at most decrease the edit distance by 1, so short circuit when