src/hb-common.cc |4 ++-
src/hb-open-type-private.hh| 26
src/hb-ot-cmap-table.hh| 40 ++---
src/hb-ot-layout-common-private.hh |4 +--
src/hb-private.hh |2 -
src/hb-shape-plan.cc |4 +--
6 files changed, 51 insertions(+), 29 deletions(-)
New commits:
commit f1a72fe7bf863535ec09b559cc0bd878fd0799f2
Author: Behdad Esfahbod beh...@behdad.org
Date: Wed Jun 4 19:00:29 2014 -0400
[ot-font] Fix cmap EncodingRecord cmp order
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index b7c89ce..e21baed 100644
--- a/src/hb-ot-cmap-table.hh
+++ b/src/hb-ot-cmap-table.hh
@@ -332,12 +332,12 @@ struct CmapSubtable
struct EncodingRecord
{
- int cmp (const EncodingRecord other) const
+ inline int cmp (const EncodingRecord other) const
{
int ret;
-ret = other.platformID.cmp (platformID);
+ret = platformID.cmp (other.platformID);
if (ret) return ret;
-ret = other.encodingID.cmp (encodingID);
+ret = encodingID.cmp (other.encodingID);
if (ret) return ret;
return 0;
}
@@ -381,8 +381,12 @@ struct cmap
encodingRecord.sanitize (c, this));
}
- USHORT version;/* Table version number (0). */
- ArrayOfEncodingRecord encodingRecord; /* Encoding tables. */
+ USHORT version;/* Table version number (0). */
+ /* Note: We can use the Sorted array variant, but since it
+ * has no performance implications, we use non-sorted array and
+ * as such accept fonts with unsorted subtable list. */
+ /*Sorted*/ArrayOfEncodingRecord
+ encodingRecord; /* Encoding tables. */
public:
DEFINE_SIZE_ARRAY (4, encodingRecord);
};
commit ce34f0b07e5324ed52e6e2c43000c2b09ee010d4
Author: Behdad Esfahbod beh...@behdad.org
Date: Wed Jun 4 18:57:46 2014 -0400
[ot-font] Use binary search for format12 cmap subtable
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index fcdee02..c4446ce 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -985,6 +985,10 @@ struct GenericSortedArrayOf : GenericArrayOfLenType, Type
template typename Type
struct SortedArrayOf : GenericSortedArrayOfUSHORT, Type {};
+/* A sorted array with a ULONG number of elements. */
+template typename Type
+struct LongSortedArrayOf : GenericSortedArrayOfULONG, Type {};
+
} /* namespace OT */
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index 65434c4..b7c89ce 100644
--- a/src/hb-ot-cmap-table.hh
+++ b/src/hb-ot-cmap-table.hh
@@ -264,7 +264,7 @@ struct CmapSubtableLongSegmented
USHORT reserved; /* Reserved; set to 0. */
ULONGlength; /* Byte length of this subtable. */
ULONGlanguage; /* Ignore. */
- LongArrayOfCmapSubtableLongGroup
+ LongSortedArrayOfCmapSubtableLongGroup
groups; /* Groupings. */
public:
DEFINE_SIZE_ARRAY (16, groups);
commit 257d1adfa1b3422c511c55e641840a6e31ec6008
Author: Behdad Esfahbod beh...@behdad.org
Date: Wed Jun 4 18:47:55 2014 -0400
[ot-font] Work around broken cmap subtable format 4 length
Roboto was hitting this. FreeType also has pretty much the
same code for this, in ttcmap.c:tt_cmap4_validate():
/* in certain fonts, the `length' field is invalid and goes */
/* out of bound. We try to correct this here...*/
if ( table + length valid-limit )
{
if ( valid-level = FT_VALIDATE_TIGHT )
FT_INVALID_TOO_SHORT;
length = (FT_UInt)( valid-limit - table );
}
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index abaceaa..65434c4 100644
--- a/src/hb-ot-cmap-table.hh
+++ b/src/hb-ot-cmap-table.hh
@@ -131,11 +131,25 @@ struct CmapSubtableFormat4
return true;
}
- inline bool sanitize (hb_sanitize_context_t *c) {
+ inline bool sanitize (hb_sanitize_context_t *c)
+ {
TRACE_SANITIZE (this);
-return TRACE_RETURN (c-check_struct (this)
-c-check_range (this, length)
-16 + 4 * (unsigned int) segCountX2 length);
+if (unlikely (!c-check_struct (this)))
+ return TRACE_RETURN (false);
+
+if (unlikely (!c-check_range (this, length)))
+{
+ /* Some broken fonts have too long of a length value.
+ * If that is the case, just change the value to truncate
+ * the subtable at the end of the blob. */
+ uint16_t new_length = (uint16_t) MIN ((uintptr_t) 65535,
+ (uintptr_t) (c-end -
+(char *) this));
+ if (!c-try_set (length, new_length))
+ return TRACE_RETURN (false);
+}
+
+return TRACE_RETURN (16 + 4 * (unsigned int) segCountX2 = length);
}