From ba6db26b65c6ce00755def84691e117249b857ff Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 22 Jul 2021 11:37:39 -0700 Subject: [PATCH] Tolerate unsorted OT table entries for small number of entries See comment. Fixes https://github.com/harfbuzz/harfbuzz/issues/3065 --- src/hb-open-file.hh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hb-open-file.hh b/src/hb-open-file.hh index fc94836a2..c2d65eb1d 100644 --- a/src/hb-open-file.hh +++ b/src/hb-open-file.hh @@ -102,7 +102,13 @@ typedef struct OpenTypeOffsetTable { Tag t; t = tag; - return tables.bfind (t, table_index, HB_NOT_FOUND_STORE, Index::NOT_FOUND_INDEX); + /* Use lfind for small fonts; there are fonts that have unsorted table entries; + * those tend to work in other tools, so tolerate them. + * https://github.com/harfbuzz/harfbuzz/issues/3065 */ + if (tables.len < 16) + return tables.lfind (t, table_index, HB_NOT_FOUND_STORE, Index::NOT_FOUND_INDEX); + else + return tables.bfind (t, table_index, HB_NOT_FOUND_STORE, Index::NOT_FOUND_INDEX); } const TableRecord& get_table_by_tag (hb_tag_t tag) const {