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