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

Behdad Esfahbod behdad at kemper.freedesktop.org
Sat Nov 24 15:18:20 UTC 2018


 src/hb-aat-layout-trak-table.hh                                                    |    1 
 src/hb-dsalgs.hh                                                                   |   29 ++++++++--
 src/hb-open-file.hh                                                                |    9 ---
 src/hb-open-type.hh                                                                |   28 +++++----
 src/hb-ot-layout-common.hh                                                         |   10 ---
 src/hb-set.hh                                                                      |    6 +-
 src/hb-vector.hh                                                                   |    6 +-
 test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5634620935110656 |binary
 test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5716208469409792 |binary
 9 files changed, 51 insertions(+), 38 deletions(-)

New commits:
commit 4a3b20738fca3231e5d9a36adba333b5bce05f4a
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Nov 24 10:17:59 2018 -0500

    [trak] Coment

diff --git a/src/hb-aat-layout-trak-table.hh b/src/hb-aat-layout-trak-table.hh
index 91c0f456..5474d1d1 100644
--- a/src/hb-aat-layout-trak-table.hh
+++ b/src/hb-aat-layout-trak-table.hh
@@ -133,7 +133,6 @@ struct TrackData
     if (!sizes) return 0.;
     if (sizes == 1) return trackTableEntry->get_value (base, 0, sizes);
 
-    /* TODO bfind() */
     hb_array_t<const Fixed> size_table ((base+sizeTable).arrayZ, sizes);
     unsigned int size_index;
     for (size_index = 0; size_index < sizes - 1; size_index++)
commit 918b1ee54d43eb493c9226bff7677ed8ec07934b
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Nov 24 10:09:17 2018 -0500

    [arrays] Add not_found to reference bsearch as well

diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh
index 1c810e71..2e3db31d 100644
--- a/src/hb-open-type.hh
+++ b/src/hb-open-type.hh
@@ -469,11 +469,11 @@ struct SortedUnsizedArrayOf : UnsizedArrayOf<Type>
   { return hb_sorted_array (this->arrayZ, len); }
 
   template <typename T>
-  inline Type &bsearch (unsigned int len, const T &x)
-  { return *as_array (len).bsearch (x, &Crap (Type)); }
+  inline Type &bsearch (unsigned int len, const T &x, Type &not_found = Crap (Type))
+  { return *as_array (len).bsearch (x, &not_found); }
   template <typename T>
