Bug 1315642 - Check that font resource decoded/sanitized by OTS is a usable OpenType format (in particular, we do NOT yet support TrueType Collection resources, even though OTS can decode them). r=jrmuizel a=gchang
authorJonathan Kew <jkew@mozilla.com>
Mon, 14 Nov 2016 14:54:23 +0000
changeset 365246 8d8a3ba5349e45bf7a44c4096da2babb4c158e47
parent 365245 f99c3a999e81a017ca3f6026b1e75fe4ec31a50a
child 365247 3d28fa9f98e1eafc400662d32823cc3594627496
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, gchang
bugs1315642
milestone52.0a2
Bug 1315642 - Check that font resource decoded/sanitized by OTS is a usable OpenType format (in particular, we do NOT yet support TrueType Collection resources, even though OTS can decode them). r=jrmuizel a=gchang
gfx/thebes/gfxUserFontSet.cpp
--- a/gfx/thebes/gfxUserFontSet.cpp
+++ b/gfx/thebes/gfxUserFontSet.cpp
@@ -631,16 +631,26 @@ gfxUserFontEntry::LoadPlatformFont(const
     // if necessary. The original data in aFontData is left unchanged.
     uint32_t saneLen;
     uint32_t fontCompressionRatio = 0;
     size_t computedSize = 0;
     const uint8_t* saneData =
         SanitizeOpenTypeData(aFontData, aLength, saneLen, fontType);
     if (!saneData) {
         mFontSet->LogMessage(this, "rejected by sanitizer");
+    } else {
+        // Check whether saneData is a known OpenType format; it might be
+        // a TrueType Collection, which OTS would accept but we don't yet
+        // know how to handle. If so, discard.
+        if (gfxFontUtils::DetermineFontDataType(saneData, saneLen) !=
+            GFX_USERFONT_OPENTYPE) {
+            mFontSet->LogMessage(this, "not a supported OpenType format");
+            free((void*)saneData);
+            saneData = nullptr;
+        }
     }
     if (saneData) {
         if (saneLen) {
             fontCompressionRatio = uint32_t(100.0 * aLength / saneLen + 0.5);
             if (fontType == GFX_USERFONT_WOFF ||
                 fontType == GFX_USERFONT_WOFF2) {
                 Telemetry::Accumulate(fontType == GFX_USERFONT_WOFF ?
                                       Telemetry::WEBFONT_COMPRESSION_WOFF :