gfx/ots/ots-woff2.patch

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-sanitiser.h
     2 --- a/gfx/ots/include/opentype-sanitiser.h
     3 +++ b/gfx/ots/include/opentype-sanitiser.h
     4 @@ -236,14 +236,16 @@ typedef TableAction (*TableActionFunc)(u
     5  // Set a callback function that will be called when OTS needs to decide what to
     6  // do for a font table.
     7  void OTS_API SetTableActionCallback(TableActionFunc func, void *user_data);
     9  // Force to disable debug output even when the library is compiled with
    10  // -DOTS_DEBUG.
    11  void DisableDebugOutput();
    13 +#ifdef MOZ_OTS_WOFF2
    14  // Enable WOFF2 support(experimental).
    15  void EnableWOFF2();
    16 +#endif
    18  }  // namespace ots
    20  #endif  // OPENTYPE_SANITISER_H_
    21 diff --git a/gfx/ots/src/ots.cc b/gfx/ots/src/ots.cc
    22 --- a/gfx/ots/src/ots.cc
    23 +++ b/gfx/ots/src/ots.cc
    24 @@ -9,25 +9,29 @@
    26  #include <algorithm>
    27  #include <cstdlib>
    28  #include <cstring>
    29  #include <limits>
    30  #include <map>
    31  #include <vector>
    33 +#ifdef MOZ_OTS_WOFF2
    34  #include "woff2.h"
    35 +#endif
    37  // The OpenType Font File
    38  // http://www.microsoft.com/typography/otspec/cmap.htm
    40  namespace {
    42  bool g_debug_output = true;
    43 +#ifdef MOZ_OTS_WOFF2
    44  bool g_enable_woff2 = false;
    45 +#endif
    47  ots::MessageFunc  g_message_func = NULL;
    48  void             *g_message_user_data = NULL;
    50  ots::TableActionFunc  g_table_action_func = NULL;
    51  void                 *g_table_action_user_data = NULL;
    53  // Generate a message with or without a table tag, when 'header' is the OpenTypeFile pointer
    54 @@ -395,16 +399,17 @@ bool ProcessWOFF(ots::OpenTypeFile *head
    55    }
    56    if (block_end != ots::Round4(length)) {
    57      return OTS_FAILURE_MSG_HDR("file length mismatch (trailing junk?)");
    58    }
    60    return ProcessGeneric(header, woff_tag, output, data, length, tables, file);
    61  }
    63 +#ifdef MOZ_OTS_WOFF2
    64  bool ProcessWOFF2(ots::OpenTypeFile *header,
    65                    ots::OTSStream *output, const uint8_t *data, size_t length) {
    66    size_t decompressed_size = ots::ComputeWOFF2FinalSize(data, length);
    67    if (decompressed_size == 0) {
    68      return OTS_FAILURE();
    69    }
    70    // decompressed font must be <= 30MB
    71    if (decompressed_size > 30 * 1024 * 1024) {
    72 @@ -413,16 +418,17 @@ bool ProcessWOFF2(ots::OpenTypeFile *hea
    74    std::vector<uint8_t> decompressed_buffer(decompressed_size);
    75    if (!ots::ConvertWOFF2ToTTF(&decompressed_buffer[0], decompressed_size,
    76                                data, length)) {
    77      return OTS_FAILURE();
    78    }
    79    return ProcessTTF(header, output, &decompressed_buffer[0], decompressed_size);
    80  }
    81 +#endif
    83  ots::TableAction GetTableAction(uint32_t tag) {
    84    ots::TableAction action = ots::TABLE_ACTION_DEFAULT;
    86    if (g_table_action_func != NULL) {
    87      action = g_table_action_func(htonl(tag), g_table_action_user_data);
    88    }
    90 @@ -795,19 +801,21 @@ bool IsValidVersionTag(uint32_t tag) {
    91           tag == Tag("true") ||
    92           tag == Tag("typ1");
    93  }
    95  void DisableDebugOutput() {
    96    g_debug_output = false;
    97  }
    99 +#ifdef MOZ_OTS_WOFF2
   100  void EnableWOFF2() {
   101    g_enable_woff2 = true;
   102  }
   103 +#endif
   105  void SetMessageCallback(MessageFunc func, void *user_data) {
   106    g_message_func = func;
   107    g_message_user_data = user_data;
   108  }
   110  void SetTableActionCallback(TableActionFunc func, void *user_data) {
   111    g_table_action_func = func;
   112 @@ -822,20 +830,22 @@ bool Process(OTSStream *output, const ui
   114    if (length < 4) {
   115      return OTS_FAILURE_MSG_(&header, "file less than 4 bytes");
   116    }
   118    bool result;
   119    if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] == 'F') {
   120      result = ProcessWOFF(&header, output, data, length);
   121 +#ifdef MOZ_OTS_WOFF2
   122    } else if (g_enable_woff2 &&
   123               data[0] == 'w' && data[1] == 'O' && data[2] == 'F' &&
   124               data[3] == '2') {
   125      result = ProcessWOFF2(&header, output, data, length);
   126 +#endif
   127    } else {
   128      result = ProcessTTF(&header, output, data, length);
   129    }
   131    for (unsigned i = 0; ; ++i) {
   132      if (table_parsers[i].parse == NULL) break;
   133      table_parsers[i].free(&header);
   134    }

mercurial