-  inline const Type &bsearch (unsigned int len, const T &x) const
-  { return *as_array (len).bsearch (x, &Null (Type)); }
+  inline const Type &bsearch (unsigned int len, const T &x, const Type &not_found = Null (Type)) const
+  { return *as_array (len).bsearch (x, &not_found); }
   template <typename T>
   inline bool bfind (unsigned int len, const T &x, unsigned int *i = nullptr,
 		     hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
@@ -778,11 +778,11 @@ struct SortedArrayOf : ArrayOf<Type, LenType>
   { return hb_sorted_array (this->arrayZ, this->len); }
 
   template <typename T>
-  inline Type &bsearch (const T &x)
-  { return *as_array ().bsearch (x, &Crap (Type)); }
+  inline Type &bsearch (const T &x, Type &not_found = Crap (Type))
+  { return *as_array ().bsearch (x, &not_found); }
   template <typename T>
-  inline const Type &bsearch (const T &x) const
-  { return *as_array ().bsearch (x, &Null (Type)); }
+  inline const Type &bsearch (const T &x, const Type &not_found = Null (Type)) const
+  { return *as_array ().bsearch (x, &not_found); }
   template <typename T>
   inline bool bfind (const T &x, unsigned int *i = nullptr,
 		     hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
commit d77a098b735cf14aa601feab5bdb9f4e474c794f
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Nov 24 10:06:13 2018 -0500

    [arrays] Improve bfind() interface
    
    Much more useful now. :)

diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh
index cc1a1d42..1680bf91 100644
--- a/src/hb-dsalgs.hh
+++ b/src/hb-dsalgs.hh
@@ -650,6 +650,13 @@ template <typename T>
 inline hb_array_t<T> hb_array (T *array, unsigned int len)
 { return hb_array_t<T> (array, len); }
 
+enum hb_bfind_not_found_t
+{
+  HB_BFIND_NOT_FOUND_DONT_STORE,
+  HB_BFIND_NOT_FOUND_STORE,
+  HB_BFIND_NOT_FOUND_STORE_CLOSEST,
+};
+
 template <typename Type>
 struct hb_sorted_array_t : hb_array_t<Type>
 {
@@ -669,7 +676,9 @@ struct hb_sorted_array_t : hb_array_t<Type>
     return bfind (x, &i) ? &this->arrayZ[i] : not_found;
   }
   template <typename T>
-  inline bool bfind (const T &x, unsigned int *i = nullptr) const
+  inline bool bfind (const T &x, unsigned int *i = nullptr,
+		     hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
+		     unsigned int to_store = (unsigned int) -1) const
   {
     int min = 0, max = (int) this->len - 1;
     const Type *array = this->arrayZ;
@@ -690,9 +699,21 @@ struct hb_sorted_array_t : hb_array_t<Type>
     }
     if (i)
     {
-      if (max < 0 || (max < (int) this->len && array[max].cmp (x) > 0))
-	max++;
-      *i = max;
+      switch (not_found)
+      {
+	case HB_BFIND_NOT_FOUND_DONT_STORE:
+	  break;
+
+	case HB_BFIND_NOT_FOUND_STORE:
+	  *i = to_store;
+	  break;
+
+	case HB_BFIND_NOT_FOUND_STORE_CLOSEST:
+	  if (max < 0 || (max < (int) this->len && array[max].cmp (x) > 0))
+	    max++;
+	  *i = max;
+	  break;
+      }
     }
     return false;
   }
diff --git a/src/hb-open-file.hh b/src/hb-open-file.hh
index d3ecc606..af68892a 100644
--- a/src/hb-open-file.hh
+++ b/src/hb-open-file.hh
@@ -111,14 +111,7 @@ typedef struct OffsetTable
   {
     Tag t;
     t.set (tag);
-    unsigned int i;
-    if (tables.bfind (t, &i))
-    {
-      if (table_index) *table_index = i;
-      return true;
-    }
-    if (table_index) *table_index = (unsigned) Index::NOT_FOUND_INDEX;
-    return false;
+    return tables.bfind (t, table_index, HB_BFIND_NOT_FOUND_STORE, Index::NOT_FOUND_INDEX);
   }
   inline const TableRecord& get_table_by_tag (hb_tag_t tag) const
   {
diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh
index c7154c42..1c810e71 100644
--- a/src/hb-open-type.hh
+++ b/src/hb-open-type.hh
@@ -475,8 +475,10 @@ struct SortedUnsizedArrayOf : UnsizedArrayOf<Type>
   inline const Type &bsearch (unsigned int len, const T &x) const
   { return *as_array (len).bsearch (x, &Null (Type)); }
   template <typename T>
-  inline bool bfind (unsigned int len, const T &x, unsigned int *i = nullptr) const
-  { return as_array (len).bfind (x, i); }
+  inline bool bfind (unsigned int len, const T &x, unsigned int *i = nullptr,
+		     hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
+		     unsigned int to_store = (unsigned int) -1) const
+  { return as_array (len).bfind (x, i, not_found, to_store); }
 };
 
 
@@ -782,8 +784,10 @@ struct SortedArrayOf : ArrayOf<Type, LenType>
   inline const Type &bsearch (const T &x) const
   { return *as_array ().bsearch (x, &Null (Type)); }
   template <typename T>
