[HarfBuzz] harfbuzz: Branch 'master' - 2 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Thu Jul 10 16:40:57 PDT 2014


 src/hb-utf-private.hh  |   42 ++++++++++++++++++++++++++++--------------
 test/api/test-buffer.c |    1 +
 2 files changed, 29 insertions(+), 14 deletions(-)

New commits:
commit 6f13b6d62daae4989e3cc2fe4b168e5c59650964
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Jul 10 19:31:40 2014 -0400

    When parsing UTF-16, generate invalid codepoint for lonely low surrogate
    
    Test passes now.

diff --git a/src/hb-utf-private.hh b/src/hb-utf-private.hh
index b9a6519..11f23cc 100644
--- a/src/hb-utf-private.hh
+++ b/src/hb-utf-private.hh
@@ -121,20 +121,27 @@ hb_utf_next (const uint16_t *text,
 {
   hb_codepoint_t c = *text++;
 
-  if (unlikely (hb_in_range<hb_codepoint_t> (c, 0xd800, 0xdbff)))
+  if (likely (!hb_in_range<hb_codepoint_t> (c, 0xd800, 0xdfff)))
   {
-    /* high surrogate */
+    *unicode = c;
+    return text;
+  }
+
+  if (likely (hb_in_range<hb_codepoint_t> (c, 0xd800, 0xdbff)))
+  {
+    /* High-surrogate in c */
     hb_codepoint_t l;
     if (text < end && ((l = *text), likely (hb_in_range<hb_codepoint_t> (l, 0xdc00, 0xdfff))))
     {
-      /* low surrogate */
+      /* Low-surrogate in l */
       *unicode = (c << 10) + l - ((0xd800 << 10) - 0x10000 + 0xdc00);
        text++;
-    } else
-      *unicode = -1;
-  } else
-    *unicode = c;
+       return text;
+    }
+  }
 
+  /* Lonely / out-of-order surrogate. */
+  *unicode = -1;
   return text;
 }
 
@@ -145,20 +152,27 @@ hb_utf_prev (const uint16_t *text,
 {
   hb_codepoint_t c = *--text;
 
-  if (unlikely (hb_in_range<hb_codepoint_t> (c, 0xdc00, 0xdfff)))
+  if (likely (!hb_in_range<hb_codepoint_t> (c, 0xd800, 0xdfff)))
   {
-    /* low surrogate */
+    *unicode = c;
+    return text;
+  }
+
+  if (likely (hb_in_range<hb_codepoint_t> (c, 0xdc00, 0xdfff)))
+  {
+    /* Low-surrogate in c */
     hb_codepoint_t h;
     if (start < text && ((h = *(text - 1)), likely (hb_in_range<hb_codepoint_t> (h, 0xd800, 0xdbff))))
     {
-      /* high surrogate */
+      /* High-surrogate in h */
       *unicode = (h << 10) + c - ((0xd800 << 10) - 0x10000 + 0xdc00);
        text--;
-    } else
-      *unicode = -1;
-  } else
-    *unicode = c;
+       return text;
+    }
+  }
 
+  /* Lonely / out-of-order surrogate. */
+  *unicode = -1;
   return text;
 }
 
commit 24b2ba9dfa7c35769cd843a07079ef88fa594bf8
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Thu Jul 10 19:31:16 2014 -0400

    [test-buffer] Add test for lonely low-surrogate
    
    Currenty fails.  Ouch!

diff --git a/test/api/test-buffer.c b/test/api/test-buffer.c
index 13465ef..0b70cf9 100644
--- a/test/api/test-buffer.c
+++ b/test/api/test-buffer.c
@@ -704,6 +704,7 @@ static const utf16_conversion_test_t utf16_conversion_tests[] = {
   {{0x41, 0xD800, 0xDF02}, {-1}},
   {{0x41, 0x61, 0xD800, 0xDF02}, {0x61, -1}},
   {{0x41, 0xD800, 0x61, 0xDF02}, {-1, 0x61}},
+  {{0x41, 0xDF00, 0x61}, {-1}},
   {{0x41, 0x61}, {0}}
 };
 


More information about the HarfBuzz mailing list