bug 762484 - update OTS to upstream rev.92. r=emk
authorJonathan Kew <jkew@mozilla.com>
Thu, 07 Jun 2012 17:00:13 +0100
changeset 96082 14d0960c626ee5ced3a4a6e0e673934934c76d32
parent 96081 5f99fe9d218212cb1acc3d5ed21151c8159acb4a
child 96083 bafcd73047967e140e55625d10b4cc204f9c1ebb
push idunknown
push userunknown
push dateunknown
reviewersemk
bugs762484
milestone16.0a1
bug 762484 - update OTS to upstream rev.92. r=emk
gfx/ots/README.mozilla
gfx/ots/src/ots.cc
--- a/gfx/ots/README.mozilla
+++ b/gfx/ots/README.mozilla
@@ -1,11 +1,11 @@
 This is the Sanitiser for OpenType project, from http://code.google.com/p/ots/.
 
-Current revision: r91
+Current revision: r92
 
 Applied local patches:
     ots-fix-vc10.patch - workaround for VS10 STL wrappers (bug 602558)
 
     ots-fix-sparc64.patch - fix alignment error on sparc64 (bug 643137)
 
     ots-graphite.patch - preserve Graphite layout tables (bug 631479)
 
--- a/gfx/ots/src/ots.cc
+++ b/gfx/ots/src/ots.cc
@@ -180,17 +180,19 @@ bool IsValidVersionTag(uint32_t tag) {
   return tag == Tag("\x00\x01\x00\x00") ||
          // OpenType fonts with CFF data have 'OTTO' tag.
          tag == Tag("OTTO") ||
          // Older Mac fonts might have 'true' or 'typ1' tag.
          tag == Tag("true") ||
          tag == Tag("typ1");
 }
 
-bool ProcessGeneric(ots::OpenTypeFile *header, ots::OTSStream *output,
+bool ProcessGeneric(ots::OpenTypeFile *header,
+                    uint32_t signature,
+                    ots::OTSStream *output,
                     const uint8_t *data, size_t length,
                     const std::vector<OpenTypeTable>& tables,
                     ots::Buffer& file);
 
 bool ProcessTTF(ots::OpenTypeFile *header,
                 ots::OTSStream *output, const uint8_t *data, size_t length) {
   ots::Buffer file(data, length);
 
@@ -258,17 +260,18 @@ bool ProcessTTF(ots::OpenTypeFile *heade
         !file.ReadU32(&table.length)) {
       return OTS_FAILURE_MSG_HDR("error reading table directory");
     }
 
     table.uncompressed_length = table.length;
     tables.push_back(table);
   }
 
-  return ProcessGeneric(header, output, data, length, tables, file);
+  return ProcessGeneric(header, header->version, output, data, length,
+                        tables, file);
 }
 
 bool ProcessWOFF(ots::OpenTypeFile *header,
                  ots::OTSStream *output, const uint8_t *data, size_t length) {
   ots::Buffer file(data, length);
 
   // we disallow all files > 1GB in size for sanity.
   if (length > 1024 * 1024 * 1024) {
@@ -416,20 +419,21 @@ bool ProcessWOFF(ots::OpenTypeFile *head
     if (block_end > std::numeric_limits<uint32_t>::max()) {
       return OTS_FAILURE_MSG_HDR("invalid private block size");
     }
   }
   if (block_end != Round4(length)) {
     return OTS_FAILURE_MSG_HDR("file length mismatch (trailing junk?)");
   }
 
-  return ProcessGeneric(header, output, data, length, tables, file);
+  return ProcessGeneric(header, woff_tag, output, data, length, tables, file);
 }
 
-bool ProcessGeneric(ots::OpenTypeFile *header, ots::OTSStream *output,
+bool ProcessGeneric(ots::OpenTypeFile *header, uint32_t signature,
+                    ots::OTSStream *output,
                     const uint8_t *data, size_t length,
                     const std::vector<OpenTypeTable>& tables,
                     ots::Buffer& file) {
   const size_t data_offset = file.offset();
 
   uint32_t uncompressed_sum = 0;
 
   for (unsigned i = 0; i < header->num_tables; ++i) {
@@ -480,20 +484,21 @@ bool ProcessGeneric(ots::OpenTypeFile *h
       if (uncompressed_sum + tables[i].uncompressed_length < uncompressed_sum) {
         return OTS_FAILURE_MSG_TAG("overflow of uncompressed sum", &tables[i].tag);
       }
 
       uncompressed_sum += tables[i].uncompressed_length;
     }
     // since we required that the file be < 1GB in length, and that the table
     // length is < 1GB, the following addtion doesn't overflow
-    const uint32_t end_byte = tables[i].offset + tables[i].length;
-    // Some fonts which are automatically generated by a font generator
-    // called TTX seems not to add 0-padding to the final table. It might be
-    // ok to accept these fonts so we round up the length of the font file.
+    uint32_t end_byte = tables[i].offset + tables[i].length;
+    // Tables in the WOFF file must be aligned 4-byte boundary.
+    if (signature == Tag("wOFF")) {
+        end_byte = Round4(end_byte);
+    }
     if (!end_byte || end_byte > length) {
       return OTS_FAILURE_MSG_TAG("table overruns end of file", &tables[i].tag);
     }
   }
 
   // All decompressed tables uncompressed must be <= 30MB.
   if (uncompressed_sum > 30 * 1024 * 1024) {
     return OTS_FAILURE_MSG_HDR("uncompressed sum exceeds 30MB");