-  inline bool bfind (const T &x, unsigned int *i = nullptr) const
-  { return as_array ().bfind (x, i); }
+  inline bool bfind (const T &x, unsigned int *i = nullptr,
+		     hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
+		     unsigned int to_store = (unsigned int) -1) const
+  { return as_array ().bfind (x, i, not_found, to_store); }
 };
 
 /*
diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh
index 6c6bcf58..b5af73af 100644
--- a/src/hb-ot-layout-common.hh
+++ b/src/hb-ot-layout-common.hh
@@ -128,12 +128,7 @@ struct RecordArrayOf : SortedArrayOf<Record<Type> >
   }
   inline bool find_index (hb_tag_t tag, unsigned int *index) const
   {
-    if (!this->bfind (tag, index))
-    {
-      if (index) *index = Index::NOT_FOUND_INDEX;
-      return false;
-    }
-    return true;
+    return this->bfind (tag, index, HB_BFIND_NOT_FOUND_STORE, Index::NOT_FOUND_INDEX);
   }
 };
 
@@ -821,8 +816,7 @@ struct CoverageFormat1
   inline unsigned int get_coverage (hb_codepoint_t glyph_id) const
   {
     unsigned int i;
-    if (!glyphArray.bfind (glyph_id, &i))
-      return NOT_COVERED;
+    glyphArray.bfind (glyph_id, &i, HB_BFIND_NOT_FOUND_STORE, NOT_COVERED);
     return i;
   }
 
diff --git a/src/hb-set.hh b/src/hb-set.hh
index a464131d..8b7a0f3d 100644
--- a/src/hb-set.hh
+++ b/src/hb-set.hh
@@ -544,7 +544,7 @@ struct hb_set_t
 
     page_map_t map = {get_major (*codepoint), 0};
     unsigned int i;
-    page_map.bfind (map, &i);
+    page_map.bfind (map, &i, HB_BFIND_NOT_FOUND_STORE_CLOSEST);
     if (i < page_map.len && page_map[i].major == map.major)
     {
       if (pages[page_map[i].index].next (codepoint))
@@ -575,7 +575,7 @@ struct hb_set_t
 
     page_map_t map = {get_major (*codepoint), 0};
     unsigned int i;
-    page_map.bfind (map, &i);
+    page_map.bfind (map, &i, HB_BFIND_NOT_FOUND_STORE_CLOSEST);
     if (i < page_map.len && page_map[i].major == map.major)
     {
       if (pages[page_map[i].index].previous (codepoint))
@@ -670,7 +670,7 @@ struct hb_set_t
   {
     page_map_t map = {get_major (g), pages.len};
     unsigned int i;
-    if (!page_map.bfind (map, &i))
+    if (!page_map.bfind (map, &i, HB_BFIND_NOT_FOUND_STORE_CLOSEST))
     {
       if (!resize (pages.len + 1))
 	return nullptr;
diff --git a/src/hb-vector.hh b/src/hb-vector.hh
index a8c98d22..787512f9 100644
--- a/src/hb-vector.hh
+++ b/src/hb-vector.hh
@@ -239,8 +239,10 @@ struct hb_vector_t
   inline const Type *bsearch (const T &x, const Type *not_found = nullptr) const
   { return as_sorted_array ().bsearch (x, not_found); }
   template <typename T>
-  inline bool bfind (const T &x, unsigned int *i = nullptr) const
-  { return as_sorted_array ().bfind (x, i); }
+  inline bool bfind (const T &x, unsigned int *i = nullptr,
+		     hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
+		     unsigned int to_store = (unsigned int) -1) const
+  { return as_sorted_array ().bfind (x, i, not_found, to_store); }
 };
 
 
commit 1204a247a5d9a4da39675d3da85d4fd3268a5b66
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Nov 24 09:49:21 2018 -0500

    [fuzzing] Add tests for previous commit
    
    Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11526
    Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11522

diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5634620935110656 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5634620935110656
new file mode 100644
index 00000000..39f9c3ce
Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5634620935110656 differ
diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5716208469409792 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5716208469409792
new file mode 100644
index 00000000..00915d68
Binary files /dev/null and b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5716208469409792 differ


More information about the HarfBuzz mailing list