[HarfBuzz] harfbuzz: Branch 'master' - 6 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Wed Jun 4 16:03:35 PDT 2014
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 <behdad at 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). */
- ArrayOf<EncodingRecord> 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*/ArrayOf<EncodingRecord>
+ encodingRecord; /* Encoding tables. */
public:
DEFINE_SIZE_ARRAY (4, encodingRecord);
};
commit ce34f0b07e5324ed52e6e2c43000c2b09ee010d4
Author: Behdad Esfahbod <behdad at 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 : GenericArrayOf<LenType, Type>
template <typename Type>
struct SortedArrayOf : GenericSortedArrayOf<USHORT, Type> {};
+/* A sorted array with a ULONG number of elements. */
+template <typename Type>
+struct LongSortedArrayOf : GenericSortedArrayOf<ULONG, 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. */
ULONG length; /* Byte length of this subtable. */
ULONG language; /* Ignore. */
- LongArrayOf<CmapSubtableLongGroup>
+ LongSortedArrayOf<CmapSubtableLongGroup>
groups; /* Groupings. */
public:
DEFINE_SIZE_ARRAY (16, groups);
commit 257d1adfa1b3422c511c55e641840a6e31ec6008
Author: Behdad Esfahbod <behdad at 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);
}
protected:
commit 51f563579b94e1ee23ced9bbcc7dd3341535ce72
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Jun 4 18:42:32 2014 -0400
Move try_set to sanitize context
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 965d4d7..fcdee02 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -266,6 +266,15 @@ struct hb_sanitize_context_t
return TRACE_RETURN (this->writable);
}
+ template <typename Type, typename ValueType>
+ inline bool try_set (Type *obj, const ValueType &v) {
+ if (this->may_edit (obj, obj->static_size)) {
+ obj->set (v);
+ return true;
+ }
+ return false;
+ }
+
mutable unsigned int debug_depth;
const char *start, *end;
bool writable;
@@ -722,20 +731,9 @@ struct GenericOffsetTo : OffsetType
return TRACE_RETURN (likely (obj.sanitize (c, user_data)) || neuter (c));
}
- inline bool try_set (hb_sanitize_context_t *c, const OffsetType &v) {
- if (c->may_edit (this, this->static_size)) {
- this->set (v);
- return true;
- }
- return false;
- }
/* Set the offset to Null */
inline bool neuter (hb_sanitize_context_t *c) {
- if (c->may_edit (this, this->static_size)) {
- this->set (0); /* 0 is Null offset */
- return true;
- }
- return false;
+ return c->try_set (this, 0);
}
};
template <typename Base, typename OffsetType, typename Type>
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index 4c6792f..688bf65 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -519,7 +519,7 @@ struct Feature
/* Check that it did not overflow. */
new_offset.set (new_offset_int);
if (new_offset == new_offset_int &&
- featureParams.try_set (c, new_offset) &&
+ c->try_set (&featureParams, new_offset) &&
!featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE))
return TRACE_RETURN (false);
}
commit 500737e8e16dce5248aff394899bb3761a9c3bbf
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Jun 4 18:17:29 2014 -0400
[ot-font] Don't select a Null cmap subtable
Can happen either in broken fonts, or as a result of sanitize().
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index b0f01e1..abaceaa 100644
--- a/src/hb-ot-cmap-table.hh
+++ b/src/hb-ot-cmap-table.hh
@@ -354,7 +354,7 @@ struct cmap
key.encodingID.set (encoding_id);
int result = encodingRecord.search (key);
- if (result == -1)
+ if (result == -1 || !encodingRecord[result].subtable)
return NULL;
return &(this+encodingRecord[result].subtable);
commit dac86026a6bae5a8a03cfe885bf93f32e5f48614
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue Jun 3 17:57:00 2014 -0400
Fix some cppcheck warnings
Bug 77800 - cppcheck reports
diff --git a/src/hb-common.cc b/src/hb-common.cc
index 96725c4..afaecce 100644
--- a/src/hb-common.cc
+++ b/src/hb-common.cc
@@ -299,9 +299,11 @@ hb_language_from_string (const char *str, int len)
if (len >= 0)
{
+ /* NUL-terminate it. */
len = MIN (len, (int) sizeof (strbuf) - 1);
- str = (char *) memcpy (strbuf, str, len);
+ memcpy (strbuf, str, len);
strbuf[len] = '\0';
+ str = strbuf;
}
hb_language_item_t *item = lang_find_or_insert (str);
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index 02d0d0f..4c6792f 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -513,7 +513,7 @@ struct Feature
closure->list_base && closure->list_base < this)
{
unsigned int new_offset_int = (unsigned int) orig_offset -
- ((char *) this - (char *) closure->list_base);
+ (((char *) this) - ((char *) closure->list_base));
Offset new_offset;
/* Check that it did not overflow. */
diff --git a/src/hb-private.hh b/src/hb-private.hh
index 1a1926d..f361875 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -193,7 +193,7 @@ ASSERT_STATIC (sizeof (hb_var_int_t) == 4);
/* Check _assertion in a method environment */
#define _ASSERT_POD1(_line) \
- inline void _static_assertion_on_line_##_line (void) const \
+ HB_UNUSED inline void _static_assertion_on_line_##_line (void) const \
{ _ASSERT_INSTANCE_POD1 (_line, *this); /* Make sure it's POD. */ }
# define _ASSERT_POD0(_line) _ASSERT_POD1 (_line)
# define ASSERT_POD() _ASSERT_POD0 (__LINE__)
diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc
index e354f29..5ffc6b1 100644
--- a/src/hb-shape-plan.cc
+++ b/src/hb-shape-plan.cc
@@ -104,8 +104,6 @@ hb_shape_plan_create (hb_face_t *face,
unsigned int num_user_features,
const char * const *shaper_list)
{
- assert (props->direction != HB_DIRECTION_INVALID);
-
hb_shape_plan_t *shape_plan;
hb_feature_t *features = NULL;
@@ -120,6 +118,8 @@ hb_shape_plan_create (hb_face_t *face,
return hb_shape_plan_get_empty ();
}
+ assert (props->direction != HB_DIRECTION_INVALID);
+
hb_face_make_immutable (face);
shape_plan->default_shaper_list = shaper_list == NULL;
shape_plan->face_unsafe = face;
More information about the HarfBuzz
mailing list