[post] Refactor a bit, use our data types

This commit is contained in:
Behdad Esfahbod 2017-10-28 16:58:56 -06:00
parent 5014c60afa
commit feadee079e
1 changed files with 10 additions and 15 deletions

View File

@ -52,13 +52,10 @@ struct postV2Tail
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (numberOfGlyphs.sanitize (c) && return_trace (glyphNameIndex.sanitize (c));
c->check_array (glyphNameIndex, sizeof (USHORT), numberOfGlyphs));
} }
USHORT numberOfGlyphs; /* Number of glyphs (this should be the ArrayOf<USHORT>glyphNameIndex; /* This is not an offset, but is the
* same as numGlyphs in 'maxp' table). */
USHORT glyphNameIndex[VAR]; /* This is not an offset, but is the
* ordinal number of the glyph in 'post' * ordinal number of the glyph in 'post'
* string tables. */ * string tables. */
BYTE namesX[VAR]; /* Glyph names with length bytes [variable] BYTE namesX[VAR]; /* Glyph names with length bytes [variable]
@ -104,7 +101,7 @@ struct post
{ {
const postV2Tail &v2 = StructAfter<postV2Tail> (*this); const postV2Tail &v2 = StructAfter<postV2Tail> (*this);
if (glyph >= v2.numberOfGlyphs) if (glyph >= v2.glyphNameIndex.len)
return false; return false;
if (!buffer_length) if (!buffer_length)
@ -121,9 +118,8 @@ struct post
} }
index -= NUM_FORMAT1_NAMES; index -= NUM_FORMAT1_NAMES;
unsigned int offset = min_size + v2.min_size + 2 * v2.numberOfGlyphs; const uint8_t *data = &StructAfter<uint8_t> (v2.glyphNameIndex);
unsigned char *data = (unsigned char *) this + offset; const uint8_t *end = (uint8_t *) this + blob_len;
unsigned char *end = (unsigned char *) this + blob_len;
for (unsigned int i = 0; data < end; i++) for (unsigned int i = 0; data < end; i++)
{ {
unsigned int name_length = data[0]; unsigned int name_length = data[0];
@ -172,13 +168,12 @@ struct post
if (version.to_int () == 0x00020000) if (version.to_int () == 0x00020000)
{ {
const postV2Tail &v2 = StructAfter<postV2Tail> (*this); const postV2Tail &v2 = StructAfter<postV2Tail> (*this);
unsigned int offset = min_size + v2.min_size + 2 * v2.numberOfGlyphs; const uint8_t *data = &StructAfter<uint8_t> (v2.glyphNameIndex);
char* data = (char*) this + offset;
/* XXX The following code is wrong. */ /* XXX The following code is wrong. */
return false; return false;
for (hb_codepoint_t gid = 0; gid < v2.numberOfGlyphs; gid++) for (hb_codepoint_t gid = 0; gid < v2.glyphNameIndex.len; gid++)
{ {
unsigned int index = v2.glyphNameIndex[gid]; unsigned int index = v2.glyphNameIndex[gid];
if (index < NUM_FORMAT1_NAMES) if (index < NUM_FORMAT1_NAMES)
@ -192,12 +187,12 @@ struct post
} }
index -= NUM_FORMAT1_NAMES; index -= NUM_FORMAT1_NAMES;
for (unsigned int i = 0; data < (char*) this + blob_len; i++) for (unsigned int i = 0; data < (uint8_t *) this + blob_len; i++)
{ {
unsigned int name_length = data[0]; unsigned int name_length = data[0];
unsigned int remaining = (char*) this + blob_len - data - 1; unsigned int remaining = CastP<uint8_t> (this) + blob_len - data - 1;
name_length = MIN (name_length, remaining); name_length = MIN (name_length, remaining);
if (name_length == (unsigned int) len && strncmp (name, data + 1, len) == 0) if (name_length == (unsigned int) len && strncmp (name, (const char *) data + 1, len) == 0)
{ {
*glyph = gid; *glyph = gid;
return true; return true;