diff --git a/application/palemoon/components/nsBrowserGlue.js b/application/palemoon/components/nsBrowserGlue.js
index 01a133833d..31a8bf40c6 100644
--- a/application/palemoon/components/nsBrowserGlue.js
+++ b/application/palemoon/components/nsBrowserGlue.js
@@ -1198,7 +1198,7 @@ BrowserGlue.prototype = {
},
_migrateUI: function BG__migrateUI() {
- const UI_VERSION = 19;
+ const UI_VERSION = 20;
const BROWSER_DOCURL = "chrome://browser/content/browser.xul#";
let currentUIVersion = 0;
try {
@@ -1433,6 +1433,11 @@ BrowserGlue.prototype = {
}
#endif
+ if (currentUIVersion < 20) {
+ // HPKP change of UI preference; reset enforcement level
+ Services.prefs.clearUserPref("security.cert_pinning.enforcement_level");
+ }
+
// Update the migration version.
Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
},
diff --git a/application/palemoon/components/preferences/security.js b/application/palemoon/components/preferences/security.js
index 9d5f302a21..54fab68ac1 100644
--- a/application/palemoon/components/preferences/security.js
+++ b/application/palemoon/components/preferences/security.js
@@ -18,7 +18,6 @@ var gSecurityPane = {
{
this._pane = document.getElementById("paneSecurity");
this._initMasterPasswordUI();
- this._initHPKPUI();
},
// ADD-ONS
@@ -233,31 +232,5 @@ var gSecurityPane = {
document.documentElement.openWindow("Toolkit:PasswordManager",
"chrome://passwordmgr/content/passwordManager.xul",
"", null);
- },
-
- _initHPKPUI: function() {
- let checkbox = document.getElementById("enableHPKP");
- let HPKPpref = document.getElementById("security.cert_pinning.enforcement_level");
-
- if (HPKPpref.value == 0) {
- checkbox.checked = false;
- } else {
- checkbox.checked = true;
- }
- },
-
- /**
- * Updates the HPKP enforcement level to the proper value depending on checkbox
- * state.
- */
- updateHPKPPref: function() {
- let checkbox = document.getElementById("enableHPKP");
- let HPKPpref = document.getElementById("security.cert_pinning.enforcement_level");
-
- if (checkbox.checked) {
- HPKPpref.value = 2;
- } else {
- HPKPpref.value = 0;
- }
}
};
diff --git a/application/palemoon/components/preferences/security.xul b/application/palemoon/components/preferences/security.xul
index bc16252751..9aa3f7a8af 100644
--- a/application/palemoon/components/preferences/security.xul
+++ b/application/palemoon/components/preferences/security.xul
@@ -46,9 +46,9 @@
-
+
@@ -150,7 +150,7 @@
+ preference="security.cert_pinning.hpkp.enabled"/>
diff --git a/devtools/client/webconsole/test/browser_webconsole_hpkp_invalid-headers.js b/devtools/client/webconsole/test/browser_webconsole_hpkp_invalid-headers.js
index 3ee33669de..39870fd547 100644
--- a/devtools/client/webconsole/test/browser_webconsole_hpkp_invalid-headers.js
+++ b/devtools/client/webconsole/test/browser_webconsole_hpkp_invalid-headers.js
@@ -14,14 +14,18 @@ const SJS_URL = "https://example.com/browser/devtools/client/webconsole/" +
"test/test_hpkp-invalid-headers.sjs";
const LEARN_MORE_URI = "https://developer.mozilla.org/docs/Web/Security/" +
"Public_Key_Pinning" + DOCS_GA_PARAMS;
+const HPKP_ENABLED_PREF = "security.cert_pinning.hpkp.enabled";
const NON_BUILTIN_ROOT_PREF = "security.cert_pinning.process_headers_from_" +
"non_builtin_roots";
add_task(function* () {
registerCleanupFunction(() => {
+ Services.prefs.clearUserPref(HPKP_ENABLED_PREF);
Services.prefs.clearUserPref(NON_BUILTIN_ROOT_PREF);
});
+ Services.prefs.setBoolPref(HPKP_ENABLED_PREF, true);
+
yield loadTab(TEST_URI);
let hud = yield openConsole();
diff --git a/devtools/shared/webconsole/test/test_network_security-hpkp.html b/devtools/shared/webconsole/test/test_network_security-hpkp.html
index 55e2621a8d..bc1a9642c5 100644
--- a/devtools/shared/webconsole/test/test_network_security-hpkp.html
+++ b/devtools/shared/webconsole/test/test_network_security-hpkp.html
@@ -17,7 +17,8 @@
SimpleTest.waitForExplicitFinish();
let gCurrentTestCase = -1;
-const HPKP_PREF = "security.cert_pinning.process_headers_from_non_builtin_roots";
+const HPKP_ENABLED_PREF = "security.cert_pinning.hpkp.enabled";
+const PROCESS_HPKP_FROM_NON_BUILTIN_ROOTS_PREF = "security.cert_pinning.process_headers_from_non_builtin_roots";
// Static pins tested by unit/test_security-info-static-hpkp.js.
const TEST_CASES = [
@@ -41,11 +42,11 @@ const TEST_CASES = [
function startTest()
{
- // Need to enable this pref or pinning headers are rejected due test
- // certificate.
- Services.prefs.setBoolPref(HPKP_PREF, true);
+ Services.prefs.setBoolPref(HPKP_ENABLED_PREF, true);
+ Services.prefs.setBoolPref(PROCESS_HPKP_FROM_NON_BUILTIN_ROOTS_PREF, true);
SimpleTest.registerCleanupFunction(() => {
- Services.prefs.setBoolPref(HPKP_PREF, false);
+ Services.prefs.setBoolPref(HPKP_ENABLED_PREF, false);
+ Services.prefs.setBoolPref(PROCESS_HPKP_FROM_NON_BUILTIN_ROOTS_PREF, false);
// Reset pinning state.
let gSSService = Cc["@mozilla.org/ssservice;1"]
diff --git a/gfx/ots/README.mozilla b/gfx/ots/README.mozilla
index 4227930d5d..0353a99c5c 100644
--- a/gfx/ots/README.mozilla
+++ b/gfx/ots/README.mozilla
@@ -2,7 +2,7 @@ This is the Sanitiser for OpenType project, from http://code.google.com/p/ots/.
Our reference repository is https://github.com/khaledhosny/ots/.
-Current revision: f87b4556191e4132ef5c47365762eb88ace97fc3 (6.0.0)
+Current revision: 8bba749d9d5401726a7d7609ab914fdb5e92bfbe (8.0.0)
Upstream files included: LICENSE, src/, include/, tests/*.cc
diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-sanitiser.h
index 69a0c2251c..52cbd3aee8 100644
--- a/gfx/ots/include/opentype-sanitiser.h
+++ b/gfx/ots/include/opentype-sanitiser.h
@@ -35,13 +35,17 @@ typedef int int32_t;
typedef unsigned int uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
-#define ntohl(x) _byteswap_ulong (x)
-#define ntohs(x) _byteswap_ushort (x)
-#define htonl(x) _byteswap_ulong (x)
-#define htons(x) _byteswap_ushort (x)
+#define ots_ntohl(x) _byteswap_ulong (x)
+#define ots_ntohs(x) _byteswap_ushort (x)
+#define ots_htonl(x) _byteswap_ulong (x)
+#define ots_htons(x) _byteswap_ushort (x)
#else
#include
#include
+#define ots_ntohl(x) ntohl (x)
+#define ots_ntohs(x) ntohs (x)
+#define ots_htonl(x) htonl (x)
+#define ots_htons(x) htons (x)
#endif
#include
@@ -80,7 +84,7 @@ class OTSStream {
const size_t l = std::min(length, static_cast(4) - chksum_offset);
uint32_t tmp = 0;
std::memcpy(reinterpret_cast(&tmp) + chksum_offset, data, l);
- chksum_ += ntohl(tmp);
+ chksum_ += ots_ntohl(tmp);
length -= l;
offset += l;
}
@@ -89,7 +93,7 @@ class OTSStream {
uint32_t tmp;
std::memcpy(&tmp, reinterpret_cast(data) + offset,
sizeof(uint32_t));
- chksum_ += ntohl(tmp);
+ chksum_ += ots_ntohl(tmp);
length -= 4;
offset += 4;
}
@@ -99,7 +103,7 @@ class OTSStream {
uint32_t tmp = 0;
std::memcpy(&tmp,
reinterpret_cast(data) + offset, length);
- chksum_ += ntohl(tmp);
+ chksum_ += ots_ntohl(tmp);
}
return WriteRaw(data, orig_length);
@@ -127,27 +131,27 @@ class OTSStream {
}
bool WriteU16(uint16_t v) {
- v = htons(v);
+ v = ots_htons(v);
return Write(&v, sizeof(v));
}
bool WriteS16(int16_t v) {
- v = htons(v);
+ v = ots_htons(v);
return Write(&v, sizeof(v));
}
bool WriteU24(uint32_t v) {
- v = htonl(v);
+ v = ots_htonl(v);
return Write(reinterpret_cast(&v)+1, 3);
}
bool WriteU32(uint32_t v) {
- v = htonl(v);
+ v = ots_htonl(v);
return Write(&v, sizeof(v));
}
bool WriteS32(int32_t v) {
- v = htonl(v);
+ v = ots_htonl(v);
return Write(&v, sizeof(v));
}
diff --git a/gfx/ots/ots-lz4.patch b/gfx/ots/ots-lz4.patch
index a3f8fa210c..4251e72d69 100644
--- a/gfx/ots/ots-lz4.patch
+++ b/gfx/ots/ots-lz4.patch
@@ -1,7 +1,8 @@
diff --git a/gfx/ots/src/glat.cc b/gfx/ots/src/glat.cc
--- a/gfx/ots/src/glat.cc
+++ b/gfx/ots/src/glat.cc
-@@ -5,7 +5,7 @@
+@@ -4,9 +4,9 @@
+
#include "glat.h"
#include "gloc.h"
@@ -10,10 +11,12 @@ diff --git a/gfx/ots/src/glat.cc b/gfx/ots/src/glat.cc
#include
namespace ots {
-@@ -201,14 +201,15 @@ bool OpenTypeGLAT_v3::Parse(const uint8_t* data, size_t length,
- return DropGraphite("Illegal nested compression");
+
+@@ -212,16 +212,17 @@ bool OpenTypeGLAT_v3::Parse(const uint8_
+ return DropGraphite("Decompressed size exceeds 30MB: %gMB",
+ decompressed_size / (1024.0 * 1024.0));
}
- std::vector decompressed(this->compHead & FULL_SIZE);
+ std::vector decompressed(decompressed_size);
- int ret = LZ4_decompress_safe_partial(
+ size_t outputSize = 0;
+ bool ret = mozilla::Compression::LZ4::decompressPartial(
@@ -23,7 +26,7 @@ diff --git a/gfx/ots/src/glat.cc b/gfx/ots/src/glat.cc
+ reinterpret_cast(decompressed.data()),
decompressed.size(), // target output size
- decompressed.size()); // output buffer size
-- if (ret != decompressed.size()) {
+- if (ret < 0 || unsigned(ret) != decompressed.size()) {
- return DropGraphite("Decompression failed with error code %d", ret);
+ &outputSize); // return output size
+ if (!ret || outputSize != decompressed.size()) {
@@ -31,10 +34,12 @@ diff --git a/gfx/ots/src/glat.cc b/gfx/ots/src/glat.cc
}
return this->Parse(decompressed.data(), decompressed.size(), true);
}
+ default:
diff --git a/gfx/ots/src/silf.cc b/gfx/ots/src/silf.cc
--- a/gfx/ots/src/silf.cc
+++ b/gfx/ots/src/silf.cc
-@@ -5,7 +5,7 @@
+@@ -4,9 +4,9 @@
+
#include "silf.h"
#include "name.h"
@@ -43,10 +48,12 @@ diff --git a/gfx/ots/src/silf.cc b/gfx/ots/src/silf.cc
#include
namespace ots {
-@@ -39,14 +39,15 @@ bool OpenTypeSILF::Parse(const uint8_t* data, size_t length,
- return DropGraphite("Illegal nested compression");
+
+@@ -50,16 +50,17 @@ bool OpenTypeSILF::Parse(const uint8_t*
+ return DropGraphite("Decompressed size exceeds 30MB: %gMB",
+ decompressed_size / (1024.0 * 1024.0));
}
- std::vector decompressed(this->compHead & FULL_SIZE);
+ std::vector decompressed(decompressed_size);
- int ret = LZ4_decompress_safe_partial(
+ size_t outputSize = 0;
+ bool ret = mozilla::Compression::LZ4::decompressPartial(
@@ -56,7 +63,7 @@ diff --git a/gfx/ots/src/silf.cc b/gfx/ots/src/silf.cc
+ reinterpret_cast(decompressed.data()),
decompressed.size(), // target output size
- decompressed.size()); // output buffer size
-- if (ret != decompressed.size()) {
+- if (ret < 0 || unsigned(ret) != decompressed.size()) {
- return DropGraphite("Decompression failed with error code %d", ret);
+ &outputSize); // return output size
+ if (!ret || outputSize != decompressed.size()) {
@@ -64,3 +71,4 @@ diff --git a/gfx/ots/src/silf.cc b/gfx/ots/src/silf.cc
}
return this->Parse(decompressed.data(), decompressed.size(), true);
}
+ default:
diff --git a/gfx/ots/ots-visibility.patch b/gfx/ots/ots-visibility.patch
index 2bf5033cbe..c1265472b8 100644
--- a/gfx/ots/ots-visibility.patch
+++ b/gfx/ots/ots-visibility.patch
@@ -1,7 +1,8 @@
diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-sanitiser.h
--- a/gfx/ots/include/opentype-sanitiser.h
+++ b/gfx/ots/include/opentype-sanitiser.h
-@@ -5,6 +5,26 @@
+@@ -4,8 +4,28 @@
+
#ifndef OPENTYPE_SANITISER_H_
#define OPENTYPE_SANITISER_H_
@@ -28,7 +29,9 @@ diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-san
#if defined(_WIN32)
#include
typedef signed char int8_t;
-@@ -161,7 +181,7 @@ enum TableAction {
+ typedef unsigned char uint8_t;
+@@ -164,9 +184,9 @@ enum TableAction {
+ TABLE_ACTION_PASSTHRU, // Serialize the table unchanged
TABLE_ACTION_DROP // Drop the table
};
@@ -37,3 +40,4 @@ diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-san
public:
OTSContext() {}
virtual ~OTSContext() {}
+
diff --git a/gfx/ots/src/avar.cc b/gfx/ots/src/avar.cc
new file mode 100644
index 0000000000..2a431b1c23
--- /dev/null
+++ b/gfx/ots/src/avar.cc
@@ -0,0 +1,109 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "avar.h"
+
+#include "fvar.h"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeAVAR
+// -----------------------------------------------------------------------------
+
+bool OpenTypeAVAR::Parse(const uint8_t* data, size_t length) {
+ Buffer table(data, length);
+ if (!table.ReadU16(&this->majorVersion) ||
+ !table.ReadU16(&this->minorVersion) ||
+ !table.ReadU16(&this->reserved) ||
+ !table.ReadU16(&this->axisCount)) {
+ return Drop("Failed to read table header");
+ }
+ if (this->majorVersion != 1) {
+ return Drop("Unknown table version");
+ }
+ if (this->minorVersion > 0) {
+ // we only know how to serialize version 1.0
+ Warning("Downgrading minor version to 0");
+ this->minorVersion = 0;
+ }
+ if (this->reserved != 0) {
+ Warning("Expected reserved=0");
+ this->reserved = 0;
+ }
+
+ OpenTypeFVAR* fvar = static_cast(
+ GetFont()->GetTypedTable(OTS_TAG_FVAR));
+ if (!fvar) {
+ return DropVariations("Required fvar table is missing");
+ }
+ if (axisCount != fvar->AxisCount()) {
+ return Drop("Axis count mismatch");
+ }
+
+ for (size_t i = 0; i < this->axisCount; i++) {
+ this->axisSegmentMaps.emplace_back();
+ uint16_t positionMapCount;
+ if (!table.ReadU16(&positionMapCount)) {
+ return Drop("Failed to read position map count");
+ }
+ int foundRequiredMappings = 0;
+ for (size_t j = 0; j < positionMapCount; j++) {
+ AxisValueMap map;
+ if (!table.ReadS16(&map.fromCoordinate) ||
+ !table.ReadS16(&map.toCoordinate)) {
+ return Drop("Failed to read axis value map");
+ }
+ if (map.fromCoordinate < -0x4000 ||
+ map.fromCoordinate > 0x4000 ||
+ map.toCoordinate < -0x4000 ||
+ map.toCoordinate > 0x4000) {
+ return Drop("Axis value map coordinate out of range");
+ }
+ if (j > 0) {
+ if (map.fromCoordinate <= this->axisSegmentMaps[i].back().fromCoordinate ||
+ map.toCoordinate < this->axisSegmentMaps[i].back().toCoordinate) {
+ return Drop("Axis value map out of order");
+ }
+ }
+ if ((map.fromCoordinate == -0x4000 && map.toCoordinate == -0x4000) ||
+ (map.fromCoordinate == 0 && map.toCoordinate == 0) ||
+ (map.fromCoordinate == 0x4000 && map.toCoordinate == 0x4000)) {
+ ++foundRequiredMappings;
+ }
+ this->axisSegmentMaps[i].push_back(map);
+ }
+ if (positionMapCount > 0 && foundRequiredMappings != 3) {
+ return Drop("A required mapping (for -1, 0 or 1) is missing");
+ }
+ }
+
+ return true;
+}
+
+bool OpenTypeAVAR::Serialize(OTSStream* out) {
+ if (!out->WriteU16(this->majorVersion) ||
+ !out->WriteU16(this->minorVersion) ||
+ !out->WriteU16(this->reserved) ||
+ !out->WriteU16(this->axisCount)) {
+ return Error("Failed to write table");
+ }
+
+ for (size_t i = 0; i < this->axisCount; i++) {
+ const auto& axisValueMap = this->axisSegmentMaps[i];
+ if (!out->WriteU16(axisValueMap.size())) {
+ return Error("Failed to write table");
+ }
+ for (size_t j = 0; j < axisValueMap.size(); j++) {
+ if (!out->WriteS16(axisValueMap[j].fromCoordinate) ||
+ !out->WriteS16(axisValueMap[j].toCoordinate)) {
+ return Error("Failed to write table");
+ }
+ }
+ }
+
+ return true;
+}
+
+} // namespace ots
diff --git a/gfx/ots/src/avar.h b/gfx/ots/src/avar.h
new file mode 100644
index 0000000000..756651c047
--- /dev/null
+++ b/gfx/ots/src/avar.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef OTS_AVAR_H_
+#define OTS_AVAR_H_
+
+#include "ots.h"
+
+#include
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeAVAR Interface
+// -----------------------------------------------------------------------------
+
+class OpenTypeAVAR : public Table {
+ public:
+ explicit OpenTypeAVAR(Font* font, uint32_t tag)
+ : Table(font, tag, tag) { }
+
+ bool Parse(const uint8_t* data, size_t length);
+ bool Serialize(OTSStream* out);
+
+ private:
+ uint16_t majorVersion;
+ uint16_t minorVersion;
+ uint16_t reserved;
+ uint16_t axisCount;
+
+ struct AxisValueMap {
+ int16_t fromCoordinate;
+ int16_t toCoordinate;
+ };
+
+ std::vector> axisSegmentMaps;
+};
+
+} // namespace ots
+
+#endif // OTS_AVAR_H_
diff --git a/gfx/ots/src/cff.cc b/gfx/ots/src/cff.cc
index 57868e3639..b0affd510b 100644
--- a/gfx/ots/src/cff.cc
+++ b/gfx/ots/src/cff.cc
@@ -9,7 +9,8 @@
#include
#include "maxp.h"
-#include "cff_type2_charstring.h"
+#include "cff_charstring.h"
+#include "variations.h"
// CFF - PostScript font program (Compact Font Format) table
// http://www.microsoft.com/typography/otspec/cff.htm
@@ -28,6 +29,7 @@ enum DICT_OPERAND_TYPE {
enum DICT_DATA_TYPE {
DICT_DATA_TOPLEVEL,
DICT_DATA_FDARRAY,
+ DICT_DATA_PRIVATE,
};
enum FONT_FORMAT {
@@ -39,7 +41,9 @@ enum FONT_FORMAT {
// see Appendix. A
const size_t kNStdString = 390;
-bool ReadOffset(ots::Buffer *table, uint8_t off_size, uint32_t *offset) {
+typedef std::pair Operand;
+
+bool ReadOffset(ots::Buffer &table, uint8_t off_size, uint32_t *offset) {
if (off_size > 4) {
return OTS_FAILURE();
}
@@ -47,7 +51,7 @@ bool ReadOffset(ots::Buffer *table, uint8_t off_size, uint32_t *offset) {
uint32_t tmp32 = 0;
for (unsigned i = 0; i < off_size; ++i) {
uint8_t tmp8 = 0;
- if (!table->ReadU8(&tmp8)) {
+ if (!table.ReadU8(&tmp8)) {
return OTS_FAILURE();
}
tmp32 <<= 8;
@@ -57,39 +61,47 @@ bool ReadOffset(ots::Buffer *table, uint8_t off_size, uint32_t *offset) {
return true;
}
-bool ParseIndex(ots::Buffer *table, ots::CFFIndex *index) {
- index->off_size = 0;
- index->offsets.clear();
+bool ParseIndex(ots::Buffer &table, ots::CFFIndex &index, bool cff2 = false) {
+ index.off_size = 0;
+ index.offsets.clear();
- if (!table->ReadU16(&(index->count))) {
- return OTS_FAILURE();
+ if (cff2) {
+ if (!table.ReadU32(&(index.count))) {
+ return OTS_FAILURE();
+ }
+ } else {
+ uint16_t count;
+ if (!table.ReadU16(&count)) {
+ return OTS_FAILURE();
+ }
+ index.count = count;
}
- if (index->count == 0) {
+
+ if (index.count == 0) {
// An empty INDEX.
- index->offset_to_next = table->offset();
+ index.offset_to_next = table.offset();
return true;
}
- if (!table->ReadU8(&(index->off_size))) {
+ if (!table.ReadU8(&(index.off_size))) {
return OTS_FAILURE();
}
- if ((index->off_size == 0) ||
- (index->off_size > 4)) {
+ if (index.off_size < 1 || index.off_size > 4) {
return OTS_FAILURE();
}
- const size_t array_size = (index->count + 1) * index->off_size;
+ const size_t array_size = (index.count + 1) * index.off_size;
// less than ((64k + 1) * 4), thus does not overflow.
- const size_t object_data_offset = table->offset() + array_size;
+ const size_t object_data_offset = table.offset() + array_size;
// does not overflow too, since offset() <= 1GB.
- if (object_data_offset >= table->length()) {
+ if (object_data_offset >= table.length()) {
return OTS_FAILURE();
}
- for (unsigned i = 0; i <= index->count; ++i) { // '<=' is not a typo.
+ for (unsigned i = 0; i <= index.count; ++i) { // '<=' is not a typo.
uint32_t rel_offset = 0;
- if (!ReadOffset(table, index->off_size, &rel_offset)) {
+ if (!ReadOffset(table, index.off_size, &rel_offset)) {
return OTS_FAILURE();
}
if (rel_offset < 1) {
@@ -99,69 +111,64 @@ bool ParseIndex(ots::Buffer *table, ots::CFFIndex *index) {
return OTS_FAILURE();
}
- if (rel_offset > table->length()) {
+ if (rel_offset > table.length()) {
return OTS_FAILURE();
}
// does not underflow.
- if (object_data_offset > table->length() - (rel_offset - 1)) {
+ if (object_data_offset > table.length() - (rel_offset - 1)) {
return OTS_FAILURE();
}
- index->offsets.push_back(
+ index.offsets.push_back(
object_data_offset + (rel_offset - 1)); // less than length(), 1GB.
}
- for (unsigned i = 1; i < index->offsets.size(); ++i) {
+ for (unsigned i = 1; i < index.offsets.size(); ++i) {
// We allow consecutive identical offsets here for zero-length strings.
// See http://crbug.com/69341 for more details.
- if (index->offsets[i] < index->offsets[i - 1]) {
+ if (index.offsets[i] < index.offsets[i - 1]) {
return OTS_FAILURE();
}
}
- index->offset_to_next = index->offsets.back();
+ index.offset_to_next = index.offsets.back();
return true;
}
bool ParseNameData(
ots::Buffer *table, const ots::CFFIndex &index, std::string* out_name) {
uint8_t name[256] = {0};
- if (index.offsets.size() == 0) { // just in case.
+
+ const size_t length = index.offsets[1] - index.offsets[0];
+ // font names should be no longer than 127 characters.
+ if (length > 127) {
return OTS_FAILURE();
}
- for (unsigned i = 1; i < index.offsets.size(); ++i) {
- const size_t length = index.offsets[i] - index.offsets[i - 1];
- // font names should be no longer than 127 characters.
- if (length > 127) {
+
+ table->set_offset(index.offsets[0]);
+ if (!table->Read(name, length)) {
+ return OTS_FAILURE();
+ }
+
+ for (size_t i = 0; i < length; ++i) {
+ // setting the first byte to NUL is allowed.
+ if (i == 0 && name[i] == 0) continue;
+ // non-ASCII characters are not recommended (except the first character).
+ if (name[i] < 33 || name[i] > 126) {
return OTS_FAILURE();
}
-
- table->set_offset(index.offsets[i - 1]);
- if (!table->Read(name, length)) {
+ // [, ], ... are not allowed.
+ if (std::strchr("[](){}<>/% ", name[i])) {
return OTS_FAILURE();
}
-
- for (size_t j = 0; j < length; ++j) {
- // setting the first byte to NUL is allowed.
- if (j == 0 && name[j] == 0) continue;
- // non-ASCII characters are not recommended (except the first character).
- if (name[j] < 33 || name[j] > 126) {
- return OTS_FAILURE();
- }
- // [, ], ... are not allowed.
- if (std::strchr("[](){}<>/% ", name[j])) {
- return OTS_FAILURE();
- }
- }
}
*out_name = reinterpret_cast(name);
return true;
}
-bool CheckOffset(const std::pair& operand,
- size_t table_length) {
+bool CheckOffset(const Operand& operand, size_t table_length) {
if (operand.second != DICT_OPERAND_INTEGER) {
return OTS_FAILURE();
}
@@ -171,8 +178,7 @@ bool CheckOffset(const std::pair& operand,
return true;
}
-bool CheckSid(const std::pair& operand,
- size_t sid_max) {
+bool CheckSid(const Operand& operand, size_t sid_max) {
if (operand.second != DICT_OPERAND_INTEGER) {
return OTS_FAILURE();
}
@@ -182,30 +188,28 @@ bool CheckSid(const std::pair& operand,
return true;
}
-bool ParseDictDataBcd(
- ots::Buffer *table,
- std::vector > *operands) {
+bool ParseDictDataBcd(ots::Buffer &table, std::vector &operands) {
bool read_decimal_point = false;
bool read_e = false;
uint8_t nibble = 0;
size_t count = 0;
while (true) {
- if (!table->ReadU8(&nibble)) {
+ if (!table.ReadU8(&nibble)) {
return OTS_FAILURE();
}
if ((nibble & 0xf0) == 0xf0) {
if ((nibble & 0xf) == 0xf) {
// TODO(yusukes): would be better to store actual double value,
// rather than the dummy integer.
- operands->push_back(std::make_pair(static_cast(0),
+ operands.push_back(std::make_pair(static_cast(0),
DICT_OPERAND_REAL));
return true;
}
return OTS_FAILURE();
}
if ((nibble & 0x0f) == 0x0f) {
- operands->push_back(std::make_pair(static_cast(0),
+ operands.push_back(std::make_pair(static_cast(0),
DICT_OPERAND_REAL));
return true;
}
@@ -242,18 +246,17 @@ bool ParseDictDataBcd(
}
}
-bool ParseDictDataEscapedOperator(
- ots::Buffer *table,
- std::vector > *operands) {
+bool ParseDictDataEscapedOperator(ots::Buffer &table,
+ std::vector &operands) {
uint8_t op = 0;
- if (!table->ReadU8(&op)) {
+ if (!table.ReadU8(&op)) {
return OTS_FAILURE();
}
if ((op <= 14) ||
(op >= 17 && op <= 23) ||
(op >= 30 && op <= 38)) {
- operands->push_back(std::make_pair((12U << 8) + op, DICT_OPERATOR));
+ operands.push_back(std::make_pair((12U << 8) + op, DICT_OPERATOR));
return true;
}
@@ -261,9 +264,8 @@ bool ParseDictDataEscapedOperator(
return OTS_FAILURE();
}
-bool ParseDictDataNumber(
- ots::Buffer *table, uint8_t b0,
- std::vector > *operands) {
+bool ParseDictDataNumber(ots::Buffer &table, uint8_t b0,
+ std::vector &operands) {
uint8_t b1 = 0;
uint8_t b2 = 0;
uint8_t b3 = 0;
@@ -271,22 +273,22 @@ bool ParseDictDataNumber(
switch (b0) {
case 28: // shortint
- if (!table->ReadU8(&b1) ||
- !table->ReadU8(&b2)) {
+ if (!table.ReadU8(&b1) ||
+ !table.ReadU8(&b2)) {
return OTS_FAILURE();
}
- operands->push_back(std::make_pair(
+ operands.push_back(std::make_pair(
static_cast((b1 << 8) + b2), DICT_OPERAND_INTEGER));
return true;
case 29: // longint
- if (!table->ReadU8(&b1) ||
- !table->ReadU8(&b2) ||
- !table->ReadU8(&b3) ||
- !table->ReadU8(&b4)) {
+ if (!table.ReadU8(&b1) ||
+ !table.ReadU8(&b2) ||
+ !table.ReadU8(&b3) ||
+ !table.ReadU8(&b4)) {
return OTS_FAILURE();
}
- operands->push_back(std::make_pair(
+ operands.push_back(std::make_pair(
static_cast((b1 << 24) + (b2 << 16) + (b3 << 8) + b4),
DICT_OPERAND_INTEGER));
return true;
@@ -302,12 +304,12 @@ bool ParseDictDataNumber(
if (b0 >=32 && b0 <=246) {
result = b0 - 139;
} else if (b0 >=247 && b0 <= 250) {
- if (!table->ReadU8(&b1)) {
+ if (!table.ReadU8(&b1)) {
return OTS_FAILURE();
}
result = (b0 - 247) * 256 + b1 + 108;
} else if (b0 >= 251 && b0 <= 254) {
- if (!table->ReadU8(&b1)) {
+ if (!table.ReadU8(&b1)) {
return OTS_FAILURE();
}
result = -(b0 - 251) * 256 + b1 - 108;
@@ -315,22 +317,21 @@ bool ParseDictDataNumber(
return OTS_FAILURE();
}
- operands->push_back(std::make_pair(result, DICT_OPERAND_INTEGER));
+ operands.push_back(std::make_pair(result, DICT_OPERAND_INTEGER));
return true;
}
-bool ParseDictDataReadNext(
- ots::Buffer *table,
- std::vector > *operands) {
+bool ParseDictDataReadNext(ots::Buffer &table,
+ std::vector &operands) {
uint8_t op = 0;
- if (!table->ReadU8(&op)) {
+ if (!table.ReadU8(&op)) {
return OTS_FAILURE();
}
- if (op <= 21) {
+ if (op <= 24) {
if (op == 12) {
return ParseDictDataEscapedOperator(table, operands);
}
- operands->push_back(std::make_pair(
+ operands.push_back(std::make_pair(
static_cast(op), DICT_OPERATOR));
return true;
} else if (op <= 27 || op == 31 || op == 255) {
@@ -341,12 +342,69 @@ bool ParseDictDataReadNext(
return ParseDictDataNumber(table, op, operands);
}
+bool OperandsOverflow(std::vector& operands, bool cff2) {
+ // An operator may be preceded by up to a maximum of 48 operands in CFF1 and
+ // 513 operands in CFF2.
+ if ((cff2 && operands.size() > ots::kMaxCFF2ArgumentStack) ||
+ (!cff2 && operands.size() > ots::kMaxCFF1ArgumentStack)) {
+ return true;
+ }
+ return false;
+}
+
+bool ParseDictDataReadOperands(ots::Buffer& dict,
+ std::vector& operands,
+ bool cff2) {
+ if (!ParseDictDataReadNext(dict, operands)) {
+ return OTS_FAILURE();
+ }
+ if (operands.empty()) {
+ return OTS_FAILURE();
+ }
+ if (OperandsOverflow(operands, cff2)) {
+ return OTS_FAILURE();
+ }
+ return true;
+}
+
+bool ValidCFF2DictOp(uint32_t op, DICT_DATA_TYPE type) {
+ if (type == DICT_DATA_TOPLEVEL) {
+ switch (op) {
+ case (12U << 8) + 7: // FontMatrix
+ case 17: // CharStrings
+ case (12U << 8) + 36: // FDArray
+ case (12U << 8) + 37: // FDSelect
+ case 24: // vstore
+ return true;
+ default:
+ return false;
+ }
+ } else if (type == DICT_DATA_FDARRAY) {
+ if (op == 18) // Private DICT
+ return true;
+ } else if (type == DICT_DATA_PRIVATE) {
+ switch (op) {
+ case (12U << 8) + 14: // ForceBold
+ case (12U << 8) + 19: // initialRandomSeed
+ case 20: // defaultWidthX
+ case 21: // nominalWidthX
+ return false;
+ default:
+ return true;
+ }
+ }
+
+ return false;
+}
+
bool ParsePrivateDictData(
- const uint8_t *data,
- size_t table_length, size_t offset, size_t dict_length,
+ ots::Buffer &table, size_t offset, size_t dict_length,
DICT_DATA_TYPE type, ots::OpenTypeCFF *out_cff) {
- ots::Buffer table(data + offset, dict_length);
- std::vector > operands;
+ ots::Buffer dict(table.buffer() + offset, dict_length);
+ std::vector operands;
+ bool cff2 = (out_cff->major == 2);
+ bool blend_seen = false;
+ uint32_t vsindex = 0;
// Since a Private DICT for FDArray might not have a Local Subr (e.g. Hiragino
// Kaku Gothic Std W8), we create an empty Local Subr here to match the size
@@ -355,15 +413,8 @@ bool ParsePrivateDictData(
out_cff->local_subrs_per_font.push_back(new ots::CFFIndex);
}
- while (table.offset() < dict_length) {
- if (!ParseDictDataReadNext(&table, &operands)) {
- return OTS_FAILURE();
- }
- if (operands.empty()) {
- return OTS_FAILURE();
- }
- if (operands.size() > 48) {
- // An operator may be preceded by up to a maximum of 48 operands.
+ while (dict.offset() < dict.length()) {
+ if (!ParseDictDataReadOperands(dict, operands, cff2)) {
return OTS_FAILURE();
}
if (operands.back().second != DICT_OPERATOR) {
@@ -374,13 +425,18 @@ bool ParsePrivateDictData(
const uint32_t op = operands.back().first;
operands.pop_back();
+ if (cff2 && !ValidCFF2DictOp(op, DICT_DATA_PRIVATE)) {
+ return OTS_FAILURE();
+ }
+
+ bool clear_operands = true;
switch (op) {
// hints
case 6: // BlueValues
case 7: // OtherBlues
case 8: // FamilyBlues
case 9: // FamilyOtherBlues
- if (operands.empty() || (operands.size() % 2) != 0) {
+ if ((operands.size() % 2) != 0) {
return OTS_FAILURE();
}
break;
@@ -420,12 +476,11 @@ bool ParsePrivateDictData(
if (operands.back().first >= 1024 * 1024 * 1024) {
return OTS_FAILURE();
}
- if (operands.back().first + offset >= table_length) {
+ if (operands.back().first + offset >= table.length()) {
return OTS_FAILURE();
}
// parse "16. Local Subrs INDEX"
- ots::Buffer cff_table(data, table_length);
- cff_table.set_offset(operands.back().first + offset);
+ table.set_offset(operands.back().first + offset);
ots::CFFIndex *local_subrs_index = NULL;
if (type == DICT_DATA_FDARRAY) {
if (out_cff->local_subrs_per_font.empty()) {
@@ -439,7 +494,7 @@ bool ParsePrivateDictData(
local_subrs_index = new ots::CFFIndex;
out_cff->local_subrs = local_subrs_index;
}
- if (!ParseIndex(&cff_table, local_subrs_index)) {
+ if (!ParseIndex(table, *local_subrs_index, cff2)) {
return OTS_FAILURE();
}
break;
@@ -458,42 +513,125 @@ bool ParsePrivateDictData(
}
break;
+ case 22: { // vsindex
+ if (!cff2) {
+ return OTS_FAILURE();
+ }
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if (operands.back().second != DICT_OPERAND_INTEGER) {
+ return OTS_FAILURE();
+ }
+ if (blend_seen) {
+ return OTS_FAILURE();
+ }
+ vsindex = operands.back().first;
+ if (vsindex >= out_cff->region_index_count.size()) {
+ return OTS_FAILURE();
+ }
+ break;
+ }
+
+ case 23: { // blend
+ if (!cff2) {
+ return OTS_FAILURE();
+ }
+ if (operands.size() < 1) {
+ return OTS_FAILURE();
+ }
+ if (vsindex >= out_cff->region_index_count.size()) {
+ return OTS_FAILURE();
+ }
+ uint16_t k = out_cff->region_index_count.at(vsindex);
+ uint16_t n = operands.back().first;
+ if (operands.size() < n * (k + 1) + 1) {
+ return OTS_FAILURE();
+ }
+ size_t operands_size = operands.size();
+ // Keep the 1st n operands on the stack for the next operator to use
+ // and pop the rest. There can be multiple consecutive blend operator,
+ // so this makes sure the operands of all of them are kept on the
+ // stack.
+ while (operands.size() > operands_size - ((n * k) + 1))
+ operands.pop_back();
+ clear_operands = false;
+ blend_seen = true;
+ break;
+ }
+
default:
return OTS_FAILURE();
}
- operands.clear();
+ if (clear_operands) {
+ operands.clear();
+ }
}
return true;
}
-bool ParseDictData(const uint8_t *data, size_t table_length,
- const ots::CFFIndex &index, uint16_t glyphs,
- size_t sid_max, DICT_DATA_TYPE type,
+bool ParseVariationStore(ots::OpenTypeCFF& out_cff, ots::Buffer& table) {
+ uint16_t length;
+
+ if (!table.ReadU16(&length)) {
+ return OTS_FAILURE();
+ }
+
+ // Empty VariationStore is allowed.
+ if (!length) {
+ return true;
+ }
+
+ if (length > table.remaining()) {
+ return OTS_FAILURE();
+ }
+
+ if (!ParseItemVariationStore(out_cff.GetFont(),
+ table.buffer() + table.offset(), length,
+ &(out_cff.region_index_count))) {
+ return OTS_FAILURE();
+ }
+
+ return true;
+}
+
+bool ParseDictData(ots::Buffer& table, ots::Buffer& dict,
+ uint16_t glyphs, size_t sid_max, DICT_DATA_TYPE type,
+ ots::OpenTypeCFF *out_cff);
+
+bool ParseDictData(ots::Buffer& table, const ots::CFFIndex &index,
+ uint16_t glyphs, size_t sid_max, DICT_DATA_TYPE type,
ots::OpenTypeCFF *out_cff) {
for (unsigned i = 1; i < index.offsets.size(); ++i) {
- if (type == DICT_DATA_TOPLEVEL) {
- out_cff->char_strings_array.push_back(new ots::CFFIndex);
- }
size_t dict_length = index.offsets[i] - index.offsets[i - 1];
- ots::Buffer table(data + index.offsets[i - 1], dict_length);
+ ots::Buffer dict(table.buffer() + index.offsets[i - 1], dict_length);
- std::vector > operands;
+ if (!ParseDictData(table, dict, glyphs, sid_max, type, out_cff)) {
+ return OTS_FAILURE();
+ }
+ }
+ return true;
+}
- FONT_FORMAT font_format = FORMAT_UNKNOWN;
- bool have_ros = false;
- uint16_t charstring_glyphs = 0;
- size_t charset_offset = 0;
+bool ParseDictData(ots::Buffer& table, ots::Buffer& dict,
+ uint16_t glyphs, size_t sid_max, DICT_DATA_TYPE type,
+ ots::OpenTypeCFF *out_cff) {
+ bool cff2 = (out_cff->major == 2);
+ std::vector operands;
- while (table.offset() < dict_length) {
- if (!ParseDictDataReadNext(&table, &operands)) {
- return OTS_FAILURE();
- }
- if (operands.empty()) {
- return OTS_FAILURE();
- }
- if (operands.size() > 48) {
- // An operator may be preceded by up to a maximum of 48 operands.
+ FONT_FORMAT font_format = FORMAT_UNKNOWN;
+ bool have_ros = false;
+ bool have_charstrings = false;
+ bool have_vstore = false;
+ size_t charset_offset = 0;
+
+ if (cff2) {
+ // Parse VariationStore first, since it might be referenced in other places
+ // (e.g. FDArray) that might be parsed after it.
+ size_t dict_offset = dict.offset();
+ while (dict.offset() < dict.length()) {
+ if (!ParseDictDataReadOperands(dict, operands, cff2)) {
return OTS_FAILURE();
}
if (operands.back().second != DICT_OPERATOR) continue;
@@ -502,399 +640,503 @@ bool ParseDictData(const uint8_t *data, size_t table_length,
const uint32_t op = operands.back().first;
operands.pop_back();
- switch (op) {
- // SID
- case 0: // version
- case 1: // Notice
- case 2: // Copyright
- case 3: // FullName
- case 4: // FamilyName
- case (12U << 8) + 0: // Copyright
- case (12U << 8) + 21: // PostScript
- case (12U << 8) + 22: // BaseFontName
- case (12U << 8) + 38: // FontName
- if (operands.size() != 1) {
- return OTS_FAILURE();
- }
- if (!CheckSid(operands.back(), sid_max)) {
- return OTS_FAILURE();
- }
- break;
-
- // array
- case 5: // FontBBox
- case 14: // XUID
- case (12U << 8) + 7: // FontMatrix
- case (12U << 8) + 23: // BaseFontBlend (delta)
- if (operands.empty()) {
- return OTS_FAILURE();
- }
- break;
-
- // number
- case 13: // UniqueID
- case (12U << 8) + 2: // ItalicAngle
- case (12U << 8) + 3: // UnderlinePosition
- case (12U << 8) + 4: // UnderlineThickness
- case (12U << 8) + 5: // PaintType
- case (12U << 8) + 8: // StrokeWidth
- case (12U << 8) + 20: // SyntheticBase
- if (operands.size() != 1) {
- return OTS_FAILURE();
- }
- break;
- case (12U << 8) + 31: // CIDFontVersion
- case (12U << 8) + 32: // CIDFontRevision
- case (12U << 8) + 33: // CIDFontType
- case (12U << 8) + 34: // CIDCount
- case (12U << 8) + 35: // UIDBase
- if (operands.size() != 1) {
- return OTS_FAILURE();
- }
- if (font_format != FORMAT_CID_KEYED) {
- return OTS_FAILURE();
- }
- break;
- case (12U << 8) + 6: // CharstringType
- if (operands.size() != 1) {
- return OTS_FAILURE();
- }
- if(operands.back().second != DICT_OPERAND_INTEGER) {
- return OTS_FAILURE();
- }
- if (operands.back().first != 2) {
- // We only support the "Type 2 Charstring Format."
- // TODO(yusukes): Support Type 1 format? Is that still in use?
- return OTS_FAILURE();
- }
- break;
-
- // boolean
- case (12U << 8) + 1: // isFixedPitch
- if (operands.size() != 1) {
- return OTS_FAILURE();
- }
- if (operands.back().second != DICT_OPERAND_INTEGER) {
- return OTS_FAILURE();
- }
- if (operands.back().first >= 2) {
- return OTS_FAILURE();
- }
- break;
-
- // offset(0)
- case 15: // charset
- if (operands.size() != 1) {
- return OTS_FAILURE();
- }
- if (operands.back().first <= 2) {
- // predefined charset, ISOAdobe, Expert or ExpertSubset, is used.
- break;
- }
- if (!CheckOffset(operands.back(), table_length)) {
- return OTS_FAILURE();
- }
- if (charset_offset) {
- return OTS_FAILURE(); // multiple charset tables?
- }
- charset_offset = operands.back().first;
- break;
-
- case 16: { // Encoding
- if (operands.size() != 1) {
- return OTS_FAILURE();
- }
- if (operands.back().first <= 1) {
- break; // predefined encoding, "Standard" or "Expert", is used.
- }
- if (!CheckOffset(operands.back(), table_length)) {
- return OTS_FAILURE();
- }
-
- // parse sub dictionary INDEX.
- ots::Buffer cff_table(data, table_length);
- cff_table.set_offset(operands.back().first);
- uint8_t format = 0;
- if (!cff_table.ReadU8(&format)) {
- return OTS_FAILURE();
- }
- if (format & 0x80) {
- // supplemental encoding is not supported at the moment.
- return OTS_FAILURE();
- }
- // TODO(yusukes): support & parse supplemental encoding tables.
- break;
- }
-
- case 17: { // CharStrings
- if (type != DICT_DATA_TOPLEVEL) {
- return OTS_FAILURE();
- }
- if (operands.size() != 1) {
- return OTS_FAILURE();
- }
- if (!CheckOffset(operands.back(), table_length)) {
- return OTS_FAILURE();
- }
- // parse "14. CharStrings INDEX"
- ots::Buffer cff_table(data, table_length);
- cff_table.set_offset(operands.back().first);
- ots::CFFIndex *charstring_index = out_cff->char_strings_array.back();
- if (!ParseIndex(&cff_table, charstring_index)) {
- return OTS_FAILURE();
- }
- if (charstring_index->count < 2) {
- return OTS_FAILURE();
- }
- if (charstring_glyphs) {
- return OTS_FAILURE(); // multiple charstring tables?
- }
- charstring_glyphs = charstring_index->count;
- if (charstring_glyphs != glyphs) {
- return OTS_FAILURE(); // CFF and maxp have different number of glyphs?
- }
- break;
- }
-
- case (12U << 8) + 36: { // FDArray
- if (type != DICT_DATA_TOPLEVEL) {
- return OTS_FAILURE();
- }
- if (operands.size() != 1) {
- return OTS_FAILURE();
- }
- if (!CheckOffset(operands.back(), table_length)) {
- return OTS_FAILURE();
- }
-
- // parse sub dictionary INDEX.
- ots::Buffer cff_table(data, table_length);
- cff_table.set_offset(operands.back().first);
- ots::CFFIndex sub_dict_index;
- if (!ParseIndex(&cff_table, &sub_dict_index)) {
- return OTS_FAILURE();
- }
- if (!ParseDictData(data, table_length,
- sub_dict_index,
- glyphs, sid_max, DICT_DATA_FDARRAY,
- out_cff)) {
- return OTS_FAILURE();
- }
- if (out_cff->font_dict_length != 0) {
- return OTS_FAILURE(); // two or more FDArray found.
- }
- out_cff->font_dict_length = sub_dict_index.count;
- break;
- }
-
- case (12U << 8) + 37: { // FDSelect
- if (type != DICT_DATA_TOPLEVEL) {
- return OTS_FAILURE();
- }
- if (operands.size() != 1) {
- return OTS_FAILURE();
- }
- if (!CheckOffset(operands.back(), table_length)) {
- return OTS_FAILURE();
- }
-
- // parse FDSelect data structure
- ots::Buffer cff_table(data, table_length);
- cff_table.set_offset(operands.back().first);
- uint8_t format = 0;
- if (!cff_table.ReadU8(&format)) {
- return OTS_FAILURE();
- }
- if (format == 0) {
- for (uint16_t j = 0; j < glyphs; ++j) {
- uint8_t fd_index = 0;
- if (!cff_table.ReadU8(&fd_index)) {
- return OTS_FAILURE();
- }
- (out_cff->fd_select)[j] = fd_index;
- }
- } else if (format == 3) {
- uint16_t n_ranges = 0;
- if (!cff_table.ReadU16(&n_ranges)) {
- return OTS_FAILURE();
- }
- if (n_ranges == 0) {
- return OTS_FAILURE();
- }
-
- uint16_t last_gid = 0;
- uint8_t fd_index = 0;
- for (unsigned j = 0; j < n_ranges; ++j) {
- uint16_t first = 0; // GID
- if (!cff_table.ReadU16(&first)) {
- return OTS_FAILURE();
- }
-
- // Sanity checks.
- if ((j == 0) && (first != 0)) {
- return OTS_FAILURE();
- }
- if ((j != 0) && (last_gid >= first)) {
- return OTS_FAILURE(); // not increasing order.
- }
-
- // Copy the mapping to |out_cff->fd_select|.
- if (j != 0) {
- for (uint16_t k = last_gid; k < first; ++k) {
- if (!out_cff->fd_select.insert(
- std::make_pair(k, fd_index)).second) {
- return OTS_FAILURE();
- }
- }
- }
-
- if (!cff_table.ReadU8(&fd_index)) {
- return OTS_FAILURE();
- }
- last_gid = first;
- // TODO(yusukes): check GID?
- }
- uint16_t sentinel = 0;
- if (!cff_table.ReadU16(&sentinel)) {
- return OTS_FAILURE();
- }
- if (last_gid >= sentinel) {
- return OTS_FAILURE();
- }
- for (uint16_t k = last_gid; k < sentinel; ++k) {
- if (!out_cff->fd_select.insert(
- std::make_pair(k, fd_index)).second) {
- return OTS_FAILURE();
- }
- }
- } else {
- // unknown format
- return OTS_FAILURE();
- }
- break;
- }
-
- // Private DICT (2 * number)
- case 18: {
- if (operands.size() != 2) {
- return OTS_FAILURE();
- }
- if (operands.back().second != DICT_OPERAND_INTEGER) {
- return OTS_FAILURE();
- }
- const uint32_t private_offset = operands.back().first;
- operands.pop_back();
- if (operands.back().second != DICT_OPERAND_INTEGER) {
- return OTS_FAILURE();
- }
- const uint32_t private_length = operands.back().first;
- if (private_offset > table_length) {
- return OTS_FAILURE();
- }
- if (private_length >= table_length) {
- return OTS_FAILURE();
- }
- if (private_length + private_offset > table_length) {
- return OTS_FAILURE();
- }
- // parse "15. Private DICT Data"
- if (!ParsePrivateDictData(data, table_length,
- private_offset, private_length,
- type, out_cff)) {
- return OTS_FAILURE();
- }
- break;
- }
-
- // ROS
- case (12U << 8) + 30:
- if (font_format != FORMAT_UNKNOWN) {
- return OTS_FAILURE();
- }
- font_format = FORMAT_CID_KEYED;
- if (operands.size() != 3) {
- return OTS_FAILURE();
- }
- // check SIDs
- operands.pop_back(); // ignore the first number.
- if (!CheckSid(operands.back(), sid_max)) {
- return OTS_FAILURE();
- }
- operands.pop_back();
- if (!CheckSid(operands.back(), sid_max)) {
- return OTS_FAILURE();
- }
- if (have_ros) {
- return OTS_FAILURE(); // multiple ROS tables?
- }
- have_ros = true;
- break;
-
- default:
+ if (op == 24) { // vstore
+ if (type != DICT_DATA_TOPLEVEL) {
return OTS_FAILURE();
+ }
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if (!CheckOffset(operands.back(), table.length())) {
+ return OTS_FAILURE();
+ }
+ // parse "VariationStore Data Contents"
+ table.set_offset(operands.back().first);
+ if (!ParseVariationStore(*out_cff, table)) {
+ return OTS_FAILURE();
+ }
+ break;
}
operands.clear();
+ }
+ operands.clear();
+ dict.set_offset(dict_offset);
+ }
- if (font_format == FORMAT_UNKNOWN) {
- font_format = FORMAT_OTHER;
- }
+ while (dict.offset() < dict.length()) {
+ if (!ParseDictDataReadOperands(dict, operands, cff2)) {
+ return OTS_FAILURE();
+ }
+ if (operands.back().second != DICT_OPERATOR) continue;
+
+ // got operator
+ const uint32_t op = operands.back().first;
+ operands.pop_back();
+
+ if (cff2 && !ValidCFF2DictOp(op, type)) {
+ return OTS_FAILURE();
}
- // parse "13. Charsets"
- if (charset_offset) {
- ots::Buffer cff_table(data, table_length);
- cff_table.set_offset(charset_offset);
- uint8_t format = 0;
- if (!cff_table.ReadU8(&format)) {
- return OTS_FAILURE();
- }
- switch (format) {
- case 0:
- for (uint16_t j = 1 /* .notdef is omitted */; j < glyphs; ++j) {
- uint16_t sid = 0;
- if (!cff_table.ReadU16(&sid)) {
- return OTS_FAILURE();
- }
- if (!have_ros && (sid > sid_max)) {
- return OTS_FAILURE();
- }
- // TODO(yusukes): check CIDs when have_ros is true.
- }
- break;
+ switch (op) {
+ // SID
+ case 0: // version
+ case 1: // Notice
+ case 2: // Copyright
+ case 3: // FullName
+ case 4: // FamilyName
+ case (12U << 8) + 0: // Copyright
+ case (12U << 8) + 21: // PostScript
+ case (12U << 8) + 22: // BaseFontName
+ case (12U << 8) + 38: // FontName
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if (!CheckSid(operands.back(), sid_max)) {
+ return OTS_FAILURE();
+ }
+ break;
- case 1:
- case 2: {
- uint32_t total = 1; // .notdef is omitted.
- while (total < glyphs) {
- uint16_t sid = 0;
- if (!cff_table.ReadU16(&sid)) {
- return OTS_FAILURE();
- }
- if (!have_ros && (sid > sid_max)) {
- return OTS_FAILURE();
- }
- // TODO(yusukes): check CIDs when have_ros is true.
+ // array
+ case 5: // FontBBox
+ case 14: // XUID
+ case (12U << 8) + 7: // FontMatrix
+ case (12U << 8) + 23: // BaseFontBlend (delta)
+ if (operands.empty()) {
+ return OTS_FAILURE();
+ }
+ break;
- if (format == 1) {
- uint8_t left = 0;
- if (!cff_table.ReadU8(&left)) {
- return OTS_FAILURE();
- }
- total += (left + 1);
- } else {
- uint16_t left = 0;
- if (!cff_table.ReadU16(&left)) {
- return OTS_FAILURE();
- }
- total += (left + 1);
- }
- }
+ // number
+ case 13: // UniqueID
+ case (12U << 8) + 2: // ItalicAngle
+ case (12U << 8) + 3: // UnderlinePosition
+ case (12U << 8) + 4: // UnderlineThickness
+ case (12U << 8) + 5: // PaintType
+ case (12U << 8) + 8: // StrokeWidth
+ case (12U << 8) + 20: // SyntheticBase
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ break;
+ case (12U << 8) + 31: // CIDFontVersion
+ case (12U << 8) + 32: // CIDFontRevision
+ case (12U << 8) + 33: // CIDFontType
+ case (12U << 8) + 34: // CIDCount
+ case (12U << 8) + 35: // UIDBase
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if (font_format != FORMAT_CID_KEYED) {
+ return OTS_FAILURE();
+ }
+ break;
+ case (12U << 8) + 6: // CharstringType
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if(operands.back().second != DICT_OPERAND_INTEGER) {
+ return OTS_FAILURE();
+ }
+ if (operands.back().first != 2) {
+ // We only support the "Type 2 Charstring Format."
+ // TODO(yusukes): Support Type 1 format? Is that still in use?
+ return OTS_FAILURE();
+ }
+ break;
+
+ // boolean
+ case (12U << 8) + 1: // isFixedPitch
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if (operands.back().second != DICT_OPERAND_INTEGER) {
+ return OTS_FAILURE();
+ }
+ if (operands.back().first >= 2) {
+ return OTS_FAILURE();
+ }
+ break;
+
+ // offset(0)
+ case 15: // charset
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if (operands.back().first <= 2) {
+ // predefined charset, ISOAdobe, Expert or ExpertSubset, is used.
break;
}
-
- default:
+ if (!CheckOffset(operands.back(), table.length())) {
return OTS_FAILURE();
+ }
+ if (charset_offset) {
+ return OTS_FAILURE(); // multiple charset tables?
+ }
+ charset_offset = operands.back().first;
+ break;
+
+ case 16: { // Encoding
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if (operands.back().first <= 1) {
+ break; // predefined encoding, "Standard" or "Expert", is used.
+ }
+ if (!CheckOffset(operands.back(), table.length())) {
+ return OTS_FAILURE();
+ }
+
+ table.set_offset(operands.back().first);
+ uint8_t format = 0;
+ if (!table.ReadU8(&format)) {
+ return OTS_FAILURE();
+ }
+ if (format & 0x80) {
+ // supplemental encoding is not supported at the moment.
+ return OTS_FAILURE();
+ }
+ // TODO(yusukes): support & parse supplemental encoding tables.
+ break;
}
+
+ case 17: { // CharStrings
+ if (type != DICT_DATA_TOPLEVEL) {
+ return OTS_FAILURE();
+ }
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if (!CheckOffset(operands.back(), table.length())) {
+ return OTS_FAILURE();
+ }
+ // parse "14. CharStrings INDEX"
+ table.set_offset(operands.back().first);
+ ots::CFFIndex *charstring_index = out_cff->charstrings_index;
+ if (!ParseIndex(table, *charstring_index, cff2)) {
+ return OTS_FAILURE();
+ }
+ if (charstring_index->count < 2) {
+ return OTS_FAILURE();
+ }
+ if (have_charstrings) {
+ return OTS_FAILURE(); // multiple charstring tables?
+ }
+ have_charstrings = true;
+ if (charstring_index->count != glyphs) {
+ return OTS_FAILURE(); // CFF and maxp have different number of glyphs?
+ }
+ break;
+ }
+
+ case 24: { // vstore
+ if (!cff2) {
+ return OTS_FAILURE();
+ }
+ if (have_vstore) {
+ return OTS_FAILURE(); // multiple vstore tables?
+ }
+ have_vstore = true;
+ // parsed above.
+ break;
+ }
+
+ case (12U << 8) + 36: { // FDArray
+ if (type != DICT_DATA_TOPLEVEL) {
+ return OTS_FAILURE();
+ }
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if (!CheckOffset(operands.back(), table.length())) {
+ return OTS_FAILURE();
+ }
+
+ // parse Font DICT INDEX.
+ table.set_offset(operands.back().first);
+ ots::CFFIndex sub_dict_index;
+ if (!ParseIndex(table, sub_dict_index, cff2)) {
+ return OTS_FAILURE();
+ }
+ if (!ParseDictData(table, sub_dict_index,
+ glyphs, sid_max, DICT_DATA_FDARRAY,
+ out_cff)) {
+ return OTS_FAILURE();
+ }
+ if (out_cff->font_dict_length != 0) {
+ return OTS_FAILURE(); // two or more FDArray found.
+ }
+ out_cff->font_dict_length = sub_dict_index.count;
+ break;
+ }
+
+ case (12U << 8) + 37: { // FDSelect
+ if (type != DICT_DATA_TOPLEVEL) {
+ return OTS_FAILURE();
+ }
+ if (operands.size() != 1) {
+ return OTS_FAILURE();
+ }
+ if (!CheckOffset(operands.back(), table.length())) {
+ return OTS_FAILURE();
+ }
+
+ // parse FDSelect data structure
+ table.set_offset(operands.back().first);
+ uint8_t format = 0;
+ if (!table.ReadU8(&format)) {
+ return OTS_FAILURE();
+ }
+ if (format == 0) {
+ for (uint16_t j = 0; j < glyphs; ++j) {
+ uint8_t fd_index = 0;
+ if (!table.ReadU8(&fd_index)) {
+ return OTS_FAILURE();
+ }
+ (out_cff->fd_select)[j] = fd_index;
+ }
+ } else if (format == 3) {
+ uint16_t n_ranges = 0;
+ if (!table.ReadU16(&n_ranges)) {
+ return OTS_FAILURE();
+ }
+ if (n_ranges == 0) {
+ return OTS_FAILURE();
+ }
+
+ uint16_t last_gid = 0;
+ uint8_t fd_index = 0;
+ for (unsigned j = 0; j < n_ranges; ++j) {
+ uint16_t first = 0; // GID
+ if (!table.ReadU16(&first)) {
+ return OTS_FAILURE();
+ }
+
+ // Sanity checks.
+ if ((j == 0) && (first != 0)) {
+ return OTS_FAILURE();
+ }
+ if ((j != 0) && (last_gid >= first)) {
+ return OTS_FAILURE(); // not increasing order.
+ }
+ if (first >= glyphs) {
+ return OTS_FAILURE(); // invalid gid.
+ }
+
+ // Copy the mapping to |out_cff->fd_select|.
+ if (j != 0) {
+ for (auto k = last_gid; k < first; ++k) {
+ if (!out_cff->fd_select.insert(
+ std::make_pair(k, fd_index)).second) {
+ return OTS_FAILURE();
+ }
+ }
+ }
+
+ if (!table.ReadU8(&fd_index)) {
+ return OTS_FAILURE();
+ }
+ last_gid = first;
+ }
+ uint16_t sentinel = 0;
+ if (!table.ReadU16(&sentinel)) {
+ return OTS_FAILURE();
+ }
+ if (last_gid >= sentinel) {
+ return OTS_FAILURE();
+ }
+ if (sentinel > glyphs) {
+ return OTS_FAILURE(); // invalid gid.
+ }
+ for (auto k = last_gid; k < sentinel; ++k) {
+ if (!out_cff->fd_select.insert(
+ std::make_pair(k, fd_index)).second) {
+ return OTS_FAILURE();
+ }
+ }
+ } else if (cff2 && format == 4) {
+ uint32_t n_ranges = 0;
+ if (!table.ReadU32(&n_ranges)) {
+ return OTS_FAILURE();
+ }
+ if (n_ranges == 0) {
+ return OTS_FAILURE();
+ }
+
+ uint32_t last_gid = 0;
+ uint16_t fd_index = 0;
+ for (unsigned j = 0; j < n_ranges; ++j) {
+ uint32_t first = 0; // GID
+ if (!table.ReadU32(&first)) {
+ return OTS_FAILURE();
+ }
+
+ // Sanity checks.
+ if ((j == 0) && (first != 0)) {
+ return OTS_FAILURE();
+ }
+ if ((j != 0) && (last_gid >= first)) {
+ return OTS_FAILURE(); // not increasing order.
+ }
+ if (first >= glyphs) {
+ return OTS_FAILURE(); // invalid gid.
+ }
+
+ // Copy the mapping to |out_cff->fd_select|.
+ if (j != 0) {
+ for (auto k = last_gid; k < first; ++k) {
+ if (!out_cff->fd_select.insert(
+ std::make_pair(k, fd_index)).second) {
+ return OTS_FAILURE();
+ }
+ }
+ }
+
+ if (!table.ReadU16(&fd_index)) {
+ return OTS_FAILURE();
+ }
+ last_gid = first;
+ }
+ uint32_t sentinel = 0;
+ if (!table.ReadU32(&sentinel)) {
+ return OTS_FAILURE();
+ }
+ if (last_gid >= sentinel) {
+ return OTS_FAILURE();
+ }
+ if (sentinel > glyphs) {
+ return OTS_FAILURE(); // invalid gid.
+ }
+ for (auto k = last_gid; k < sentinel; ++k) {
+ if (!out_cff->fd_select.insert(
+ std::make_pair(k, fd_index)).second) {
+ return OTS_FAILURE();
+ }
+ }
+ } else {
+ // unknown format
+ return OTS_FAILURE();
+ }
+ break;
+ }
+
+ // Private DICT (2 * number)
+ case 18: {
+ if (operands.size() != 2) {
+ return OTS_FAILURE();
+ }
+ if (operands.back().second != DICT_OPERAND_INTEGER) {
+ return OTS_FAILURE();
+ }
+ const uint32_t private_offset = operands.back().first;
+ operands.pop_back();
+ if (operands.back().second != DICT_OPERAND_INTEGER) {
+ return OTS_FAILURE();
+ }
+ const uint32_t private_length = operands.back().first;
+ if (private_offset > table.length()) {
+ return OTS_FAILURE();
+ }
+ if (private_length >= table.length()) {
+ return OTS_FAILURE();
+ }
+ if (private_length + private_offset > table.length()) {
+ return OTS_FAILURE();
+ }
+ // parse "15. Private DICT data"
+ if (!ParsePrivateDictData(table, private_offset, private_length,
+ type, out_cff)) {
+ return OTS_FAILURE();
+ }
+ break;
+ }
+
+ // ROS
+ case (12U << 8) + 30:
+ if (font_format != FORMAT_UNKNOWN) {
+ return OTS_FAILURE();
+ }
+ font_format = FORMAT_CID_KEYED;
+ if (operands.size() != 3) {
+ return OTS_FAILURE();
+ }
+ // check SIDs
+ operands.pop_back(); // ignore the first number.
+ if (!CheckSid(operands.back(), sid_max)) {
+ return OTS_FAILURE();
+ }
+ operands.pop_back();
+ if (!CheckSid(operands.back(), sid_max)) {
+ return OTS_FAILURE();
+ }
+ if (have_ros) {
+ return OTS_FAILURE(); // multiple ROS tables?
+ }
+ have_ros = true;
+ break;
+
+ default:
+ return OTS_FAILURE();
+ }
+ operands.clear();
+
+ if (font_format == FORMAT_UNKNOWN) {
+ font_format = FORMAT_OTHER;
+ }
+ }
+
+ // parse "13. Charsets"
+ if (charset_offset) {
+ table.set_offset(charset_offset);
+ uint8_t format = 0;
+ if (!table.ReadU8(&format)) {
+ return OTS_FAILURE();
+ }
+ switch (format) {
+ case 0:
+ for (uint16_t j = 1 /* .notdef is omitted */; j < glyphs; ++j) {
+ uint16_t sid = 0;
+ if (!table.ReadU16(&sid)) {
+ return OTS_FAILURE();
+ }
+ if (!have_ros && (sid > sid_max)) {
+ return OTS_FAILURE();
+ }
+ // TODO(yusukes): check CIDs when have_ros is true.
+ }
+ break;
+
+ case 1:
+ case 2: {
+ uint32_t total = 1; // .notdef is omitted.
+ while (total < glyphs) {
+ uint16_t sid = 0;
+ if (!table.ReadU16(&sid)) {
+ return OTS_FAILURE();
+ }
+ if (!have_ros && (sid > sid_max)) {
+ return OTS_FAILURE();
+ }
+ // TODO(yusukes): check CIDs when have_ros is true.
+
+ if (format == 1) {
+ uint8_t left = 0;
+ if (!table.ReadU8(&left)) {
+ return OTS_FAILURE();
+ }
+ total += (left + 1);
+ } else {
+ uint16_t left = 0;
+ if (!table.ReadU16(&left)) {
+ return OTS_FAILURE();
+ }
+ total += (left + 1);
+ }
+ }
+ break;
+ }
+
+ default:
+ return OTS_FAILURE();
}
}
return true;
@@ -904,6 +1146,20 @@ bool ParseDictData(const uint8_t *data, size_t table_length,
namespace ots {
+bool OpenTypeCFF::ValidateFDSelect(uint16_t num_glyphs) {
+ for (const auto& fd_select : this->fd_select) {
+ if (fd_select.first >= num_glyphs) {
+ return Error("Invalid glyph index in FDSelect: %d >= %d\n",
+ fd_select.first, num_glyphs);
+ }
+ if (fd_select.second >= this->font_dict_length) {
+ return Error("Invalid FD index: %d >= %d\n",
+ fd_select.second, this->font_dict_length);
+ }
+ }
+ return true;
+}
+
bool OpenTypeCFF::Parse(const uint8_t *data, size_t length) {
Buffer table(data, length);
@@ -917,63 +1173,64 @@ bool OpenTypeCFF::Parse(const uint8_t *data, size_t length) {
uint8_t minor = 0;
uint8_t hdr_size = 0;
uint8_t off_size = 0;
- if (!table.ReadU8(&major)) {
- return OTS_FAILURE();
- }
- if (!table.ReadU8(&minor)) {
- return OTS_FAILURE();
- }
- if (!table.ReadU8(&hdr_size)) {
- return OTS_FAILURE();
- }
- if (!table.ReadU8(&off_size)) {
- return OTS_FAILURE();
- }
- if ((off_size == 0) || (off_size > 4)) {
- return OTS_FAILURE();
+ if (!table.ReadU8(&major) ||
+ !table.ReadU8(&minor) ||
+ !table.ReadU8(&hdr_size) ||
+ !table.ReadU8(&off_size)) {
+ return Error("Failed to read table header");
}
- if ((major != 1) ||
- (minor != 0) ||
- (hdr_size != 4)) {
- return OTS_FAILURE();
+ if (off_size < 1 || off_size > 4) {
+ return Error("Bad offSize: %d", off_size);
}
- if (hdr_size >= length) {
- return OTS_FAILURE();
+
+ if (major != 1 || minor != 0) {
+ return Error("Unsupported table version: %d.%d", major, minor);
+ }
+
+ this->major = major;
+
+ if (hdr_size != 4 || hdr_size >= length) {
+ return Error("Bad hdrSize: %d", hdr_size);
}
// parse "7. Name INDEX"
table.set_offset(hdr_size);
CFFIndex name_index;
- if (!ParseIndex(&table, &name_index)) {
- return OTS_FAILURE();
+ if (!ParseIndex(table, name_index)) {
+ return Error("Failed to parse Name INDEX");
+ }
+ if (name_index.count != 1 || name_index.offsets.size() != 2) {
+ return Error("Name INDEX must contain only one entry, not %d",
+ name_index.count);
}
if (!ParseNameData(&table, name_index, &(this->name))) {
- return OTS_FAILURE();
+ return Error("Failed to parse Name INDEX data");
}
// parse "8. Top DICT INDEX"
table.set_offset(name_index.offset_to_next);
CFFIndex top_dict_index;
- if (!ParseIndex(&table, &top_dict_index)) {
- return OTS_FAILURE();
+ if (!ParseIndex(table, top_dict_index)) {
+ return Error("Failed to parse Top DICT INDEX");
}
- if (name_index.count != top_dict_index.count) {
- return OTS_FAILURE();
+ if (top_dict_index.count != 1) {
+ return Error("Top DICT INDEX must contain only one entry, not %d",
+ top_dict_index.count);
}
// parse "10. String INDEX"
table.set_offset(top_dict_index.offset_to_next);
CFFIndex string_index;
- if (!ParseIndex(&table, &string_index)) {
- return OTS_FAILURE();
+ if (!ParseIndex(table, string_index)) {
+ return Error("Failed to parse String INDEX");
}
if (string_index.count >= 65000 - kNStdString) {
- return OTS_FAILURE();
+ return Error("Too many entries in String INDEX: %d", string_index.count);
}
OpenTypeMAXP *maxp = static_cast(
- GetFont()->GetTypedTable(OTS_TAG_MAXP));
+ font->GetTypedTable(OTS_TAG_MAXP));
if (!maxp) {
return Error("Required maxp table missing");
}
@@ -982,39 +1239,28 @@ bool OpenTypeCFF::Parse(const uint8_t *data, size_t length) {
// string_index.count == 0 is allowed.
// parse "9. Top DICT Data"
- if (!ParseDictData(data, length, top_dict_index,
+ this->charstrings_index = new ots::CFFIndex;
+ if (!ParseDictData(table, top_dict_index,
num_glyphs, sid_max,
DICT_DATA_TOPLEVEL, this)) {
- return OTS_FAILURE();
+ return Error("Failed to parse Top DICT Data");
}
// parse "16. Global Subrs INDEX"
table.set_offset(string_index.offset_to_next);
CFFIndex global_subrs_index;
- if (!ParseIndex(&table, &global_subrs_index)) {
- return OTS_FAILURE();
+ if (!ParseIndex(table, global_subrs_index)) {
+ return Error("Failed to parse Global Subrs INDEX");
}
- // Check if all fd_index in FDSelect are valid.
- std::map::const_iterator iter;
- std::map::const_iterator end = this->fd_select.end();
- for (iter = this->fd_select.begin(); iter != end; ++iter) {
- if (iter->second >= this->font_dict_length) {
- return OTS_FAILURE();
- }
+ // Check if all fd and glyph indices in FDSelect are valid.
+ if (!ValidateFDSelect(num_glyphs)) {
+ return Error("Failed to validate FDSelect");
}
// Check if all charstrings (font hinting code for each glyph) are valid.
- for (size_t i = 0; i < this->char_strings_array.size(); ++i) {
- if (!ValidateType2CharStringIndex(font,
- *(this->char_strings_array.at(i)),
- global_subrs_index,
- this->fd_select,
- this->local_subrs_per_font,
- this->local_subrs,
- &table)) {
- return Error("Failed validating charstring set %d", (int) i);
- }
+ if (!ValidateCFFCharStrings(*this, global_subrs_index, &table)) {
+ return Error("Failed validating CharStrings INDEX");
}
return true;
@@ -1028,15 +1274,92 @@ bool OpenTypeCFF::Serialize(OTSStream *out) {
}
OpenTypeCFF::~OpenTypeCFF() {
- for (size_t i = 0; i < this->char_strings_array.size(); ++i) {
- delete (this->char_strings_array)[i];
- }
for (size_t i = 0; i < this->local_subrs_per_font.size(); ++i) {
delete (this->local_subrs_per_font)[i];
}
+ delete this->charstrings_index;
delete this->local_subrs;
}
+bool OpenTypeCFF2::Parse(const uint8_t *data, size_t length) {
+ Buffer table(data, length);
+
+ Font *font = GetFont();
+
+ this->m_data = data;
+ this->m_length = length;
+
+ // parse "6. Header"
+ uint8_t major = 0;
+ uint8_t minor = 0;
+ uint8_t hdr_size = 0;
+ uint16_t top_dict_size = 0;
+ if (!table.ReadU8(&major) ||
+ !table.ReadU8(&minor) ||
+ !table.ReadU8(&hdr_size) ||
+ !table.ReadU16(&top_dict_size)) {
+ return Error("Failed to read table header");
+ }
+
+ if (major != 2 || minor != 0) {
+ return Error("Unsupported table version: %d.%d", major, minor);
+ }
+
+ this->major = major;
+
+ if (hdr_size >= length) {
+ return Error("Bad hdrSize: %d", hdr_size);
+ }
+
+ if (top_dict_size == 0 || hdr_size + top_dict_size > length) {
+ return Error("Bad topDictLength: %d", top_dict_size);
+ }
+
+ OpenTypeMAXP *maxp = static_cast(
+ font->GetTypedTable(OTS_TAG_MAXP));
+ if (!maxp) {
+ return Error("Required maxp table missing");
+ }
+ const uint16_t num_glyphs = maxp->num_glyphs;
+ const size_t sid_max = kNStdString;
+
+ // parse "7. Top DICT Data"
+ ots::Buffer top_dict(data + hdr_size, top_dict_size);
+ table.set_offset(hdr_size);
+ this->charstrings_index = new ots::CFFIndex;
+ if (!ParseDictData(table, top_dict,
+ num_glyphs, sid_max,
+ DICT_DATA_TOPLEVEL, this)) {
+ return Error("Failed to parse Top DICT Data");
+ }
+
+ // parse "9. Global Subrs INDEX"
+ table.set_offset(hdr_size + top_dict_size);
+ CFFIndex global_subrs_index;
+ if (!ParseIndex(table, global_subrs_index, true)) {
+ return Error("Failed to parse Global Subrs INDEX");
+ }
+
+ // Check if all fd and glyph indices in FDSelect are valid.
+ if (!ValidateFDSelect(num_glyphs)) {
+ return Error("Failed to validate FDSelect");
+ }
+
+ // Check if all charstrings (font hinting code for each glyph) are valid.
+ if (!ValidateCFFCharStrings(*this, global_subrs_index, &table)) {
+ return Error("Failed validating CharStrings INDEX");
+ }
+
+ return true;
+}
+
+bool OpenTypeCFF2::Serialize(OTSStream *out) {
+ if (!out->Write(this->m_data, this->m_length)) {
+ return Error("Failed to write table");
+ }
+ return true;
+}
+
} // namespace ots
#undef TABLE_NAME
diff --git a/gfx/ots/src/cff.h b/gfx/ots/src/cff.h
index 4d8134029c..cfce9ab914 100644
--- a/gfx/ots/src/cff.h
+++ b/gfx/ots/src/cff.h
@@ -11,22 +11,28 @@
#include
#include
+#undef major // glibc defines major!
+
namespace ots {
struct CFFIndex {
CFFIndex()
: count(0), off_size(0), offset_to_next(0) {}
- uint16_t count;
+ uint32_t count;
uint8_t off_size;
std::vector offsets;
uint32_t offset_to_next;
};
+typedef std::map CFFFDSelect;
+
class OpenTypeCFF : public Table {
public:
explicit OpenTypeCFF(Font *font, uint32_t tag)
: Table(font, tag, tag),
+ major(0),
font_dict_length(0),
+ charstrings_index(NULL),
local_subrs(NULL),
m_data(NULL),
m_length(0) {
@@ -37,21 +43,46 @@ class OpenTypeCFF : public Table {
bool Parse(const uint8_t *data, size_t length);
bool Serialize(OTSStream *out);
+ // Major version number.
+ uint8_t major;
+
// Name INDEX. This name is used in name.cc as a postscript font name.
std::string name;
// The number of fonts the file has.
size_t font_dict_length;
// A map from glyph # to font #.
- std::map fd_select;
+ CFFFDSelect fd_select;
// A list of char strings.
- std::vector char_strings_array;
+ CFFIndex* charstrings_index;
// A list of Local Subrs associated with FDArrays. Can be empty.
std::vector local_subrs_per_font;
// A Local Subrs associated with Top DICT. Can be NULL.
CFFIndex *local_subrs;
+ // CFF2 VariationStore regionIndexCount.
+ std::vector region_index_count;
+
+ protected:
+ bool ValidateFDSelect(uint16_t num_glyphs);
+
+ private:
+ const uint8_t *m_data;
+ size_t m_length;
+};
+
+class OpenTypeCFF2 : public OpenTypeCFF {
+ public:
+ explicit OpenTypeCFF2(Font *font, uint32_t tag)
+ : OpenTypeCFF(font, tag),
+ m_data(NULL),
+ m_length(0) {
+ }
+
+ bool Parse(const uint8_t *data, size_t length);
+ bool Serialize(OTSStream *out);
+
private:
const uint8_t *m_data;
size_t m_length;
diff --git a/gfx/ots/src/cff_type2_charstring.cc b/gfx/ots/src/cff_charstring.cc
similarity index 71%
rename from gfx/ots/src/cff_type2_charstring.cc
rename to gfx/ots/src/cff_charstring.cc
index 3b134d155f..23c17d183d 100644
--- a/gfx/ots/src/cff_type2_charstring.cc
+++ b/gfx/ots/src/cff_charstring.cc
@@ -5,7 +5,7 @@
// A parser for the Type 2 Charstring Format.
// http://www.adobe.com/devnet/font/pdfs/5177.Type2.pdf
-#include "cff_type2_charstring.h"
+#include "cff_charstring.h"
#include
#include
@@ -22,7 +22,6 @@ namespace {
// Note #5177.
const int32_t kMaxSubrsCount = 65536;
const size_t kMaxCharStringLength = 65535;
-const size_t kMaxArgumentStack = 48;
const size_t kMaxNumberOfStemHints = 96;
const size_t kMaxSubrNesting = 10;
@@ -30,117 +29,130 @@ const size_t kMaxSubrNesting = 10;
// will fail with the dummy value.
const int32_t dummy_result = INT_MAX;
-bool ExecuteType2CharString(ots::Font *font,
- size_t call_depth,
- const ots::CFFIndex& global_subrs_index,
- const ots::CFFIndex& local_subrs_index,
- ots::Buffer *cff_table,
- ots::Buffer *char_string,
- std::stack *argument_stack,
- bool *out_found_endchar,
- bool *out_found_width,
- size_t *in_out_num_stems);
+bool ExecuteCharString(ots::OpenTypeCFF& cff,
+ size_t call_depth,
+ const ots::CFFIndex& global_subrs_index,
+ const ots::CFFIndex& local_subrs_index,
+ ots::Buffer *cff_table,
+ ots::Buffer *char_string,
+ std::stack *argument_stack,
+ bool *out_found_endchar,
+ bool *out_found_width,
+ size_t *in_out_num_stems,
+ bool cff2);
+
+bool ArgumentStackOverflows(std::stack *argument_stack, bool cff2) {
+ if ((cff2 && argument_stack->size() > ots::kMaxCFF2ArgumentStack) ||
+ (!cff2 && argument_stack->size() > ots::kMaxCFF1ArgumentStack)) {
+ return true;
+ }
+ return false;
+}
#ifdef DUMP_T2CHARSTRING
// Converts |op| to a string and returns it.
-const char *Type2CharStringOperatorToString(ots::Type2CharStringOperator op) {
+const char *CharStringOperatorToString(ots::CharStringOperator op) {
switch (op) {
case ots::kHStem:
- return "HStem";
+ return "hstem";
case ots::kVStem:
- return "VStem";
+ return "vstem";
case ots::kVMoveTo:
- return "VMoveTo";
+ return "vmoveto";
case ots::kRLineTo:
- return "RLineTo";
+ return "rlineto";
case ots::kHLineTo:
- return "HLineTo";
+ return "hlineto";
case ots::kVLineTo:
- return "VLineTo";
+ return "vlineto";
case ots::kRRCurveTo:
- return "RRCurveTo";
+ return "rrcurveto";
case ots::kCallSubr:
- return "CallSubr";
+ return "callsubr";
case ots::kReturn:
- return "Return";
+ return "return";
case ots::kEndChar:
- return "EndChar";
+ return "endchar";
+ case ots::kVSIndex:
+ return "vsindex";
+ case ots::kBlend:
+ return "blend";
case ots::kHStemHm:
- return "HStemHm";
+ return "hstemhm";
case ots::kHintMask:
- return "HintMask";
+ return "hintmask";
case ots::kCntrMask:
- return "CntrMask";
+ return "cntrmask";
case ots::kRMoveTo:
- return "RMoveTo";
+ return "rmoveto";
case ots::kHMoveTo:
- return "HMoveTo";
+ return "hmoveto";
case ots::kVStemHm:
- return "VStemHm";
+ return "vstemhm";
case ots::kRCurveLine:
- return "RCurveLine";
+ return "rcurveline";
case ots::kRLineCurve:
- return "RLineCurve";
+ return "rlinecurve";
case ots::kVVCurveTo:
return "VVCurveTo";
case ots::kHHCurveTo:
- return "HHCurveTo";
+ return "hhcurveto";
case ots::kCallGSubr:
- return "CallGSubr";
+ return "callgsubr";
case ots::kVHCurveTo:
- return "VHCurveTo";
+ return "vhcurveto";
case ots::kHVCurveTo:
return "HVCurveTo";
case ots::kDotSection:
- return "DotSection";
+ return "dotsection";
case ots::kAnd:
- return "And";
+ return "and";
case ots::kOr:
- return "Or";
+ return "or";
case ots::kNot:
- return "Not";
+ return "not";
case ots::kAbs:
- return "Abs";
+ return "abs";
case ots::kAdd:
- return "Add";
+ return "add";
case ots::kSub:
- return "Sub";
+ return "sub";
case ots::kDiv:
- return "Div";
+ return "div";
case ots::kNeg:
- return "Neg";
+ return "neg";
case ots::kEq:
- return "Eq";
+ return "eq";
case ots::kDrop:
- return "Drop";
+ return "drop";
case ots::kPut:
- return "Put";
+ return "put";
case ots::kGet:
- return "Get";
+ return "get";
case ots::kIfElse:
- return "IfElse";
+ return "ifelse";
case ots::kRandom:
- return "Random";
+ return "random";
case ots::kMul:
- return "Mul";
+ return "mul";
case ots::kSqrt:
- return "Sqrt";
+ return "sqrt";
case ots::kDup:
- return "Dup";
+ return "dup";
case ots::kExch:
- return "Exch";
+ return "exch";
case ots::kIndex:
- return "Index";
+ return "index";
case ots::kRoll:
- return "Roll";
+ return "roll";
case ots::kHFlex:
- return "HFlex";
+ return "hflex";
case ots::kFlex:
- return "Flex";
+ return "flex";
case ots::kHFlex1:
- return "HFlex1";
+ return "hflex1";
case ots::kFlex1:
- return "Flex1";
+ return "flex1";
}
return "UNKNOWN";
@@ -150,9 +162,9 @@ const char *Type2CharStringOperatorToString(ots::Type2CharStringOperator op) {
// Read one or more bytes from the |char_string| buffer and stores the number
// read on |out_number|. If the number read is an operator (ex 'vstem'), sets
// true on |out_is_operator|. Returns true if the function read a number.
-bool ReadNextNumberFromType2CharString(ots::Buffer *char_string,
- int32_t *out_number,
- bool *out_is_operator) {
+bool ReadNextNumberFromCharString(ots::Buffer *char_string,
+ int32_t *out_number,
+ bool *out_is_operator) {
uint8_t v = 0;
if (!char_string->ReadU8(&v)) {
return OTS_FAILURE();
@@ -174,7 +186,7 @@ bool ReadNextNumberFromType2CharString(ots::Buffer *char_string,
*out_is_operator = true;
} else if (v <= 27) {
// Special handling for v==19 and v==20 are implemented in
- // ExecuteType2CharStringOperator().
+ // ExecuteCharStringOperator().
*out_number = v;
*out_is_operator = true;
} else if (v == 28) {
@@ -221,23 +233,63 @@ bool ReadNextNumberFromType2CharString(ots::Buffer *char_string,
return true;
}
+bool ValidCFF2Operator(int32_t op) {
+ switch (op) {
+ case ots::kReturn:
+ case ots::kEndChar:
+ case ots::kAbs:
+ case ots::kAdd:
+ case ots::kSub:
+ case ots::kDiv:
+ case ots::kNeg:
+ case ots::kRandom:
+ case ots::kMul:
+ case ots::kSqrt:
+ case ots::kDrop:
+ case ots::kExch:
+ case ots::kIndex:
+ case ots::kRoll:
+ case ots::kDup:
+ case ots::kPut:
+ case ots::kGet:
+ case ots::kDotSection:
+ case ots::kAnd:
+ case ots::kOr:
+ case ots::kNot:
+ case ots::kEq:
+ case ots::kIfElse:
+ return false;
+ }
+
+ return true;
+}
+
// Executes |op| and updates |argument_stack|. Returns true if the execution
// succeeds. If the |op| is kCallSubr or kCallGSubr, the function recursively
-// calls ExecuteType2CharString() function. The arguments other than |op| and
+// calls ExecuteCharString() function. The arguments other than |op| and
// |argument_stack| are passed for that reason.
-bool ExecuteType2CharStringOperator(ots::Font *font,
- int32_t op,
- size_t call_depth,
- const ots::CFFIndex& global_subrs_index,
- const ots::CFFIndex& local_subrs_index,
- ots::Buffer *cff_table,
- ots::Buffer *char_string,
- std::stack *argument_stack,
- bool *out_found_endchar,
- bool *in_out_found_width,
- size_t *in_out_num_stems) {
+bool ExecuteCharStringOperator(ots::OpenTypeCFF& cff,
+ int32_t op,
+ size_t call_depth,
+ const ots::CFFIndex& global_subrs_index,
+ const ots::CFFIndex& local_subrs_index,
+ ots::Buffer *cff_table,
+ ots::Buffer *char_string,
+ std::stack *argument_stack,
+ bool *out_found_endchar,
+ bool *in_out_found_width,
+ size_t *in_out_num_stems,
+ bool *in_out_have_blend,
+ bool *in_out_have_visindex,
+ int32_t *in_out_vsindex,
+ bool cff2) {
+ ots::Font* font = cff.GetFont();
const size_t stack_size = argument_stack->size();
+ if (cff2 && !ValidCFF2Operator(op)) {
+ return OTS_FAILURE();
+ }
+
switch (op) {
case ots::kCallSubr:
case ots::kCallGSubr: {
@@ -290,16 +342,17 @@ bool ExecuteType2CharStringOperator(ots::Font *font,
}
ots::Buffer char_string_to_jump(cff_table->buffer() + offset, length);
- return ExecuteType2CharString(font,
- call_depth + 1,
- global_subrs_index,
- local_subrs_index,
- cff_table,
- &char_string_to_jump,
- argument_stack,
- out_found_endchar,
- in_out_found_width,
- in_out_num_stems);
+ return ExecuteCharString(cff,
+ call_depth + 1,
+ global_subrs_index,
+ local_subrs_index,
+ cff_table,
+ &char_string_to_jump,
+ argument_stack,
+ out_found_endchar,
+ in_out_found_width,
+ in_out_num_stems,
+ cff2);
}
case ots::kReturn:
@@ -310,6 +363,51 @@ bool ExecuteType2CharStringOperator(ots::Font *font,
*in_out_found_width = true; // just in case.
return true;
+ case ots::kVSIndex: {
+ if (!cff2) {
+ return OTS_FAILURE();
+ }
+ if (stack_size != 1) {
+ return OTS_FAILURE();
+ }
+ if (*in_out_have_blend || *in_out_have_visindex) {
+ return OTS_FAILURE();
+ }
+ if (argument_stack->top() >= cff.region_index_count.size()) {
+ return OTS_FAILURE();
+ }
+ *in_out_have_visindex = true;
+ *in_out_vsindex = argument_stack->top();
+ while (!argument_stack->empty())
+ argument_stack->pop();
+ return true;
+ }
+
+ case ots::kBlend: {
+ if (!cff2) {
+ return OTS_FAILURE();
+ }
+ if (stack_size < 1) {
+ return OTS_FAILURE();
+ }
+ if (*in_out_vsindex >= cff.region_index_count.size()) {
+ return OTS_FAILURE();
+ }
+ uint16_t k = cff.region_index_count.at(*in_out_vsindex);
+ uint16_t n = argument_stack->top();
+ if (stack_size < n * (k + 1) + 1) {
+ return OTS_FAILURE();
+ }
+
+ // Keep the 1st n operands on the stack for the next operator to use and
+ // pop the rest. There can be multiple consecutive blend operator, so this
+ // makes sure the operands of all of them are kept on the stack.
+ while (argument_stack->size() > stack_size - ((n * k) + 1))
+ argument_stack->pop();
+ *in_out_have_blend = true;
+ return true;
+ }
+
case ots::kHStem:
case ots::kVStem:
case ots::kHStemHm:
@@ -649,7 +747,7 @@ bool ExecuteType2CharStringOperator(ots::Font *font,
argument_stack->pop();
argument_stack->push(dummy_result);
argument_stack->push(dummy_result);
- if (argument_stack->size() > kMaxArgumentStack) {
+ if (ArgumentStackOverflows(argument_stack, cff2)) {
return OTS_FAILURE();
}
// TODO(yusukes): Implement this. We should push a real value for all
@@ -729,26 +827,29 @@ bool ExecuteType2CharStringOperator(ots::Font *font,
// in_out_found_width: true is set if |char_string| contains 'width' byte (which
// is 0 or 1 byte.)
// in_out_num_stems: total number of hstems and vstems processed so far.
-bool ExecuteType2CharString(ots::Font *font,
- size_t call_depth,
- const ots::CFFIndex& global_subrs_index,
- const ots::CFFIndex& local_subrs_index,
- ots::Buffer *cff_table,
- ots::Buffer *char_string,
- std::stack *argument_stack,
- bool *out_found_endchar,
- bool *in_out_found_width,
- size_t *in_out_num_stems) {
+bool ExecuteCharString(ots::OpenTypeCFF& cff,
+ size_t call_depth,
+ const ots::CFFIndex& global_subrs_index,
+ const ots::CFFIndex& local_subrs_index,
+ ots::Buffer *cff_table,
+ ots::Buffer *char_string,
+ std::stack *argument_stack,
+ bool *out_found_endchar,
+ bool *in_out_found_width,
+ size_t *in_out_num_stems,
+ bool cff2) {
if (call_depth > kMaxSubrNesting) {
return OTS_FAILURE();
}
*out_found_endchar = false;
+ bool in_out_have_blend = false, in_out_have_visindex = false;
+ int32_t in_out_vsindex = 0;
const size_t length = char_string->length();
while (char_string->offset() < length) {
int32_t operator_or_operand = 0;
bool is_operator = false;
- if (!ReadNextNumberFromType2CharString(char_string,
+ if (!ReadNextNumberFromCharString(char_string,
&operator_or_operand,
&is_operator)) {
return OTS_FAILURE();
@@ -761,35 +862,39 @@ bool ExecuteType2CharString(ots::Font *font,
*/
if (!is_operator) {
- std::fprintf(stderr, "#%d# ", operator_or_operand);
+ std::fprintf(stderr, "%d ", operator_or_operand);
} else {
- std::fprintf(stderr, "#%s#\n",
- Type2CharStringOperatorToString(
- ots::Type2CharStringOperator(operator_or_operand))
+ std::fprintf(stderr, "%s\n",
+ CharStringOperatorToString(
+ ots::CharStringOperator(operator_or_operand))
);
}
#endif
if (!is_operator) {
argument_stack->push(operator_or_operand);
- if (argument_stack->size() > kMaxArgumentStack) {
+ if (ArgumentStackOverflows(argument_stack, cff2)) {
return OTS_FAILURE();
}
continue;
}
// An operator is found. Execute it.
- if (!ExecuteType2CharStringOperator(font,
- operator_or_operand,
- call_depth,
- global_subrs_index,
- local_subrs_index,
- cff_table,
- char_string,
- argument_stack,
- out_found_endchar,
- in_out_found_width,
- in_out_num_stems)) {
+ if (!ExecuteCharStringOperator(cff,
+ operator_or_operand,
+ call_depth,
+ global_subrs_index,
+ local_subrs_index,
+ cff_table,
+ char_string,
+ argument_stack,
+ out_found_endchar,
+ in_out_found_width,
+ in_out_num_stems,
+ &in_out_have_blend,
+ &in_out_have_visindex,
+ &in_out_vsindex,
+ cff2)) {
return OTS_FAILURE();
}
if (*out_found_endchar) {
@@ -801,37 +906,39 @@ bool ExecuteType2CharString(ots::Font *font,
}
// No endchar operator is found.
+ if (cff2)
+ return true;
return OTS_FAILURE();
}
// Selects a set of subroutings for |glyph_index| from |cff| and sets it on
// |out_local_subrs_to_use|. Returns true on success.
-bool SelectLocalSubr(const std::map &fd_select,
- const std::vector &local_subrs_per_font,
- const ots::CFFIndex *local_subrs,
+bool SelectLocalSubr(const ots::OpenTypeCFF& cff,
uint16_t glyph_index, // 0-origin
const ots::CFFIndex **out_local_subrs_to_use) {
+ bool cff2 = (cff.major == 2);
*out_local_subrs_to_use = NULL;
// First, find local subrs from |local_subrs_per_font|.
- if ((fd_select.size() > 0) &&
- (!local_subrs_per_font.empty())) {
+ if ((cff.fd_select.size() > 0) &&
+ (!cff.local_subrs_per_font.empty())) {
// Look up FDArray index for the glyph.
- std::map::const_iterator iter =
- fd_select.find(glyph_index);
- if (iter == fd_select.end()) {
+ const auto& iter = cff.fd_select.find(glyph_index);
+ if (iter == cff.fd_select.end()) {
return OTS_FAILURE();
}
- const uint8_t fd_index = iter->second;
- if (fd_index >= local_subrs_per_font.size()) {
+ const auto fd_index = iter->second;
+ if (fd_index >= cff.local_subrs_per_font.size()) {
return OTS_FAILURE();
}
- *out_local_subrs_to_use = local_subrs_per_font.at(fd_index);
- } else if (local_subrs) {
+ *out_local_subrs_to_use = cff.local_subrs_per_font.at(fd_index);
+ } else if (cff.local_subrs) {
// Second, try to use |local_subrs|. Most Latin fonts don't have FDSelect
// entries. If The font has a local subrs index associated with the Top
// DICT (not FDArrays), use it.
- *out_local_subrs_to_use = local_subrs;
+ *out_local_subrs_to_use = cff.local_subrs;
+ } else if (cff2 && cff.local_subrs_per_font.size() == 1) {
+ *out_local_subrs_to_use = cff.local_subrs_per_font.at(0);
} else {
// Just return NULL.
*out_local_subrs_to_use = NULL;
@@ -844,18 +951,16 @@ bool SelectLocalSubr(const std::map &fd_select,
namespace ots {
-bool ValidateType2CharStringIndex(
- ots::Font *font,
- const CFFIndex& char_strings_index,
+bool ValidateCFFCharStrings(
+ ots::OpenTypeCFF& cff,
const CFFIndex& global_subrs_index,
- const std::map &fd_select,
- const std::vector &local_subrs_per_font,
- const CFFIndex *local_subrs,
Buffer* cff_table) {
+ const CFFIndex& char_strings_index = *(cff.charstrings_index);
if (char_strings_index.offsets.size() == 0) {
return OTS_FAILURE(); // no charstring.
}
+ bool cff2 = (cff.major == 2);
// For each glyph, validate the corresponding charstring.
for (unsigned i = 1; i < char_strings_index.offsets.size(); ++i) {
// Prepare a Buffer object, |char_string|, which contains the charstring
@@ -875,9 +980,7 @@ bool ValidateType2CharStringIndex(
// Get a local subrs for the glyph.
const unsigned glyph_index = i - 1; // index in the map is 0-origin.
const CFFIndex *local_subrs_to_use = NULL;
- if (!SelectLocalSubr(fd_select,
- local_subrs_per_font,
- local_subrs,
+ if (!SelectLocalSubr(cff,
glyph_index,
&local_subrs_to_use)) {
return OTS_FAILURE();
@@ -891,16 +994,19 @@ bool ValidateType2CharStringIndex(
// Check a charstring for the |i|-th glyph.
std::stack argument_stack;
bool found_endchar = false;
- bool found_width = false;
+ // CFF2 CharString has no value for width, so we start with true here to
+ // error out if width is found.
+ bool found_width = cff2;
size_t num_stems = 0;
- if (!ExecuteType2CharString(font,
- 0 /* initial call_depth is zero */,
- global_subrs_index, *local_subrs_to_use,
- cff_table, &char_string, &argument_stack,
- &found_endchar, &found_width, &num_stems)) {
+ if (!ExecuteCharString(cff,
+ 0 /* initial call_depth is zero */,
+ global_subrs_index, *local_subrs_to_use,
+ cff_table, &char_string, &argument_stack,
+ &found_endchar, &found_width, &num_stems,
+ cff2)) {
return OTS_FAILURE();
}
- if (!found_endchar) {
+ if (!cff2 && !found_endchar) {
return OTS_FAILURE();
}
}
diff --git a/gfx/ots/src/cff_type2_charstring.h b/gfx/ots/src/cff_charstring.h
similarity index 91%
rename from gfx/ots/src/cff_type2_charstring.h
rename to gfx/ots/src/cff_charstring.h
index bf6dff194d..5a2fa9ff2c 100644
--- a/gfx/ots/src/cff_type2_charstring.h
+++ b/gfx/ots/src/cff_charstring.h
@@ -13,6 +13,9 @@
namespace ots {
+const size_t kMaxCFF1ArgumentStack = 48;
+const size_t kMaxCFF2ArgumentStack = 513;
+
// Validates all charstrings in |char_strings_index|. Charstring is a small
// language for font hinting defined in Adobe Technical Note #5177.
// http://www.adobe.com/devnet/font/pdfs/5177.Type2.pdf
@@ -34,17 +37,14 @@ namespace ots {
// local_subrs: A Local Subrs associated with Top DICT. Can be NULL.
// cff_table: A buffer which contains actual byte code of charstring, global
// subroutines and local subroutines.
-bool ValidateType2CharStringIndex(
- Font *font,
- const CFFIndex &char_strings_index,
+bool ValidateCFFCharStrings(
+ OpenTypeCFF& cff,
const CFFIndex &global_subrs_index,
- const std::map &fd_select,
- const std::vector &local_subrs_per_font,
- const CFFIndex *local_subrs,
Buffer *cff_table);
// The list of Operators. See Appendix. A in Adobe Technical Note #5177.
-enum Type2CharStringOperator {
+// and https://docs.microsoft.com/en-us/typography/opentype/spec/cff2charstr
+enum CharStringOperator {
kHStem = 1,
kVStem = 3,
kVMoveTo = 4,
@@ -55,6 +55,8 @@ enum Type2CharStringOperator {
kCallSubr = 10,
kReturn = 11,
kEndChar = 14,
+ kVSIndex = 15,
+ kBlend = 16,
kHStemHm = 18,
kHintMask = 19,
kCntrMask = 20,
diff --git a/gfx/ots/src/cmap.cc b/gfx/ots/src/cmap.cc
index 6fb0eab1ce..72c2a20fc4 100644
--- a/gfx/ots/src/cmap.cc
+++ b/gfx/ots/src/cmap.cc
@@ -238,7 +238,7 @@ bool OpenTypeCMAP::ParseFormat4(int platform, int encoding,
}
uint16_t glyph;
std::memcpy(&glyph, data + glyph_id_offset, 2);
- glyph = ntohs(glyph);
+ glyph = ots_ntohs(glyph);
if (glyph >= num_glyphs) {
return Error("Range glyph reference too high (%d > %d)", glyph, num_glyphs - 1);
}
@@ -771,9 +771,10 @@ bool OpenTypeCMAP::Parse(const uint8_t *data, size_t length) {
subtable_headers[i].length, num_glyphs)) {
return Error("Failed to parse format 4 cmap subtable %d", i);
}
- } else if ((subtable_headers[i].encoding == 3) &&
+ } else if ((subtable_headers[i].encoding == 3 ||
+ subtable_headers[i].encoding == 4) &&
(subtable_headers[i].format == 12)) {
- // parse and output the 0-3-12 table as 3-10-12 table.
+ // parse and output the 0-3-12 or 0-4-12 tables as 3-10-12 table.
if (!Parse31012(data + subtable_headers[i].offset,
subtable_headers[i].length, num_glyphs)) {
return Error("Failed to parse format 12 cmap subtable %d", i);
diff --git a/gfx/ots/src/cvar.cc b/gfx/ots/src/cvar.cc
new file mode 100644
index 0000000000..a2bad7a15e
--- /dev/null
+++ b/gfx/ots/src/cvar.cc
@@ -0,0 +1,56 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cvar.h"
+
+#include "fvar.h"
+#include "variations.h"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeCVAR
+// -----------------------------------------------------------------------------
+
+bool OpenTypeCVAR::Parse(const uint8_t* data, size_t length) {
+ Buffer table(data, length);
+
+ uint16_t majorVersion;
+ uint16_t minorVersion;
+
+ if (!table.ReadU16(&majorVersion) ||
+ !table.ReadU16(&minorVersion)) {
+ return Drop("Failed to read table header");
+ }
+
+ if (majorVersion != 1) {
+ return Drop("Unknown table version");
+ }
+
+ OpenTypeFVAR* fvar = static_cast(
+ GetFont()->GetTypedTable(OTS_TAG_FVAR));
+ if (!fvar) {
+ return DropVariations("Required fvar table is missing");
+ }
+
+ if (!ParseVariationData(GetFont(), data + table.offset(), length - table.offset(),
+ fvar->AxisCount(), 0)) {
+ return Drop("Failed to parse variation data");
+ }
+
+ this->m_data = data;
+ this->m_length = length;
+
+ return true;
+}
+
+bool OpenTypeCVAR::Serialize(OTSStream* out) {
+ if (!out->Write(this->m_data, this->m_length)) {
+ return Error("Failed to write cvar table");
+ }
+
+ return true;
+}
+
+} // namespace ots
diff --git a/gfx/ots/src/cvar.h b/gfx/ots/src/cvar.h
new file mode 100644
index 0000000000..8f31e98cd1
--- /dev/null
+++ b/gfx/ots/src/cvar.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef OTS_CVAR_H_
+#define OTS_CVAR_H_
+
+#include "ots.h"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeCVAR Interface
+// -----------------------------------------------------------------------------
+
+class OpenTypeCVAR : public Table {
+ public:
+ explicit OpenTypeCVAR(Font* font, uint32_t tag)
+ : Table(font, tag, tag) { }
+
+ bool Parse(const uint8_t* data, size_t length);
+ bool Serialize(OTSStream* out);
+
+ private:
+ const uint8_t *m_data;
+ size_t m_length;
+};
+
+} // namespace ots
+
+#endif // OTS_CVAR_H_
diff --git a/gfx/ots/src/fvar.cc b/gfx/ots/src/fvar.cc
new file mode 100644
index 0000000000..6f9b4d6ebf
--- /dev/null
+++ b/gfx/ots/src/fvar.cc
@@ -0,0 +1,164 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "fvar.h"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeFVAR
+// -----------------------------------------------------------------------------
+
+bool OpenTypeFVAR::Parse(const uint8_t* data, size_t length) {
+ Buffer table(data, length);
+ if (!table.ReadU16(&this->majorVersion) ||
+ !table.ReadU16(&this->minorVersion) ||
+ !table.ReadU16(&this->axesArrayOffset) ||
+ !table.ReadU16(&this->reserved) ||
+ !table.ReadU16(&this->axisCount) ||
+ !table.ReadU16(&this->axisSize) ||
+ !table.ReadU16(&this->instanceCount) ||
+ !table.ReadU16(&this->instanceSize)) {
+ return DropVariations("Failed to read table header");
+ }
+ if (this->majorVersion != 1) {
+ return DropVariations("Unknown table version");
+ }
+ if (this->minorVersion > 0) {
+ Warning("Downgrading minor version to 0");
+ this->minorVersion = 0;
+ }
+ if (this->axesArrayOffset > length || this->axesArrayOffset < table.offset()) {
+ return DropVariations("Bad axesArrayOffset");
+ }
+ if (this->reserved != 2) {
+ Warning("Expected reserved=2");
+ this->reserved = 2;
+ }
+ if (this->axisCount == 0) {
+ return DropVariations("No variation axes");
+ }
+ if (this->axisSize != 20) {
+ return DropVariations("Invalid axisSize");
+ }
+ // instanceCount is not validated
+ if (this->instanceSize == this->axisCount * sizeof(Fixed) + 6) {
+ this->instancesHavePostScriptNameID = true;
+ } else if (this->instanceSize == this->axisCount * sizeof(Fixed) + 4) {
+ this->instancesHavePostScriptNameID = false;
+ } else {
+ return DropVariations("Invalid instanceSize");
+ }
+
+ // When we serialize, the axes array will go here, even if it was
+ // originally at a different offset. So we update the axesArrayOffset
+ // field for the header.
+ uint32_t origAxesArrayOffset = this->axesArrayOffset;
+ this->axesArrayOffset = table.offset();
+
+ table.set_offset(origAxesArrayOffset);
+ for (unsigned i = 0; i < this->axisCount; i++) {
+ this->axes.emplace_back();
+ auto& axis = this->axes[i];
+ if (!table.ReadU32(&axis.axisTag) ||
+ !table.ReadS32(&axis.minValue) ||
+ !table.ReadS32(&axis.defaultValue) ||
+ !table.ReadS32(&axis.maxValue) ||
+ !table.ReadU16(&axis.flags) ||
+ !table.ReadU16(&axis.axisNameID)) {
+ return DropVariations("Failed to read axis record");
+ }
+ if (!CheckTag(axis.axisTag)) {
+ return DropVariations("Bad axis tag");
+ }
+ if (!(axis.minValue <= axis.defaultValue && axis.defaultValue <= axis.maxValue)) {
+ return DropVariations("Bad axis value range");
+ }
+ if ((axis.flags & 0xFFFEu) != 0) {
+ Warning("Discarding unknown axis flags");
+ axis.flags &= ~0xFFFEu;
+ }
+ if (axis.axisNameID <= 255 || axis.axisNameID >= 32768) {
+ Warning("Axis nameID out of range");
+ // We don't check that the name actually exists -- assume the client can handle
+ // a missing name when it tries to read the table.
+ }
+ }
+
+ for (unsigned i = 0; i < this->instanceCount; i++) {
+ this->instances.emplace_back();
+ auto& inst = this->instances[i];
+ if (!table.ReadU16(&inst.subfamilyNameID) ||
+ !table.ReadU16(&inst.flags)) {
+ return DropVariations("Failed to read instance record");
+ }
+ inst.coordinates.reserve(this->axisCount);
+ for (unsigned j = 0; j < this->axisCount; j++) {
+ inst.coordinates.emplace_back();
+ auto& coord = inst.coordinates[j];
+ if (!table.ReadS32(&coord)) {
+ return DropVariations("Failed to read instance coordinates");
+ }
+ }
+ if (this->instancesHavePostScriptNameID) {
+ if (!table.ReadU16(&inst.postScriptNameID)) {
+ return DropVariations("Failed to read instance psname ID");
+ }
+ }
+ }
+
+ if (table.remaining()) {
+ return Warning("%zu bytes unparsed", table.remaining());
+ }
+
+ return true;
+}
+
+bool OpenTypeFVAR::Serialize(OTSStream* out) {
+ if (!out->WriteU16(this->majorVersion) ||
+ !out->WriteU16(this->minorVersion) ||
+ !out->WriteU16(this->axesArrayOffset) ||
+ !out->WriteU16(this->reserved) ||
+ !out->WriteU16(this->axisCount) ||
+ !out->WriteU16(this->axisSize) ||
+ !out->WriteU16(this->instanceCount) ||
+ !out->WriteU16(this->instanceSize)) {
+ return Error("Failed to write table");
+ }
+
+ for (unsigned i = 0; i < this->axisCount; i++) {
+ const auto& axis = this->axes[i];
+ if (!out->WriteU32(axis.axisTag) ||
+ !out->WriteS32(axis.minValue) ||
+ !out->WriteS32(axis.defaultValue) ||
+ !out->WriteS32(axis.maxValue) ||
+ !out->WriteU16(axis.flags) ||
+ !out->WriteU16(axis.axisNameID)) {
+ return Error("Failed to write table");
+ }
+ }
+
+ for (unsigned i = 0; i < this->instanceCount; i++) {
+ const auto& inst = this->instances[i];
+ if (!out->WriteU16(inst.subfamilyNameID) ||
+ !out->WriteU16(inst.flags)) {
+ return Error("Failed to write table");
+ }
+ for (unsigned j = 0; j < this->axisCount; j++) {
+ const auto& coord = inst.coordinates[j];
+ if (!out->WriteS32(coord)) {
+ return Error("Failed to write table");
+ }
+ }
+ if (this->instancesHavePostScriptNameID) {
+ if (!out->WriteU16(inst.postScriptNameID)) {
+ return Error("Failed to write table");
+ }
+ }
+ }
+
+ return true;
+}
+
+} // namespace ots
diff --git a/gfx/ots/src/fvar.h b/gfx/ots/src/fvar.h
new file mode 100644
index 0000000000..a469c8cddf
--- /dev/null
+++ b/gfx/ots/src/fvar.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef OTS_FVAR_H_
+#define OTS_FVAR_H_
+
+#include
+
+#include "ots.h"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeFVAR Interface
+// -----------------------------------------------------------------------------
+
+class OpenTypeFVAR : public Table {
+ public:
+ explicit OpenTypeFVAR(Font* font, uint32_t tag)
+ : Table(font, tag, tag) { }
+
+ bool Parse(const uint8_t* data, size_t length);
+ bool Serialize(OTSStream* out);
+
+ uint16_t AxisCount() const { return axisCount; }
+
+ private:
+ uint16_t majorVersion;
+ uint16_t minorVersion;
+ uint16_t axesArrayOffset;
+ uint16_t reserved;
+ uint16_t axisCount;
+ uint16_t axisSize;
+ uint16_t instanceCount;
+ uint16_t instanceSize;
+
+ typedef int32_t Fixed; /* 16.16 fixed-point value */
+
+ struct VariationAxisRecord {
+ uint32_t axisTag;
+ Fixed minValue;
+ Fixed defaultValue;
+ Fixed maxValue;
+ uint16_t flags;
+ uint16_t axisNameID;
+ };
+ std::vector axes;
+
+ struct InstanceRecord {
+ uint16_t subfamilyNameID;
+ uint16_t flags;
+ std::vector coordinates;
+ uint16_t postScriptNameID; // optional
+ };
+ std::vector instances;
+
+ bool instancesHavePostScriptNameID;
+};
+
+} // namespace ots
+
+#endif // OTS_FVAR_H_
diff --git a/gfx/ots/src/gdef.cc b/gfx/ots/src/gdef.cc
index 01eab15c05..71e1075e3d 100644
--- a/gfx/ots/src/gdef.cc
+++ b/gfx/ots/src/gdef.cc
@@ -11,20 +11,17 @@
#include "gsub.h"
#include "layout.h"
#include "maxp.h"
+#include "variations.h"
// GDEF - The Glyph Definition Table
// http://www.microsoft.com/typography/otspec/gdef.htm
namespace {
-// The maximum class value in class definition tables.
-const uint16_t kMaxClassDefValue = 0xFFFF;
// The maximum class value in the glyph class definision table.
const uint16_t kMaxGlyphClassDefValue = 4;
// The maximum format number of caret value tables.
-// We don't support format 3 for now. See the comment in
-// ParseLigCaretListTable() for the reason.
-const uint16_t kMaxCaretValueFormat = 2;
+const uint16_t kMaxCaretValueFormat = 3;
} // namespace
@@ -165,9 +162,6 @@ bool OpenTypeGDEF::ParseLigCaretListTable(const uint8_t *data, size_t length) {
if (!subtable.ReadU16(&caret_format)) {
return Error("Can't read caret values table %d in glyph %d", j, i);
}
- // TODO(bashi): We only support caret value format 1 and 2 for now
- // because there are no fonts which contain caret value format 3
- // as far as we investigated.
if (caret_format == 0 || caret_format > kMaxCaretValueFormat) {
return Error("bad caret value format: %u", caret_format);
}
@@ -176,6 +170,24 @@ bool OpenTypeGDEF::ParseLigCaretListTable(const uint8_t *data, size_t length) {
if (!subtable.Skip(2)) {
return Error("Bad caret value table structure %d in glyph %d", j, i);
}
+ if (caret_format == 3) {
+ uint16_t offset_device = 0;
+ if (!subtable.ReadU16(&offset_device)) {
+ return Error("Can't read device offset for caret value %d "
+ "in glyph %d", j, i);
+ }
+ uint16_t absolute_offset = lig_glyphs[i] + caret_value_offsets[j]
+ + offset_device;
+ if (offset_device == 0 || absolute_offset >= length) {
+ return Error("Bad device offset for caret value %d in glyph %d: %d",
+ j, i, offset_device);
+ }
+ if (!ots::ParseDeviceTable(GetFont(), data + absolute_offset,
+ length - absolute_offset)) {
+ return Error("Bad device table for caret value %d in glyph %d",
+ j, i, offset_device);
+ }
+ }
}
}
return true;
@@ -228,18 +240,15 @@ bool OpenTypeGDEF::Parse(const uint8_t *data, size_t length) {
Buffer table(data, length);
- uint32_t version = 0;
- if (!table.ReadU32(&version)) {
+ uint16_t version_major = 0, version_minor = 0;
+ if (!table.ReadU16(&version_major) ||
+ !table.ReadU16(&version_minor)) {
return Error("Incomplete table");
}
- if (version < 0x00010000 || version == 0x00010001) {
+ if (version_major != 1 || version_minor == 1) { // there is no v1.1
return Error("Bad version");
}
- if (version >= 0x00010002) {
- this->version_2 = true;
- }
-
uint16_t offset_glyph_class_def = 0;
uint16_t offset_attach_list = 0;
uint16_t offset_lig_caret_list = 0;
@@ -251,15 +260,23 @@ bool OpenTypeGDEF::Parse(const uint8_t *data, size_t length) {
return Error("Incomplete table");
}
uint16_t offset_mark_glyph_sets_def = 0;
- if (this->version_2) {
+ if (version_minor >= 2) {
if (!table.ReadU16(&offset_mark_glyph_sets_def)) {
return Error("Incomplete table");
}
}
+ uint32_t item_var_store_offset = 0;
+ if (version_minor >= 3) {
+ if (!table.ReadU32(&item_var_store_offset)) {
+ return Error("Incomplete table");
+ }
+ }
unsigned gdef_header_end = 4 + 4 * 2;
- if (this->version_2)
+ if (version_minor >= 2)
gdef_header_end += 2;
+ if (version_minor >= 3)
+ gdef_header_end += 4;
// Parse subtables
if (offset_glyph_class_def) {
@@ -272,7 +289,6 @@ bool OpenTypeGDEF::Parse(const uint8_t *data, size_t length) {
this->m_num_glyphs, kMaxGlyphClassDefValue)) {
return Error("Invalid glyph classes");
}
- this->has_glyph_class_def = true;
}
if (offset_attach_list) {
@@ -308,7 +324,6 @@ bool OpenTypeGDEF::Parse(const uint8_t *data, size_t length) {
this->m_num_glyphs, kMaxClassDefValue)) {
return Error("Invalid mark attachment list");
}
- this->has_mark_attachment_class_def = true;
}
if (offset_mark_glyph_sets_def) {
@@ -320,8 +335,19 @@ bool OpenTypeGDEF::Parse(const uint8_t *data, size_t length) {
length - offset_mark_glyph_sets_def)) {
return Error("Invalid mark glyph sets");
}
- this->has_mark_glyph_sets_def = true;
}
+
+ if (item_var_store_offset) {
+ if (item_var_store_offset >= length ||
+ item_var_store_offset < gdef_header_end) {
+ return Error("invalid offset to item variation store");
+ }
+ if (!ParseItemVariationStore(GetFont(), data + item_var_store_offset,
+ length - item_var_store_offset)) {
+ return Error("Invalid item variation store");
+ }
+ }
+
this->m_data = data;
this->m_length = length;
return true;
diff --git a/gfx/ots/src/gdef.h b/gfx/ots/src/gdef.h
index 686956e841..7c7cc0ce53 100644
--- a/gfx/ots/src/gdef.h
+++ b/gfx/ots/src/gdef.h
@@ -13,10 +13,6 @@ class OpenTypeGDEF : public Table {
public:
explicit OpenTypeGDEF(Font *font, uint32_t tag)
: Table(font, tag, tag),
- version_2(false),
- has_glyph_class_def(false),
- has_mark_attachment_class_def(false),
- has_mark_glyph_sets_def(false),
num_mark_glyph_sets(0),
m_data(NULL),
m_length(0),
@@ -26,10 +22,6 @@ class OpenTypeGDEF : public Table {
bool Parse(const uint8_t *data, size_t length);
bool Serialize(OTSStream *out);
- bool version_2;
- bool has_glyph_class_def;
- bool has_mark_attachment_class_def;
- bool has_mark_glyph_sets_def;
uint16_t num_mark_glyph_sets;
private:
diff --git a/gfx/ots/src/glat.cc b/gfx/ots/src/glat.cc
index b7a2c47c48..23f7dfd9a8 100644
--- a/gfx/ots/src/glat.cc
+++ b/gfx/ots/src/glat.cc
@@ -200,7 +200,19 @@ bool OpenTypeGLAT_v3::Parse(const uint8_t* data, size_t length,
if (prevent_decompression) {
return DropGraphite("Illegal nested compression");
}
- std::vector decompressed(this->compHead & FULL_SIZE);
+ size_t decompressed_size = this->compHead & FULL_SIZE;
+ if (decompressed_size < length) {
+ return DropGraphite("Decompressed size is less than compressed size");
+ }
+ if (decompressed_size == 0) {
+ return DropGraphite("Decompressed size is set to 0");
+ }
+ // decompressed table must be <= 30MB
+ if (decompressed_size > 30 * 1024 * 1024) {
+ return DropGraphite("Decompressed size exceeds 30MB: %gMB",
+ decompressed_size / (1024.0 * 1024.0));
+ }
+ std::vector decompressed(decompressed_size);
size_t outputSize = 0;
bool ret = mozilla::Compression::LZ4::decompressPartial(
reinterpret_cast(data + table.offset()),
@@ -305,7 +317,7 @@ OctaboxMetrics::ParsePart(Buffer& table) {
unsigned subboxes_len = 0; // count of 1's in this->subbox_bitmap
for (uint16_t i = this->subbox_bitmap; i; i >>= 1) {
- if (i & 1) {
+ if (i & 0b1) {
++subboxes_len;
}
}
diff --git a/gfx/ots/src/gloc.cc b/gfx/ots/src/gloc.cc
index e06e978bc6..9c5ee3bdf6 100644
--- a/gfx/ots/src/gloc.cc
+++ b/gfx/ots/src/gloc.cc
@@ -25,7 +25,7 @@ bool OpenTypeGLOC::Parse(const uint8_t* data, size_t length) {
if (this->version >> 16 != 1) {
return DropGraphite("Unsupported table version: %u", this->version >> 16);
}
- if (!table.ReadU16(&this->flags) || this->flags > 3) {
+ if (!table.ReadU16(&this->flags) || this->flags > 0b11) {
return DropGraphite("Failed to read valid flags");
}
if (!table.ReadU16(&this->numAttribs)) {
diff --git a/gfx/ots/src/glyf.cc b/gfx/ots/src/glyf.cc
index 5d2aae5ff8..0c19d6d7bc 100644
--- a/gfx/ots/src/glyf.cc
+++ b/gfx/ots/src/glyf.cc
@@ -38,6 +38,16 @@ bool OpenTypeGLYF::ParseFlagsForSimpleGlyph(Buffer &glyph,
delta += 2;
}
+ /* MS and Apple specs say this bit is reserved and must be set to zero, but
+ * Apple spec then contradicts itself and says it should be set on the first
+ * contour flag for simple glyphs with overlapping contours:
+ * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6AATIntro.html
+ * (“Overlapping contours” section) */
+ if (flag & (1u << 6) && *flag_index != 0) {
+ return Error("Bad glyph flag (%d), "
+ "bit 6 must be set to zero for flag %d", flag, *flag_index);
+ }
+
if (flag & (1u << 3)) { // repeat
if (*flag_index + 1 >= num_flags) {
return Error("Count too high (%d + 1 >= %d)", *flag_index, num_flags);
@@ -57,8 +67,8 @@ bool OpenTypeGLYF::ParseFlagsForSimpleGlyph(Buffer &glyph,
}
}
- if ((flag & (1u << 6)) || (flag & (1u << 7))) { // reserved flags
- return Error("Bad glyph flag value (%d), reserved flags must be set to zero", flag);
+ if (flag & (1u << 7)) { // reserved flag
+ return Error("Bad glyph flag (%d), reserved bit 7 must be set to zero", flag);
}
*coordinates_length += delta;
@@ -96,8 +106,9 @@ bool OpenTypeGLYF::ParseSimpleGlyph(Buffer &glyph,
if (this->maxp->version_1 &&
this->maxp->max_size_glyf_instructions < bytecode_length) {
- return Error("Bytecode length is bigger than maxp.maxSizeOfInstructions "
- "%d: %d", this->maxp->max_size_glyf_instructions, bytecode_length);
+ this->maxp->max_size_glyf_instructions = bytecode_length;
+ Warning("Bytecode length is bigger than maxp.maxSizeOfInstructions %d: %d",
+ this->maxp->max_size_glyf_instructions, bytecode_length);
}
if (!glyph.Skip(bytecode_length)) {
@@ -192,9 +203,10 @@ bool OpenTypeGLYF::ParseCompositeGlyph(Buffer &glyph) {
if (this->maxp->version_1 &&
this->maxp->max_size_glyf_instructions < bytecode_length) {
- return Error("Bytecode length is bigger than maxp.maxSizeOfInstructions "
- "%d: %d",
- this->maxp->max_size_glyf_instructions, bytecode_length);
+ this->maxp->max_size_glyf_instructions = bytecode_length;
+ Warning("Bytecode length is bigger than maxp.maxSizeOfInstructions "
+ "%d: %d",
+ this->maxp->max_size_glyf_instructions, bytecode_length);
}
if (!glyph.Skip(bytecode_length)) {
diff --git a/gfx/ots/src/gpos.cc b/gfx/ots/src/gpos.cc
index 074b5b1cf0..034f9799d8 100644
--- a/gfx/ots/src/gpos.cc
+++ b/gfx/ots/src/gpos.cc
@@ -30,12 +30,12 @@ enum GPOS_TYPE {
GPOS_TYPE_RESERVED = 10
};
-// The size of gpos header.
-const unsigned kGposHeaderSize = 10;
+// The size of gpos header, version 1.0.
+const unsigned kGposHeaderSize_1_0 = 10;
+// The size of gpos header, version 1.1.
+const unsigned kGposHeaderSize_1_1 = 14;
// The maximum format number for anchor tables.
const uint16_t kMaxAnchorFormat = 3;
-// The maximum number of class value.
-const uint16_t kMaxClassDefValue = 0xFFFF;
// Lookup type parsers.
bool ParseSingleAdjustment(const ots::Font *font,
@@ -393,12 +393,12 @@ bool ParsePairPosFormat2(const ots::Font *font,
// Check class definition tables.
if (!ots::ParseClassDefTable(font, data + offset_class_def1,
length - offset_class_def1,
- num_glyphs, kMaxClassDefValue)) {
+ num_glyphs, ots::kMaxClassDefValue)) {
return OTS_FAILURE_MSG("Failed to parse class definition table 1");
}
if (!ots::ParseClassDefTable(font, data + offset_class_def2,
length - offset_class_def2,
- num_glyphs, kMaxClassDefValue)) {
+ num_glyphs, ots::kMaxClassDefValue)) {
return OTS_FAILURE_MSG("Failed to parse class definition table 2");
}
@@ -749,23 +749,34 @@ bool OpenTypeGPOS::Parse(const uint8_t *data, size_t length) {
Font *font = GetFont();
Buffer table(data, length);
- uint32_t version = 0;
+ uint16_t version_major = 0, version_minor = 0;
uint16_t offset_script_list = 0;
uint16_t offset_feature_list = 0;
uint16_t offset_lookup_list = 0;
- if (!table.ReadU32(&version) ||
+ uint32_t offset_feature_variations = 0;
+ if (!table.ReadU16(&version_major) ||
+ !table.ReadU16(&version_minor) ||
!table.ReadU16(&offset_script_list) ||
!table.ReadU16(&offset_feature_list) ||
!table.ReadU16(&offset_lookup_list)) {
return Error("Incomplete table");
}
- if (version != 0x00010000) {
+ if (version_major != 1 || version_minor > 1) {
return Error("Bad version");
}
+ if (version_minor > 0) {
+ if (!table.ReadU32(&offset_feature_variations)) {
+ return Error("Incomplete table");
+ }
+ }
+
+ const size_t header_size =
+ (version_minor == 0) ? kGposHeaderSize_1_0 : kGposHeaderSize_1_1;
+
if (offset_lookup_list) {
- if (offset_lookup_list < kGposHeaderSize || offset_lookup_list >= length) {
+ if (offset_lookup_list < header_size || offset_lookup_list >= length) {
return Error("Bad lookup list offset in table header");
}
@@ -779,7 +790,7 @@ bool OpenTypeGPOS::Parse(const uint8_t *data, size_t length) {
uint16_t num_features = 0;
if (offset_feature_list) {
- if (offset_feature_list < kGposHeaderSize || offset_feature_list >= length) {
+ if (offset_feature_list < header_size || offset_feature_list >= length) {
return Error("Bad feature list offset in table header");
}
@@ -791,7 +802,7 @@ bool OpenTypeGPOS::Parse(const uint8_t *data, size_t length) {
}
if (offset_script_list) {
- if (offset_script_list < kGposHeaderSize || offset_script_list >= length) {
+ if (offset_script_list < header_size || offset_script_list >= length) {
return Error("Bad script list offset in table header");
}
@@ -801,6 +812,18 @@ bool OpenTypeGPOS::Parse(const uint8_t *data, size_t length) {
}
}
+ if (offset_feature_variations) {
+ if (offset_feature_variations < header_size || offset_feature_variations >= length) {
+ return Error("Bad feature variations offset in table header");
+ }
+
+ if (!ParseFeatureVariationsTable(font, data + offset_feature_variations,
+ length - offset_feature_variations,
+ this->num_lookups)) {
+ return Error("Failed to parse feature variations table");
+ }
+ }
+
this->m_data = data;
this->m_length = length;
return true;
diff --git a/gfx/ots/src/graphite.h b/gfx/ots/src/graphite.h
index 1bd95f5c94..452cb26a87 100644
--- a/gfx/ots/src/graphite.h
+++ b/gfx/ots/src/graphite.h
@@ -14,6 +14,7 @@ template
class TablePart {
public:
TablePart(ParentType* parent) : parent(parent) { }
+ virtual ~TablePart() { }
virtual bool ParsePart(Buffer& table) = 0;
virtual bool SerializePart(OTSStream* out) const = 0;
protected:
diff --git a/gfx/ots/src/gsub.cc b/gfx/ots/src/gsub.cc
index 4db1b3e7aa..c90fb48f33 100644
--- a/gfx/ots/src/gsub.cc
+++ b/gfx/ots/src/gsub.cc
@@ -17,8 +17,10 @@
namespace {
-// The GSUB header size
-const size_t kGsubHeaderSize = 4 + 3 * 2;
+// The GSUB header size for table version 1.0
+const size_t kGsubHeaderSize_1_0 = 4 + 3 * 2;
+// GSUB header size v1.1
+const size_t kGsubHeaderSize_1_1 = 4 + 3 * 2 + 4;
enum GSUB_TYPE {
GSUB_TYPE_SINGLE = 1,
@@ -580,23 +582,34 @@ bool OpenTypeGSUB::Parse(const uint8_t *data, size_t length) {
Font *font = GetFont();
Buffer table(data, length);
- uint32_t version = 0;
+ uint16_t version_major = 0, version_minor = 0;
uint16_t offset_script_list = 0;
uint16_t offset_feature_list = 0;
uint16_t offset_lookup_list = 0;
- if (!table.ReadU32(&version) ||
+ uint32_t offset_feature_variations = 0;
+ if (!table.ReadU16(&version_major) ||
+ !table.ReadU16(&version_minor) ||
!table.ReadU16(&offset_script_list) ||
!table.ReadU16(&offset_feature_list) ||
!table.ReadU16(&offset_lookup_list)) {
return Error("Incomplete table");
}
- if (version != 0x00010000) {
+ if (version_major != 1 || version_minor > 1) {
return Error("Bad version");
}
+ if (version_minor > 0) {
+ if (!table.ReadU32(&offset_feature_variations)) {
+ return Error("Incomplete table");
+ }
+ }
+
+ const size_t header_size =
+ (version_minor == 0) ? kGsubHeaderSize_1_0 : kGsubHeaderSize_1_1;
+
if (offset_lookup_list) {
- if (offset_lookup_list < kGsubHeaderSize || offset_lookup_list >= length) {
+ if (offset_lookup_list < header_size || offset_lookup_list >= length) {
return Error("Bad lookup list offset in table header");
}
@@ -610,7 +623,7 @@ bool OpenTypeGSUB::Parse(const uint8_t *data, size_t length) {
uint16_t num_features = 0;
if (offset_feature_list) {
- if (offset_feature_list < kGsubHeaderSize || offset_feature_list >= length) {
+ if (offset_feature_list < header_size || offset_feature_list >= length) {
return Error("Bad feature list offset in table header");
}
@@ -622,7 +635,7 @@ bool OpenTypeGSUB::Parse(const uint8_t *data, size_t length) {
}
if (offset_script_list) {
- if (offset_script_list < kGsubHeaderSize || offset_script_list >= length) {
+ if (offset_script_list < header_size || offset_script_list >= length) {
return Error("Bad script list offset in table header");
}
@@ -632,6 +645,18 @@ bool OpenTypeGSUB::Parse(const uint8_t *data, size_t length) {
}
}
+ if (offset_feature_variations) {
+ if (offset_feature_variations < header_size || offset_feature_variations >= length) {
+ return Error("Bad feature variations offset in table header");
+ }
+
+ if (!ParseFeatureVariationsTable(font, data + offset_feature_variations,
+ length - offset_feature_variations,
+ this->num_lookups)) {
+ return Error("Failed to parse feature variations table");
+ }
+ }
+
this->m_data = data;
this->m_length = length;
return true;
diff --git a/gfx/ots/src/gvar.cc b/gfx/ots/src/gvar.cc
new file mode 100644
index 0000000000..324a0fc838
--- /dev/null
+++ b/gfx/ots/src/gvar.cc
@@ -0,0 +1,158 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gvar.h"
+
+#include "fvar.h"
+#include "maxp.h"
+#include "variations.h"
+
+#define TABLE_NAME "gvar"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeGVAR
+// -----------------------------------------------------------------------------
+
+static bool ParseSharedTuples(const Font* font, const uint8_t* data, size_t length,
+ size_t sharedTupleCount, size_t axisCount) {
+ Buffer subtable(data, length);
+ for (unsigned i = 0; i < sharedTupleCount; i++) {
+ for (unsigned j = 0; j < axisCount; j++) {
+ int16_t coordinate;
+ if (!subtable.ReadS16(&coordinate)) {
+ return OTS_FAILURE_MSG("Failed to read shared tuple coordinate");
+ }
+ }
+ }
+ return true;
+}
+
+static bool ParseGlyphVariationDataArray(const Font* font, const uint8_t* data, size_t length,
+ uint16_t flags, size_t glyphCount, size_t axisCount,
+ size_t sharedTupleCount,
+ const uint8_t* glyphVariationData,
+ size_t glyphVariationDataLength) {
+ Buffer subtable(data, length);
+
+ bool glyphVariationDataOffsetsAreLong = (flags & 0x0001u);
+ uint32_t prevOffset = 0;
+ for (size_t i = 0; i < glyphCount + 1; i++) {
+ uint32_t offset;
+ if (glyphVariationDataOffsetsAreLong) {
+ if (!subtable.ReadU32(&offset)) {
+ return OTS_FAILURE_MSG("Failed to read GlyphVariationData offset");
+ }
+ } else {
+ uint16_t halfOffset;
+ if (!subtable.ReadU16(&halfOffset)) {
+ return OTS_FAILURE_MSG("Failed to read GlyphVariationData offset");
+ }
+ offset = halfOffset * 2;
+ }
+
+ if (i > 0 && offset > prevOffset) {
+ if (prevOffset > glyphVariationDataLength) {
+ return OTS_FAILURE_MSG("Invalid GlyphVariationData offset");
+ }
+ if (!ParseVariationData(font, glyphVariationData + prevOffset,
+ glyphVariationDataLength - prevOffset,
+ axisCount, sharedTupleCount)) {
+ return OTS_FAILURE_MSG("Failed to parse GlyphVariationData");
+ }
+ }
+ prevOffset = offset;
+ }
+
+ return true;
+}
+
+bool OpenTypeGVAR::Parse(const uint8_t* data, size_t length) {
+ Buffer table(data, length);
+
+ uint16_t majorVersion;
+ uint16_t minorVersion;
+ uint16_t axisCount;
+ uint16_t sharedTupleCount;
+ uint32_t sharedTuplesOffset;
+ uint16_t glyphCount;
+ uint16_t flags;
+ uint32_t glyphVariationDataArrayOffset;
+
+ if (!table.ReadU16(&majorVersion) ||
+ !table.ReadU16(&minorVersion) ||
+ !table.ReadU16(&axisCount) ||
+ !table.ReadU16(&sharedTupleCount) ||
+ !table.ReadU32(&sharedTuplesOffset) ||
+ !table.ReadU16(&glyphCount) ||
+ !table.ReadU16(&flags) ||
+ !table.ReadU32(&glyphVariationDataArrayOffset)) {
+ return DropVariations("Failed to read table header");
+ }
+ if (majorVersion != 1) {
+ return DropVariations("Unknown table version");
+ }
+
+ // check axisCount == fvar->axisCount
+ OpenTypeFVAR* fvar = static_cast(
+ GetFont()->GetTypedTable(OTS_TAG_FVAR));
+ if (!fvar) {
+ return DropVariations("Required fvar table is missing");
+ }
+ if (axisCount != fvar->AxisCount()) {
+ return DropVariations("Axis count mismatch");
+ }
+
+ // check glyphCount == maxp->num_glyphs
+ OpenTypeMAXP* maxp = static_cast(
+ GetFont()->GetTypedTable(OTS_TAG_MAXP));
+ if (!maxp) {
+ return DropVariations("Required maxp table is missing");
+ }
+ if (glyphCount != maxp->num_glyphs) {
+ return DropVariations("Glyph count mismatch");
+ }
+
+ if (sharedTupleCount > 0) {
+ if (sharedTuplesOffset < table.offset() || sharedTuplesOffset > length) {
+ return DropVariations("Invalid sharedTuplesOffset");
+ }
+ if (!ParseSharedTuples(GetFont(),
+ data + sharedTuplesOffset, length - sharedTuplesOffset,
+ sharedTupleCount, axisCount)) {
+ return DropVariations("Failed to parse shared tuples");
+ }
+ }
+
+ if (glyphVariationDataArrayOffset) {
+ if (glyphVariationDataArrayOffset > length) {
+ return DropVariations("Invalid glyphVariationDataArrayOffset");
+ }
+ if (!ParseGlyphVariationDataArray(GetFont(),
+ data + table.offset(), length - table.offset(),
+ flags, glyphCount, axisCount, sharedTupleCount,
+ data + glyphVariationDataArrayOffset,
+ length - glyphVariationDataArrayOffset)) {
+ return DropVariations("Failed to read glyph variation data array");
+ }
+ }
+
+ this->m_data = data;
+ this->m_length = length;
+
+ return true;
+}
+
+bool OpenTypeGVAR::Serialize(OTSStream* out) {
+ if (!out->Write(this->m_data, this->m_length)) {
+ return Error("Failed to write gvar table");
+ }
+
+ return true;
+}
+
+} // namespace ots
+
+#undef TABLE_NAME
diff --git a/gfx/ots/src/gvar.h b/gfx/ots/src/gvar.h
new file mode 100644
index 0000000000..8a90c57a39
--- /dev/null
+++ b/gfx/ots/src/gvar.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef OTS_GVAR_H_
+#define OTS_GVAR_H_
+
+#include "ots.h"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeGVAR Interface
+// -----------------------------------------------------------------------------
+
+class OpenTypeGVAR : public Table {
+ public:
+ explicit OpenTypeGVAR(Font* font, uint32_t tag)
+ : Table(font, tag, tag) { }
+
+ bool Parse(const uint8_t* data, size_t length);
+ bool Serialize(OTSStream* out);
+
+ private:
+ const uint8_t *m_data;
+ size_t m_length;
+};
+
+} // namespace ots
+
+#endif // OTS_GVAR_H_
diff --git a/gfx/ots/src/hvar.cc b/gfx/ots/src/hvar.cc
new file mode 100644
index 0000000000..2bcea86803
--- /dev/null
+++ b/gfx/ots/src/hvar.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "hvar.h"
+
+#include "variations.h"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeHVAR
+// -----------------------------------------------------------------------------
+
+bool OpenTypeHVAR::Parse(const uint8_t* data, size_t length) {
+ Buffer table(data, length);
+
+ uint16_t majorVersion;
+ uint16_t minorVersion;
+ uint32_t itemVariationStoreOffset;
+ uint32_t advanceWidthMappingOffset;
+ uint32_t lsbMappingOffset;
+ uint32_t rsbMappingOffset;
+
+ if (!table.ReadU16(&majorVersion) ||
+ !table.ReadU16(&minorVersion) ||
+ !table.ReadU32(&itemVariationStoreOffset) ||
+ !table.ReadU32(&advanceWidthMappingOffset) ||
+ !table.ReadU32(&lsbMappingOffset) ||
+ !table.ReadU32(&rsbMappingOffset)) {
+ return DropVariations("Failed to read table header");
+ }
+
+ if (majorVersion != 1) {
+ return DropVariations("Unknown table version");
+ }
+
+ if (itemVariationStoreOffset > length ||
+ advanceWidthMappingOffset > length ||
+ lsbMappingOffset > length ||
+ rsbMappingOffset > length) {
+ return DropVariations("Invalid subtable offset");
+ }
+
+ if (!ParseItemVariationStore(GetFont(), data + itemVariationStoreOffset,
+ length - itemVariationStoreOffset)) {
+ return DropVariations("Failed to parse item variation store");
+ }
+
+ if (advanceWidthMappingOffset) {
+ if (!ParseDeltaSetIndexMap(GetFont(), data + advanceWidthMappingOffset,
+ length - advanceWidthMappingOffset)) {
+ return DropVariations("Failed to parse advance width mappings");
+ }
+ }
+
+ if (lsbMappingOffset) {
+ if (!ParseDeltaSetIndexMap(GetFont(), data + lsbMappingOffset,
+ length - lsbMappingOffset)) {
+ return DropVariations("Failed to parse LSB mappings");
+ }
+ }
+
+ if (rsbMappingOffset) {
+ if (!ParseDeltaSetIndexMap(GetFont(), data + rsbMappingOffset,
+ length - rsbMappingOffset)) {
+ return DropVariations("Failed to parse RSB mappings");
+ }
+ }
+
+ this->m_data = data;
+ this->m_length = length;
+
+ return true;
+}
+
+bool OpenTypeHVAR::Serialize(OTSStream* out) {
+ if (!out->Write(this->m_data, this->m_length)) {
+ return Error("Failed to write HVAR table");
+ }
+
+ return true;
+}
+
+} // namespace ots
diff --git a/gfx/ots/src/hvar.h b/gfx/ots/src/hvar.h
new file mode 100644
index 0000000000..5bfd2e4eae
--- /dev/null
+++ b/gfx/ots/src/hvar.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef OTS_HVAR_H_
+#define OTS_HVAR_H_
+
+#include "ots.h"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeHVAR Interface
+// -----------------------------------------------------------------------------
+
+class OpenTypeHVAR : public Table {
+ public:
+ explicit OpenTypeHVAR(Font* font, uint32_t tag)
+ : Table(font, tag, tag) { }
+
+ bool Parse(const uint8_t* data, size_t length);
+ bool Serialize(OTSStream* out);
+
+ private:
+ const uint8_t *m_data;
+ size_t m_length;
+};
+
+} // namespace ots
+
+#endif // OTS_HVAR_H_
diff --git a/gfx/ots/src/layout.cc b/gfx/ots/src/layout.cc
index c21ede7e97..8e99f573df 100644
--- a/gfx/ots/src/layout.cc
+++ b/gfx/ots/src/layout.cc
@@ -7,6 +7,7 @@
#include
#include
+#include "fvar.h"
#include "gdef.h"
// OpenType Layout Common Table Formats
@@ -22,14 +23,11 @@ const uint32_t kScriptTableTagDflt = 0x44464c54;
const uint16_t kNoRequiredFeatureIndexDefined = 0xFFFF;
// The lookup flag bit which indicates existence of MarkFilteringSet.
const uint16_t kUseMarkFilteringSetBit = 0x0010;
-// The lookup flags which require GDEF table.
-const uint16_t kGdefRequiredFlags = 0x0002 | 0x0004 | 0x0008;
-// The mask for MarkAttachmentType.
-const uint16_t kMarkAttachmentTypeMask = 0xFF00;
// The maximum type number of format for device tables.
const uint16_t kMaxDeltaFormatType = 3;
-// The maximum number of class value.
-const uint16_t kMaxClassDefValue = 0xFFFF;
+// In variation fonts, Device Tables are replaced by VariationIndex tables,
+// indicated by this flag in the deltaFormat field.
+const uint16_t kVariationIndex = 0x8000;
struct ScriptRecord {
uint32_t tag;
@@ -194,30 +192,7 @@ bool ParseLookupTable(ots::Font *font, const uint8_t *data,
return OTS_FAILURE_MSG("Bad lookup type %d", lookup_type);
}
- ots::OpenTypeGDEF *gdef = static_cast(
- font->GetTypedTable(OTS_TAG_GDEF));
-
- // Check lookup flags.
- if ((lookup_flag & kGdefRequiredFlags) &&
- (!gdef || !gdef->has_glyph_class_def)) {
- return OTS_FAILURE_MSG("Lookup flags require GDEF table, "
- "but none was found: %d", lookup_flag);
- }
- if ((lookup_flag & kMarkAttachmentTypeMask) &&
- (!gdef || !gdef->has_mark_attachment_class_def)) {
- return OTS_FAILURE_MSG("Lookup flags ask for mark attachment, "
- "but there is no GDEF table or it has no "
- "mark attachment classes: %d", lookup_flag);
- }
- bool use_mark_filtering_set = false;
- if (lookup_flag & kUseMarkFilteringSetBit) {
- if (!gdef || !gdef->has_mark_glyph_sets_def) {
- return OTS_FAILURE_MSG("Lookup flags ask for mark filtering, "
- "but there is no GDEF table or it has no "
- "mark filtering sets: %d", lookup_flag);
- }
- use_mark_filtering_set = true;
- }
+ bool use_mark_filtering_set = lookup_flag & kUseMarkFilteringSetBit;
std::vector subtables;
subtables.reserve(subtable_count);
@@ -248,8 +223,12 @@ bool ParseLookupTable(ots::Font *font, const uint8_t *data,
if (!subtable.ReadU16(&mark_filtering_set)) {
return OTS_FAILURE_MSG("Failed to read mark filtering set");
}
- if (gdef->num_mark_glyph_sets == 0 ||
- mark_filtering_set >= gdef->num_mark_glyph_sets) {
+
+ ots::OpenTypeGDEF *gdef = static_cast(
+ font->GetTypedTable(OTS_TAG_GDEF));
+
+ if (gdef && (gdef->num_mark_glyph_sets == 0 ||
+ mark_filtering_set >= gdef->num_mark_glyph_sets)) {
return OTS_FAILURE_MSG("Bad mark filtering set %d", mark_filtering_set);
}
}
@@ -664,7 +643,7 @@ bool ParseContextFormat2(const ots::Font *font,
}
if (!ots::ParseClassDefTable(font, data + offset_class_def,
length - offset_class_def,
- num_glyphs, kMaxClassDefValue)) {
+ num_glyphs, ots::kMaxClassDefValue)) {
return OTS_FAILURE_MSG("Failed to parse class definition table in context format 2");
}
@@ -1017,7 +996,7 @@ bool ParseChainContextFormat2(const ots::Font *font,
}
if (!ots::ParseClassDefTable(font, data + offset_backtrack_class_def,
length - offset_backtrack_class_def,
- num_glyphs, kMaxClassDefValue)) {
+ num_glyphs, ots::kMaxClassDefValue)) {
return OTS_FAILURE_MSG("Failed to parse backtrack class defn table in chain context format 2");
}
}
@@ -1028,7 +1007,7 @@ bool ParseChainContextFormat2(const ots::Font *font,
}
if (!ots::ParseClassDefTable(font, data + offset_input_class_def,
length - offset_input_class_def,
- num_glyphs, kMaxClassDefValue)) {
+ num_glyphs, ots::kMaxClassDefValue)) {
return OTS_FAILURE_MSG("Failed to parse input class defn in chain context format 2");
}
@@ -1039,7 +1018,7 @@ bool ParseChainContextFormat2(const ots::Font *font,
}
if (!ots::ParseClassDefTable(font, data + offset_lookahead_class_def,
length - offset_lookahead_class_def,
- num_glyphs, kMaxClassDefValue)) {
+ num_glyphs, ots::kMaxClassDefValue)) {
return OTS_FAILURE_MSG("Failed to parse lookahead class defn in chain context format 2");
}
}
@@ -1403,11 +1382,17 @@ bool ParseDeviceTable(const ots::Font *font,
!subtable.ReadU16(&delta_format)) {
return OTS_FAILURE_MSG("Failed to read device table header");
}
+ if (delta_format == kVariationIndex) {
+ // start_size and end_size are replaced by deltaSetOuterIndex
+ // and deltaSetInnerIndex respectively, but we don't attempt to
+ // check them here, so nothing more to do.
+ return true;
+ }
if (start_size > end_size) {
- return OTS_FAILURE_MSG("bad size range: %u > %u", start_size, end_size);
+ return OTS_FAILURE_MSG("Bad device table size range: %u > %u", start_size, end_size);
}
if (delta_format == 0 || delta_format > kMaxDeltaFormatType) {
- return OTS_FAILURE_MSG("bad delta format: %u", delta_format);
+ return OTS_FAILURE_MSG("Bad device table delta format: 0x%x", delta_format);
}
// The number of delta values per uint16. The device table should contain
// at least |num_units| * 2 bytes compressed data.
@@ -1519,6 +1504,173 @@ bool ParseExtensionSubtable(const Font *font,
return true;
}
+bool ParseConditionTable(const Font *font,
+ const uint8_t *data, const size_t length,
+ const uint16_t axis_count) {
+ Buffer subtable(data, length);
+
+ uint16_t format = 0;
+ if (!subtable.ReadU16(&format)) {
+ return OTS_FAILURE_MSG("Failed to read condition table format");
+ }
+
+ if (format != 1) {
+ // An unknown format is not an error, but should be ignored per spec.
+ return true;
+ }
+
+ uint16_t axis_index = 0;
+ int16_t filter_range_min_value = 0;
+ int16_t filter_range_max_value = 0;
+ if (!subtable.ReadU16(&axis_index) ||
+ !subtable.ReadS16(&filter_range_min_value) ||
+ !subtable.ReadS16(&filter_range_max_value)) {
+ return OTS_FAILURE_MSG("Failed to read condition table (format 1)");
+ }
+
+ if (axis_index >= axis_count) {
+ return OTS_FAILURE_MSG("Axis index out of range in condition");
+ }
+
+ // Check min/max values are within range -1.0 .. 1.0 and properly ordered
+ if (filter_range_min_value < -0x4000 || // -1.0 in F2DOT14 format
+ filter_range_max_value > 0x4000 || // +1.0 in F2DOT14 format
+ filter_range_min_value > filter_range_max_value) {
+ return OTS_FAILURE_MSG("Invalid filter range in condition");
+ }
+
+ return true;
+}
+
+bool ParseConditionSetTable(const Font *font,
+ const uint8_t *data, const size_t length,
+ const uint16_t axis_count) {
+ Buffer subtable(data, length);
+
+ uint16_t condition_count = 0;
+ if (!subtable.ReadU16(&condition_count)) {
+ return OTS_FAILURE_MSG("Failed to read condition count");
+ }
+
+ for (uint16_t i = 0; i < condition_count; i++) {
+ uint32_t condition_offset = 0;
+ if (!subtable.ReadU32(&condition_offset)) {
+ return OTS_FAILURE_MSG("Failed to read condition offset");
+ }
+ if (condition_offset < subtable.offset() || condition_offset >= length) {
+ return OTS_FAILURE_MSG("Offset out of range");
+ }
+ if (!ParseConditionTable(font, data + condition_offset, length - condition_offset,
+ axis_count)) {
+ return OTS_FAILURE_MSG("Failed to parse condition table");
+ }
+ }
+
+ return true;
+}
+
+bool ParseFeatureTableSubstitutionTable(const Font *font,
+ const uint8_t *data, const size_t length,
+ const uint16_t num_lookups) {
+ Buffer subtable(data, length);
+
+ uint16_t version_major = 0;
+ uint16_t version_minor = 0;
+ uint16_t substitution_count = 0;
+ const size_t kFeatureTableSubstitutionHeaderSize = 3 * sizeof(uint16_t);
+
+ if (!subtable.ReadU16(&version_major) ||
+ !subtable.ReadU16(&version_minor) ||
+ !subtable.ReadU16(&substitution_count)) {
+ return OTS_FAILURE_MSG("Failed to read feature table substitution table header");
+ }
+
+ for (uint16_t i = 0; i < substitution_count; i++) {
+ uint16_t feature_index = 0;
+ uint32_t alternate_feature_table_offset = 0;
+ const size_t kFeatureTableSubstitutionRecordSize = sizeof(uint16_t) + sizeof(uint32_t);
+
+ if (!subtable.ReadU16(&feature_index) ||
+ !subtable.ReadU32(&alternate_feature_table_offset)) {
+ return OTS_FAILURE_MSG("Failed to read feature table substitution record");
+ }
+
+ if (alternate_feature_table_offset < kFeatureTableSubstitutionHeaderSize +
+ kFeatureTableSubstitutionRecordSize * substitution_count ||
+ alternate_feature_table_offset >= length) {
+ return OTS_FAILURE_MSG("Invalid alternate feature table offset");
+ }
+
+ if (!ParseFeatureTable(font, data + alternate_feature_table_offset,
+ length - alternate_feature_table_offset, num_lookups)) {
+ return OTS_FAILURE_MSG("Failed to parse alternate feature table");
+ }
+ }
+
+ return true;
+}
+
+bool ParseFeatureVariationsTable(const Font *font,
+ const uint8_t *data, const size_t length,
+ const uint16_t num_lookups) {
+ Buffer subtable(data, length);
+
+ uint16_t version_major = 0;
+ uint16_t version_minor = 0;
+ uint32_t feature_variation_record_count = 0;
+
+ if (!subtable.ReadU16(&version_major) ||
+ !subtable.ReadU16(&version_minor) ||
+ !subtable.ReadU32(&feature_variation_record_count)) {
+ return OTS_FAILURE_MSG("Failed to read feature variations table header");
+ }
+
+ OpenTypeFVAR* fvar = static_cast(font->GetTypedTable(OTS_TAG_FVAR));
+ if (!fvar) {
+ return OTS_FAILURE_MSG("Not a variation font");
+ }
+ const uint16_t axis_count = fvar->AxisCount();
+
+ const size_t kEndOfFeatureVariationRecords =
+ 2 * sizeof(uint16_t) + sizeof(uint32_t) +
+ feature_variation_record_count * 2 * sizeof(uint32_t);
+
+ for (uint32_t i = 0; i < feature_variation_record_count; i++) {
+ uint32_t condition_set_offset = 0;
+ uint32_t feature_table_substitution_offset = 0;
+ if (!subtable.ReadU32(&condition_set_offset) ||
+ !subtable.ReadU32(&feature_table_substitution_offset)) {
+ return OTS_FAILURE_MSG("Failed to read feature variation record");
+ }
+
+ if (condition_set_offset) {
+ if (condition_set_offset < kEndOfFeatureVariationRecords ||
+ condition_set_offset >= length) {
+ return OTS_FAILURE_MSG("Condition set offset out of range");
+ }
+ if (!ParseConditionSetTable(font, data + condition_set_offset,
+ length - condition_set_offset,
+ axis_count)) {
+ return OTS_FAILURE_MSG("Failed to parse condition set table");
+ }
+ }
+
+ if (feature_table_substitution_offset) {
+ if (feature_table_substitution_offset < kEndOfFeatureVariationRecords ||
+ feature_table_substitution_offset >= length) {
+ return OTS_FAILURE_MSG("Feature table substitution offset out of range");
+ }
+ if (!ParseFeatureTableSubstitutionTable(font, data + feature_table_substitution_offset,
+ length - feature_table_substitution_offset,
+ num_lookups)) {
+ return OTS_FAILURE_MSG("Failed to parse feature table substitution table");
+ }
+ }
+ }
+
+ return true;
+}
+
} // namespace ots
#undef TABLE_NAME
diff --git a/gfx/ots/src/layout.h b/gfx/ots/src/layout.h
index 4d18f40404..d10a3be5bd 100644
--- a/gfx/ots/src/layout.h
+++ b/gfx/ots/src/layout.h
@@ -12,6 +12,8 @@
namespace ots {
+// The maximum number of class value.
+const uint16_t kMaxClassDefValue = 0xFFFF;
struct LookupSubtableParser {
struct TypeParser {
@@ -70,6 +72,23 @@ bool ParseExtensionSubtable(const Font *font,
const uint8_t *data, const size_t length,
const LookupSubtableParser* parser);
+// For feature variations table (in GSUB/GPOS v1.1)
+bool ParseConditionTable(const Font *font,
+ const uint8_t *data, const size_t length,
+ const uint16_t axis_count);
+
+bool ParseConditionSetTable(const Font *font,
+ const uint8_t *data, const size_t length,
+ const uint16_t axis_count);
+
+bool ParseFeatureTableSubstitutionTable(const Font *font,
+ const uint8_t *data, const size_t length,
+ const uint16_t num_lookups);
+
+bool ParseFeatureVariationsTable(const Font *font,
+ const uint8_t *data, const size_t length,
+ const uint16_t num_lookups);
+
} // namespace ots
#endif // OTS_LAYOUT_H_
diff --git a/gfx/ots/src/moz.build b/gfx/ots/src/moz.build
index ce217bcda0..962a86a5b9 100644
--- a/gfx/ots/src/moz.build
+++ b/gfx/ots/src/moz.build
@@ -9,28 +9,29 @@ EXPORTS += [
'../include/ots-memory-stream.h',
]
-SOURCES += [
- # needs to be separate because gpos.cc also defines kMaxClassDefValue
- 'gdef.cc',
-]
-
UNIFIED_SOURCES += [
+ 'avar.cc',
'cff.cc',
- 'cff_type2_charstring.cc',
+ 'cff_charstring.cc',
'cmap.cc',
+ 'cvar.cc',
'cvt.cc',
'feat.cc',
'fpgm.cc',
+ 'fvar.cc',
'gasp.cc',
+ 'gdef.cc',
'glat.cc',
'gloc.cc',
'glyf.cc',
'gpos.cc',
'gsub.cc',
+ 'gvar.cc',
'hdmx.cc',
'head.cc',
'hhea.cc',
'hmtx.cc',
+ 'hvar.cc',
'kern.cc',
'layout.cc',
'loca.cc',
@@ -38,6 +39,7 @@ UNIFIED_SOURCES += [
'math.cc',
'maxp.cc',
'metrics.cc',
+ 'mvar.cc',
'name.cc',
'os2.cc',
'ots.cc',
@@ -46,10 +48,13 @@ UNIFIED_SOURCES += [
'sile.cc',
'silf.cc',
'sill.cc',
+ 'stat.cc',
+ 'variations.cc',
'vdmx.cc',
'vhea.cc',
'vmtx.cc',
'vorg.cc',
+ 'vvar.cc',
]
# We allow warnings for third-party code that can be updated from upstream.
@@ -60,6 +65,7 @@ FINAL_LIBRARY = 'gkmedias'
DEFINES['PACKAGE_VERSION'] = '"moz"'
DEFINES['PACKAGE_BUGREPORT'] = '"http://bugzilla.mozilla.org/"'
DEFINES['OTS_GRAPHITE'] = 1
+DEFINES['OTS_VARIATIONS'] = 1
USE_LIBS += [
'brotli',
diff --git a/gfx/ots/src/mvar.cc b/gfx/ots/src/mvar.cc
new file mode 100644
index 0000000000..d021203d39
--- /dev/null
+++ b/gfx/ots/src/mvar.cc
@@ -0,0 +1,105 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mvar.h"
+
+#include "variations.h"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeMVAR
+// -----------------------------------------------------------------------------
+
+bool OpenTypeMVAR::Parse(const uint8_t* data, size_t length) {
+ Buffer table(data, length);
+
+ uint16_t majorVersion;
+ uint16_t minorVersion;
+ uint16_t reserved;
+ uint16_t valueRecordSize;
+ uint16_t valueRecordCount;
+ uint16_t itemVariationStoreOffset;
+
+ if (!table.ReadU16(&majorVersion) ||
+ !table.ReadU16(&minorVersion) ||
+ !table.ReadU16(&reserved) ||
+ !table.ReadU16(&valueRecordSize) ||
+ !table.ReadU16(&valueRecordCount) ||
+ !table.ReadU16(&itemVariationStoreOffset)) {
+ return DropVariations("Failed to read table header");
+ }
+
+ if (majorVersion != 1) {
+ return DropVariations("Unknown table version");
+ }
+
+ if (reserved != 0) {
+ Warning("Expected reserved=0");
+ }
+
+ // The spec says that valueRecordSize "must be greater than zero",
+ // but we don't enforce this in the case where valueRecordCount
+ // is zero.
+ // The minimum size for a valueRecord to be valid is 8, for the
+ // three fields currently defined in the record (see below).
+ if (valueRecordSize < 8) {
+ if (valueRecordCount != 0) {
+ return DropVariations("Value record size too small");
+ }
+ }
+
+ if (valueRecordCount == 0) {
+ if (itemVariationStoreOffset != 0) {
+ // The spec says "if valueRecordCount is zero, set to zero",
+ // but having a variation store even when record count is zero
+ // should be harmless -- it just won't be useful for anything.
+ // But we don't need to reject altogether.
+ Warning("Unexpected item variation store");
+ }
+ } else {
+ if (itemVariationStoreOffset < table.offset() || itemVariationStoreOffset > length) {
+ return DropVariations("Invalid item variation store offset");
+ }
+ if (!ParseItemVariationStore(GetFont(), data + itemVariationStoreOffset,
+ length - itemVariationStoreOffset)) {
+ return DropVariations("Failed to parse item variation store");
+ }
+ }
+
+ uint32_t prevTag = 0;
+ size_t offset = table.offset();
+ for (unsigned i = 0; i < valueRecordCount; i++) {
+ uint32_t tag;
+ uint16_t deltaSetOuterIndex, deltaSetInnerIndex;
+ if (!table.ReadU32(&tag) ||
+ !table.ReadU16(&deltaSetOuterIndex) ||
+ !table.ReadU16(&deltaSetInnerIndex)) {
+ return DropVariations("Failed to read value record");
+ }
+ if (tag <= prevTag) {
+ return DropVariations("Invalid or out-of-order value tag");
+ }
+ prevTag = tag;
+ // Adjust offset in case additional fields have been added to the
+ // valueRecord by a new minor version (allowed by spec).
+ offset += valueRecordSize;
+ table.set_offset(offset);
+ }
+
+ this->m_data = data;
+ this->m_length = length;
+
+ return true;
+}
+
+bool OpenTypeMVAR::Serialize(OTSStream* out) {
+ if (!out->Write(this->m_data, this->m_length)) {
+ return Error("Failed to write MVAR table");
+ }
+
+ return true;
+}
+
+} // namespace ots
diff --git a/gfx/ots/src/mvar.h b/gfx/ots/src/mvar.h
new file mode 100644
index 0000000000..81fb6155dd
--- /dev/null
+++ b/gfx/ots/src/mvar.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2018 The OTS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef OTS_MVAR_H_
+#define OTS_MVAR_H_
+
+#include "ots.h"
+
+namespace ots {
+
+// -----------------------------------------------------------------------------
+// OpenTypeMVAR Interface
+// -----------------------------------------------------------------------------
+
+class OpenTypeMVAR : public Table {
+ public:
+ explicit OpenTypeMVAR(Font* font, uint32_t tag)
+ : Table(font, tag, tag) { }
+
+ bool Parse(const uint8_t* data, size_t length);
+ bool Serialize(OTSStream* out);
+
+ private:
+ const uint8_t *m_data;
+ size_t m_length;
+};
+
+} // namespace ots
+
+#endif // OTS_MVAR_H_
diff --git a/gfx/ots/src/name.cc b/gfx/ots/src/name.cc
index dd1e83206c..11deeecaad 100644
--- a/gfx/ots/src/name.cc
+++ b/gfx/ots/src/name.cc
@@ -169,6 +169,14 @@ bool OpenTypeNAME::Parse(const uint8_t* data, size_t length) {
if (tag_end > length) {
return Error("bad end of tag %d > %ld for langTagRecord %d", tag_end, length, i);
}
+ // Lang tag is BCP 47 tag per the spec, the recommonded BCP 47 max tag
+ // length is 35:
+ // https://tools.ietf.org/html/bcp47#section-4.4.1
+ // We are being too generous and allowing for 100 (multiplied by 2 since
+ // this is UTF-16 string).
+ if (tag_length > 100 * 2) {
+ return Error("Too long language tag for LangTagRecord %d: %d", i, tag_length);
+ }
std::string tag(string_base + tag_offset, tag_length);
this->lang_tags.push_back(tag);
}
@@ -203,17 +211,16 @@ bool OpenTypeNAME::Parse(const uint8_t* data, size_t length) {
// if not, we'll add our fixed versions here
bool mac_name[kStdNameCount] = { 0 };
bool win_name[kStdNameCount] = { 0 };
- for (std::vector::iterator name_iter = this->names.begin();
- name_iter != this->names.end(); ++name_iter) {
- const uint16_t id = name_iter->name_id;
+ for (const auto& name : this->names) {
+ const uint16_t id = name.name_id;
if (id >= kStdNameCount || kStdNames[id] == NULL) {
continue;
}
- if (name_iter->platform_id == 1) {
+ if (name.platform_id == 1) {
mac_name[id] = true;
continue;
}
- if (name_iter->platform_id == 3) {
+ if (name.platform_id == 3) {
win_name[id] = true;
continue;
}
@@ -266,9 +273,7 @@ bool OpenTypeNAME::Serialize(OTSStream* out) {
}
std::string string_data;
- for (std::vector::const_iterator name_iter = this->names.begin();
- name_iter != this->names.end(); ++name_iter) {
- const NameRecord& rec = *name_iter;
+ for (const auto& rec : this->names) {
if (string_data.size() + rec.text.size() >
std::numeric_limits::max() ||
!out->WriteU16(rec.platform_id) ||
@@ -286,16 +291,14 @@ bool OpenTypeNAME::Serialize(OTSStream* out) {
if (!out->WriteU16(lang_tag_count)) {
return Error("Faile to write langTagCount");
}
- for (std::vector::const_iterator tag_iter =
- this->lang_tags.begin();
- tag_iter != this->lang_tags.end(); ++tag_iter) {
- if (string_data.size() + tag_iter->size() >
+ for (const auto& tag : this->lang_tags) {
+ if (string_data.size() + tag.size() >
std::numeric_limits::max() ||
- !out->WriteU16(static_cast(tag_iter->size())) ||
+ !out->WriteU16(static_cast(tag.size())) ||
!out->WriteU16(static_cast(string_data.size()))) {
return Error("Failed to write langTagRecord");
}
- string_data.append(*tag_iter);
+ string_data.append(tag);
}
}
diff --git a/gfx/ots/src/os2.cc b/gfx/ots/src/os2.cc
index d298987108..5376a1dbb1 100644
--- a/gfx/ots/src/os2.cc
+++ b/gfx/ots/src/os2.cc
@@ -38,17 +38,14 @@ bool OpenTypeOS2::Parse(const uint8_t *data, size_t length) {
return Error("Unsupported table version: %u", this->table.version);
}
- // Follow WPF Font Selection Model's advice.
- if (1 <= this->table.weight_class && this->table.weight_class <= 9) {
- Warning("Bad usWeightClass: %u, changing it to %u",
- this->table.weight_class, this->table.weight_class * 100);
- this->table.weight_class *= 100;
- }
- // Ditto.
- if (this->table.weight_class > 999) {
+ if (this->table.weight_class < 1) {
Warning("Bad usWeightClass: %u, changing it to %d",
- this->table.weight_class, 999);
- this->table.weight_class = 999;
+ this->table.weight_class, 1);
+ this->table.weight_class = 1;
+ } else if (this->table.weight_class > 1000) {
+ Warning("Bad usWeightClass: %u, changing it to %d",
+ this->table.weight_class, 1000);
+ this->table.weight_class = 1000;
}
if (this->table.width_class < 1) {
@@ -89,7 +86,7 @@ bool OpenTypeOS2::Parse(const uint8_t *data, size_t length) {
SET_TO_ZERO("yStrikeoutSize", strikeout_size);
#undef SET_TO_ZERO
- static std::string panose_strings[10] = {
+ static const char* panose_strings[10] = {
"bFamilyType",
"bSerifStyle",
"bWeight",
@@ -103,7 +100,7 @@ bool OpenTypeOS2::Parse(const uint8_t *data, size_t length) {
};
for (unsigned i = 0; i < 10; ++i) {
if (!table.ReadU8(&this->table.panose[i])) {
- return Error("Failed to read PANOSE %s", panose_strings[i].c_str());
+ return Error("Failed to read PANOSE %s", panose_strings[i]);
}
}
@@ -155,16 +152,17 @@ bool OpenTypeOS2::Parse(const uint8_t *data, size_t length) {
if ((this->table.version < 4) &&
(this->table.selection & 0x300)) {
// bit 8 and 9 must be unset in OS/2 table versions less than 4.
- return Error("fSelection bits 8 and 9 must be unset for table version %d",
- this->table.version);
+ Warning("fsSelection bits 8 and 9 must be unset for table version %d",
+ this->table.version);
}
// mask reserved bits. use only 0..9 bits.
this->table.selection &= 0x3ff;
if (this->table.first_char_index > this->table.last_char_index) {
- return Error("usFirstCharIndex %d > usLastCharIndex %d",
- this->table.first_char_index, this->table.last_char_index);
+ Warning("usFirstCharIndex %d > usLastCharIndex %d",
+ this->table.first_char_index, this->table.last_char_index);
+ this->table.first_char_index = this->table.last_char_index;
}
if (this->table.typo_linegap < 0) {
Warning("Bad sTypoLineGap, setting it to 0: %d", this->table.typo_linegap);
diff --git a/gfx/ots/src/ots.cc b/gfx/ots/src/ots.cc
index 281aa7288c..38d97a9edf 100644
--- a/gfx/ots/src/ots.cc
+++ b/gfx/ots/src/ots.cc
@@ -14,38 +14,46 @@
#include