Bug 1035438 - Ensure tags are limited to 4 chars in OTS error messages. r=jdaggett, a=sledru
authorJonathan Kew <jkew@mozilla.com>
Tue, 08 Jul 2014 14:55:51 +0100
changeset 200776 edd37821774c1434c29ffec565e9baadae177b74
parent 200775 9c09b72ad255af0b70a3c07f50934305d2f589c2
child 200777 cce16809b52e8f7e928b563f77d58c8fd3006ac7
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett, sledru
bugs1035438
milestone31.0
Bug 1035438 - Ensure tags are limited to 4 chars in OTS error messages. r=jdaggett, a=sledru
gfx/ots/src/layout.cc
--- a/gfx/ots/src/layout.cc
+++ b/gfx/ots/src/layout.cc
@@ -50,92 +50,92 @@ bool ParseLangSysTable(const ots::OpenTy
                        ots::Buffer *subtable, const uint32_t tag,
                        const uint16_t num_features) {
   uint16_t offset_lookup_order = 0;
   uint16_t req_feature_index = 0;
   uint16_t feature_count = 0;
   if (!subtable->ReadU16(&offset_lookup_order) ||
       !subtable->ReadU16(&req_feature_index) ||
       !subtable->ReadU16(&feature_count)) {
-    return OTS_FAILURE_MSG("Failed to read langsys header for table %4s", (char *)&tag);
+    return OTS_FAILURE_MSG("Failed to read langsys header for tag %4.4s", (char *)&tag);
   }
   // |offset_lookup_order| is reserved and should be NULL.
   if (offset_lookup_order != 0) {
-    return OTS_FAILURE_MSG("Bad lookup offset order %d in table %4s", offset_lookup_order, (char *)&tag);
+    return OTS_FAILURE_MSG("Bad lookup offset order %d for langsys tag %4.4s", offset_lookup_order, (char *)&tag);
   }
   if (req_feature_index != kNoRequiredFeatureIndexDefined &&
       req_feature_index >= num_features) {
-    return OTS_FAILURE_MSG("Bad required features index %d in table %4s", req_feature_index, (char *)&tag);
+    return OTS_FAILURE_MSG("Bad required features index %d for langsys tag %4.4s", req_feature_index, (char *)&tag);
   }
   if (feature_count > num_features) {
-    return OTS_FAILURE_MSG("Bad feature count %d in table %4s", feature_count, (char *)&tag);
+    return OTS_FAILURE_MSG("Bad feature count %d for langsys tag %4.4s", feature_count, (char *)&tag);
   }
 
   for (unsigned i = 0; i < feature_count; ++i) {
     uint16_t feature_index = 0;
     if (!subtable->ReadU16(&feature_index)) {
-      return OTS_FAILURE_MSG("Failed to read feature index %d in table %4s", i, (char *)&tag);
+      return OTS_FAILURE_MSG("Failed to read feature index %d for langsys tag %4.4s", i, (char *)&tag);
     }
     if (feature_index >= num_features) {
-      return OTS_FAILURE_MSG("Bad feature index %d for feature %d in table %4s", feature_index, i, (char *)&tag);
+      return OTS_FAILURE_MSG("Bad feature index %d for feature %d for langsys tag %4.4s", feature_index, i, (char *)&tag);
     }
   }
   return true;
 }
 
 bool ParseScriptTable(const ots::OpenTypeFile *file,
                       const uint8_t *data, const size_t length,
                       const uint32_t tag, const uint16_t num_features) {
   ots::Buffer subtable(data, length);
 
   uint16_t offset_default_lang_sys = 0;
   uint16_t lang_sys_count = 0;
   if (!subtable.ReadU16(&offset_default_lang_sys) ||
       !subtable.ReadU16(&lang_sys_count)) {
-    return OTS_FAILURE_MSG("Failed to read script header for table %4s", (char *)&tag);
+    return OTS_FAILURE_MSG("Failed to read script header for script tag %4.4s", (char *)&tag);
   }
 
   // The spec requires a script table for 'DFLT' tag must contain non-NULL
   // |offset_default_lang_sys| and |lang_sys_count| == 0
   if (tag == kScriptTableTagDflt &&
       (offset_default_lang_sys == 0 || lang_sys_count != 0)) {
-    return OTS_FAILURE_MSG("DFLT table doesn't satisfy the spec. in table %4s", (char *)&tag);
+    return OTS_FAILURE_MSG("DFLT table doesn't satisfy the spec. for script tag %4.4s", (char *)&tag);
   }
 
   const unsigned lang_sys_record_end =
       6 * static_cast<unsigned>(lang_sys_count) + 4;
   if (lang_sys_record_end > std::numeric_limits<uint16_t>::max()) {
-    return OTS_FAILURE_MSG("Bad end of langsys record %d in table %4s", lang_sys_record_end, (char *)&tag);
+    return OTS_FAILURE_MSG("Bad end of langsys record %d for script tag %4.4s", lang_sys_record_end, (char *)&tag);
   }
 
   std::vector<LangSysRecord> lang_sys_records;
   lang_sys_records.resize(lang_sys_count);
   uint32_t last_tag = 0;
   for (unsigned i = 0; i < lang_sys_count; ++i) {
     if (!subtable.ReadU32(&lang_sys_records[i].tag) ||
         !subtable.ReadU16(&lang_sys_records[i].offset)) {
-      return OTS_FAILURE_MSG("Failed to read langsys record header %d for table %4s", i, (char *)&tag);
+      return OTS_FAILURE_MSG("Failed to read langsys record header %d for script tag %4.4s", i, (char *)&tag);
     }
     // The record array must store the records alphabetically by tag
     if (last_tag != 0 && last_tag > lang_sys_records[i].tag) {
-      return OTS_FAILURE_MSG("Bad last tag %d for langsys record %d in table %4s", last_tag, i, (char *)&tag);
+      return OTS_FAILURE_MSG("Bad last tag %d for langsys record %d for script tag %4.4s", last_tag, i, (char *)&tag);
     }
     if (lang_sys_records[i].offset < lang_sys_record_end ||
         lang_sys_records[i].offset >= length) {
       return OTS_FAILURE_MSG("bad offset to lang sys table: %x",
                   lang_sys_records[i].offset);
     }
     last_tag = lang_sys_records[i].tag;
   }
 
   // Check lang sys tables
   for (unsigned i = 0; i < lang_sys_count; ++i) {
     subtable.set_offset(lang_sys_records[i].offset);
     if (!ParseLangSysTable(file, &subtable, lang_sys_records[i].tag, num_features)) {
-      return OTS_FAILURE_MSG("Failed to parse langsys table %d (%4s) in table %4s", i, (char *)&lang_sys_records[i].tag, (char *)&tag);
+      return OTS_FAILURE_MSG("Failed to parse langsys table %d (%4.4s) for script tag %4.4s", i, (char *)&lang_sys_records[i].tag, (char *)&tag);
     }
   }
 
   return true;
 }
 
 bool ParseFeatureTable(const ots::OpenTypeFile *file,
                        const uint8_t *data, const size_t length,
@@ -153,17 +153,17 @@ bool ParseFeatureTable(const ots::OpenTy
       2 * static_cast<unsigned>(lookup_count) + 4;
   if (feature_table_end > std::numeric_limits<uint16_t>::max()) {
     return OTS_FAILURE_MSG("Bad end of feature table %d", feature_table_end);
   }
   // |offset_feature_params| is generally set to NULL.
   if (offset_feature_params != 0 &&
       (offset_feature_params < feature_table_end ||
        offset_feature_params >= length)) {
-    return OTS_FAILURE_MSG("Badd feature parames offset %d", offset_feature_params);
+    return OTS_FAILURE_MSG("Bad feature params offset %d", offset_feature_params);
   }
 
   for (unsigned i = 0; i < lookup_count; ++i) {
     uint16_t lookup_index = 0;
     if (!subtable.ReadU16(&lookup_index)) {
       return OTS_FAILURE_MSG("Failed to read lookup index for lookup %d", i);
     }
     // lookup index starts with 0.
@@ -1223,17 +1223,17 @@ bool ParseScriptListTable(const ots::Ope
     if (last_tag != 0 && last_tag > record.tag) {
       // Several fonts don't arrange tags alphabetically.
       // It seems that the order of tags might not be a security issue
       // so we just warn it.
       OTS_WARNING("tags aren't arranged alphabetically.");
     }
     last_tag = record.tag;
     if (record.offset < script_record_end || record.offset >= length) {
-      return OTS_FAILURE_MSG("Bad record offset %d for script %4s entry %d in script list table", record.offset, (char *)&record.tag, i);
+      return OTS_FAILURE_MSG("Bad record offset %d for script %4.4s entry %d in script list table", record.offset, (char *)&record.tag, i);
     }
     script_list.push_back(record);
   }
   if (script_list.size() != script_count) {
     return OTS_FAILURE_MSG("Bad script list size %ld in script list table", script_list.size());
   }
 
   // Check script records.
@@ -1279,17 +1279,17 @@ bool ParseFeatureListTable(const ots::Op
       // Several fonts don't arrange tags alphabetically.
       // It seems that the order of tags might not be a security issue
       // so we just warn it.
       OTS_WARNING("tags aren't arranged alphabetically.");
     }
     last_tag = feature_records[i].tag;
     if (feature_records[i].offset < feature_record_end ||
         feature_records[i].offset >= length) {
-      return OTS_FAILURE_MSG("Bad feature offset %d for feature %d %4s", feature_records[i].offset, i, (char *)&feature_records[i].tag);
+      return OTS_FAILURE_MSG("Bad feature offset %d for feature %d %4.4s", feature_records[i].offset, i, (char *)&feature_records[i].tag);
     }
   }
 
   for (unsigned i = 0; i < feature_count; ++i) {
     if (!ParseFeatureTable(file, data + feature_records[i].offset,
                            length - feature_records[i].offset, num_lookups)) {
       return OTS_FAILURE_MSG("Failed to parse feature table %d", i);
     }