[name] Do record sanitization at run-time

pull/1319/head
Behdad Esfahbod 6 years ago
parent a53d301b1c
commit dc9a5f88b4
  1. 62
      src/hb-dsalgs.hh
  2. 22
      src/hb-ot-name-table.hh
  3. 2
      src/hb-ot-name.cc

@ -530,6 +530,35 @@ struct hb_auto_t : Type
void fini (void) {}
};
struct hb_bytes_t
{
inline hb_bytes_t (void) : arrayZ (nullptr), len (0) {}
inline hb_bytes_t (const char *bytes_, unsigned int len_) : arrayZ (bytes_), len (len_) {}
inline hb_bytes_t (const void *bytes_, unsigned int len_) : arrayZ ((const char *) bytes_), len (len_) {}
template <typename T>
inline hb_bytes_t (const T& array) : arrayZ ((const char *) array.arrayZ), len (array.len) {}
inline void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; }
inline int cmp (const hb_bytes_t &a) const
{
if (len != a.len)
return (int) a.len - (int) len;
return memcmp (a.arrayZ, arrayZ, len);
}
static inline int cmp (const void *pa, const void *pb)
{
hb_bytes_t *a = (hb_bytes_t *) pa;
hb_bytes_t *b = (hb_bytes_t *) pb;
return b->cmp (*a);
}
const char *arrayZ;
unsigned int len;
};
template <typename T>
struct hb_array_t
{
@ -553,6 +582,11 @@ struct hb_array_t
return hb_array_t<T> (arrayZ + start_offset, count);
}
inline hb_bytes_t as_bytes (void) const
{
return hb_bytes_t (arrayZ, len * sizeof (T));
}
inline void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; }
T *arrayZ;
@ -561,34 +595,6 @@ struct hb_array_t
template <typename T> static inline
hb_array_t<T> hb_array (T *array, unsigned int len) { return hb_array_t<T> (array, len); }
struct hb_bytes_t
{
inline hb_bytes_t (void) : arrayZ (nullptr), len (0) {}
inline hb_bytes_t (const char *bytes_, unsigned int len_) : arrayZ (bytes_), len (len_) {}
inline hb_bytes_t (const void *bytes_, unsigned int len_) : arrayZ ((const char *) bytes_), len (len_) {}
template <typename T>
inline hb_bytes_t (const T& array) : arrayZ ((const char *) array.arrayZ), len (array.len) {}
inline void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; }
inline int cmp (const hb_bytes_t &a) const
{
if (len != a.len)
return (int) a.len - (int) len;
return memcmp (a.arrayZ, arrayZ, len);
}
static inline int cmp (const void *pa, const void *pb)
{
hb_bytes_t *a = (hb_bytes_t *) pa;
hb_bytes_t *b = (hb_bytes_t *) pb;
return b->cmp (*a);
}
const char *arrayZ;
unsigned int len;
};
struct HbOpOr
{

@ -152,13 +152,6 @@ struct name
{
static const hb_tag_t tableTag = HB_OT_TAG_name;
inline hb_bytes_t get_name (unsigned int idx) const
{
const hb_array_t<const NameRecord> all_names (nameRecordZ.arrayZ, count);
const NameRecord &record = all_names[idx];
return hb_bytes_t ((const char *) (this+stringOffset).arrayZ + record.offset, record.length);
}
inline unsigned int get_size (void) const
{ return min_size + count * nameRecordZ[0].min_size; }
@ -178,7 +171,7 @@ struct name
return_trace (c->check_struct (this) &&
likely (format == 0 || format == 1) &&
c->check_array (nameRecordZ.arrayZ, count) &&
sanitize_records (c));
c->check_range (this, stringOffset));
}
struct accelerator_t
@ -187,6 +180,9 @@ struct name
{
this->blob = hb_sanitize_context_t().reference_table<name> (face);
this->table = this->blob->as<name> ();
assert (this->blob->length >= this->table->stringOffset);
this->pool = (this->table+this->table->stringOffset).arrayZ;
this->pool_len = this->blob->length - this->table->stringOffset;
const hb_array_t<const NameRecord> all_names (this->table->nameRecordZ.arrayZ,
this->table->count);
@ -246,8 +242,18 @@ struct name
return entry->entry_index;
}
inline hb_bytes_t get_name (unsigned int idx) const
{
const hb_array_t<const NameRecord> all_names (table->nameRecordZ.arrayZ, table->count);
const NameRecord &record = all_names[idx];
const hb_array_t<const char> string_pool ((const char *) pool, pool_len);
return string_pool.sub_array (record.offset, record.length).as_bytes ();
}
private:
hb_blob_t *blob;
const void *pool;
unsigned int pool_len;
public:
const name *table;
hb_vector_t<hb_ot_name_entry_t> names;

@ -110,7 +110,7 @@ hb_ot_name_get_utf (hb_face_t *face,
int idx = name.get_index (name_id, language, &width);
if (idx != -1)
{
hb_bytes_t bytes = name.table->get_name (idx);
hb_bytes_t bytes = name.get_name (idx);
if (width == 2) /* UTF16-BE */
return hb_ot_name_convert_utf<hb_utf16_be_t, utf_t> (&bytes, text_size, text);

Loading…
Cancel
Save