Commit 3a672fe0 authored by ksakamoto's avatar ksakamoto Committed by Commit bot

Update OTS to revision 6d2e08b

This brings in a bugfix of checksum calculation that caused assertion
failure on debug builds.

BUG=464780

Review URL: https://codereview.chromium.org/1062093002

Cr-Commit-Position: refs/heads/master@{#324023}
parent 9318af7f
Name: OTS Name: OTS
URL: https://github.com/khaledhosny/ots.git URL: https://github.com/khaledhosny/ots.git
Version: 4d011721c2eadd4e649326f8d164423db060d85e Version: 6d2e08bdc56d6739d48f5e59594669616f6b8b9d
Security Critical: yes Security Critical: yes
License: BSD License: BSD
Local Modifications: Local Modifications:
- src/woff2.cc: Changed include path to brotli/dec/decode.h. - src/woff2.cc: Changed include path to brotli/dec/decode.h.
- BUILD.gn: Added.
...@@ -29,6 +29,9 @@ typedef unsigned __int64 uint64_t; ...@@ -29,6 +29,9 @@ typedef unsigned __int64 uint64_t;
#include <cstddef> #include <cstddef>
#include <cstring> #include <cstring>
#define OTS_TAG(c1,c2,c3,c4) ((uint32_t)((((uint8_t)(c1))<<24)|(((uint8_t)(c2))<<16)|(((uint8_t)(c3))<<8)|((uint8_t)(c4))))
#define OTS_UNTAG(tag) ((uint8_t)((tag)>>24)), ((uint8_t)((tag)>>16)), ((uint8_t)((tag)>>8)), ((uint8_t)(tag))
namespace ots { namespace ots {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -37,9 +40,7 @@ namespace ots { ...@@ -37,9 +40,7 @@ namespace ots {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
class OTSStream { class OTSStream {
public: public:
OTSStream() { OTSStream() : chksum_(0) {}
ResetChecksum();
}
virtual ~OTSStream() {} virtual ~OTSStream() {}
...@@ -51,20 +52,15 @@ class OTSStream { ...@@ -51,20 +52,15 @@ class OTSStream {
const size_t orig_length = length; const size_t orig_length = length;
size_t offset = 0; size_t offset = 0;
if (chksum_buffer_offset_) {
const size_t l =
std::min(length, static_cast<size_t>(4) - chksum_buffer_offset_);
std::memcpy(chksum_buffer_ + chksum_buffer_offset_, data, l);
chksum_buffer_offset_ += l;
offset += l;
length -= l;
}
if (chksum_buffer_offset_ == 4) { size_t chksum_offset = Tell() & 3;
uint32_t tmp; if (chksum_offset) {
std::memcpy(&tmp, chksum_buffer_, 4); const size_t l = std::min(length, static_cast<size_t>(4) - chksum_offset);
uint32_t tmp = 0;
std::memcpy(reinterpret_cast<uint8_t *>(&tmp) + chksum_offset, data, l);
chksum_ += ntohl(tmp); chksum_ += ntohl(tmp);
chksum_buffer_offset_ = 0; length -= l;
offset += l;
} }
while (length >= 4) { while (length >= 4) {
...@@ -77,11 +73,11 @@ class OTSStream { ...@@ -77,11 +73,11 @@ class OTSStream {
} }
if (length) { if (length) {
if (chksum_buffer_offset_ != 0) return false; // not reached
if (length > 4) return false; // not reached if (length > 4) return false; // not reached
std::memcpy(chksum_buffer_, uint32_t tmp = 0;
reinterpret_cast<const uint8_t*>(data) + offset, length); std::memcpy(&tmp,
chksum_buffer_offset_ = length; reinterpret_cast<const uint8_t*>(data) + offset, length);
chksum_ += ntohl(tmp);
} }
return WriteRaw(data, orig_length); return WriteRaw(data, orig_length);
...@@ -142,41 +138,16 @@ class OTSStream { ...@@ -142,41 +138,16 @@ class OTSStream {
} }
void ResetChecksum() { void ResetChecksum() {
assert((Tell() & 3) == 0);
chksum_ = 0; chksum_ = 0;
chksum_buffer_offset_ = 0;
} }
uint32_t chksum() const { uint32_t chksum() const {
assert(chksum_buffer_offset_ == 0);
return chksum_; return chksum_;
} }
struct ChecksumState {
uint32_t chksum;
uint8_t chksum_buffer[4];
unsigned chksum_buffer_offset;
};
ChecksumState SaveChecksumState() const {
ChecksumState s;
s.chksum = chksum_;
s.chksum_buffer_offset = chksum_buffer_offset_;
std::memcpy(s.chksum_buffer, chksum_buffer_, 4);
return s;
}
void RestoreChecksum(const ChecksumState &s) {
assert(chksum_buffer_offset_ == 0);
chksum_ += s.chksum;
chksum_buffer_offset_ = s.chksum_buffer_offset;
std::memcpy(chksum_buffer_, s.chksum_buffer, 4);
}
protected: protected:
uint32_t chksum_; uint32_t chksum_;
uint8_t chksum_buffer_[4];
unsigned chksum_buffer_offset_;
}; };
#ifdef __GCC__ #ifdef __GCC__
...@@ -218,9 +189,6 @@ class OTSContext { ...@@ -218,9 +189,6 @@ class OTSContext {
virtual TableAction GetTableAction(uint32_t tag) { return ots::TABLE_ACTION_DEFAULT; } virtual TableAction GetTableAction(uint32_t tag) { return ots::TABLE_ACTION_DEFAULT; }
}; };
// For backward compatibility - remove once Chrome switches over to the new API.
bool Process(OTSStream *output, const uint8_t *input, size_t length);
} // namespace ots } // namespace ots
#endif // OPENTYPE_SANITISER_H_ #endif // OPENTYPE_SANITISER_H_
...@@ -1023,10 +1023,6 @@ bool ots_cmap_serialise(OTSStream *out, OpenTypeFile *file) { ...@@ -1023,10 +1023,6 @@ bool ots_cmap_serialise(OTSStream *out, OpenTypeFile *file) {
} }
const off_t table_end = out->Tell(); const off_t table_end = out->Tell();
// We might have hanging bytes from the above's checksum which the OTSStream
// then merges into the table of offsets.
OTSStream::ChecksumState saved_checksum = out->SaveChecksumState();
out->ResetChecksum();
// Now seek back and write the table of offsets // Now seek back and write the table of offsets
if (!out->Seek(record_offset)) { if (!out->Seek(record_offset)) {
...@@ -1092,7 +1088,6 @@ bool ots_cmap_serialise(OTSStream *out, OpenTypeFile *file) { ...@@ -1092,7 +1088,6 @@ bool ots_cmap_serialise(OTSStream *out, OpenTypeFile *file) {
if (!out->Seek(table_end)) { if (!out->Seek(table_end)) {
return OTS_FAILURE(); return OTS_FAILURE();
} }
out->RestoreChecksum(saved_checksum);
return true; return true;
} }
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "os2.h" #include <string>
#include "os2.h"
#include "head.h" #include "head.h"
// OS/2 - OS/2 and Windows Metrics // OS/2 - OS/2 and Windows Metrics
...@@ -35,26 +36,29 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { ...@@ -35,26 +36,29 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
!table.ReadS16(&os2->strikeout_size) || !table.ReadS16(&os2->strikeout_size) ||
!table.ReadS16(&os2->strikeout_position) || !table.ReadS16(&os2->strikeout_position) ||
!table.ReadS16(&os2->family_class)) { !table.ReadS16(&os2->family_class)) {
return OTS_FAILURE_MSG("Failed toi read basic os2 elements"); return OTS_FAILURE_MSG("Error reading basic table elements");
} }
if (os2->version > 4) { if (os2->version > 5) {
return OTS_FAILURE_MSG("os2 version too high %d", os2->version); return OTS_FAILURE_MSG("Unsupported table version: %u", os2->version);
} }
// Some linux fonts (e.g., Kedage-t.ttf and LucidaSansDemiOblique.ttf) have // Follow WPF Font Selection Model's advice.
// weird weight/width classes. Overwrite them with FW_NORMAL/1/9. if (1 <= os2->weight_class && os2->weight_class <= 9) {
if (os2->weight_class < 100 || OTS_WARNING("Bad usWeightClass: %u, changing it to: %u", os2->weight_class, os2->weight_class * 100);
os2->weight_class > 900 || os2->weight_class *= 100;
os2->weight_class % 100) {
OTS_WARNING("bad weight: %u", os2->weight_class);
os2->weight_class = 400; // FW_NORMAL
} }
// Ditto.
if (os2->weight_class > 999) {
OTS_WARNING("Bad usWeightClass: %u, changing it to: %d", os2->weight_class, 999);
os2->weight_class = 999;
}
if (os2->width_class < 1) { if (os2->width_class < 1) {
OTS_WARNING("bad width: %u", os2->width_class); OTS_WARNING("Bad usWidthClass: %u, changing it to: %d", os2->width_class, 1);
os2->width_class = 1; os2->width_class = 1;
} else if (os2->width_class > 9) { } else if (os2->width_class > 9) {
OTS_WARNING("bad width: %u", os2->width_class); OTS_WARNING("Bad usWidthClass: %u, changing it to: %d", os2->width_class, 9);
os2->width_class = 9; os2->width_class = 9;
} }
...@@ -73,30 +77,34 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { ...@@ -73,30 +77,34 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
// mask reserved bits. use only 0..3, 8, 9 bits. // mask reserved bits. use only 0..3, 8, 9 bits.
os2->type &= 0x30f; os2->type &= 0x30f;
if (os2->subscript_x_size < 0) { #define SET_TO_ZERO(a, b) \
OTS_WARNING("bad subscript_x_size: %d", os2->subscript_x_size); if (os2->b < 0) { \
os2->subscript_x_size = 0; OTS_WARNING("Bad " a ": %d, setting it to zero", os2->b); \
} os2->b = 0; \
if (os2->subscript_y_size < 0) { }
OTS_WARNING("bad subscript_y_size: %d", os2->subscript_y_size);
os2->subscript_y_size = 0; SET_TO_ZERO("ySubscriptXSize", subscript_x_size);
} SET_TO_ZERO("ySubscriptYSize", subscript_y_size);
if (os2->superscript_x_size < 0) { SET_TO_ZERO("ySuperscriptXSize", superscript_x_size);
OTS_WARNING("bad superscript_x_size: %d", os2->superscript_x_size); SET_TO_ZERO("ySuperscriptYSize", superscript_y_size);
os2->superscript_x_size = 0; SET_TO_ZERO("yStrikeoutSize", strikeout_size);
} #undef SET_TO_ZERO
if (os2->superscript_y_size < 0) {
OTS_WARNING("bad superscript_y_size: %d", os2->superscript_y_size); static std::string panose_strings[10] = {
os2->superscript_y_size = 0; "bFamilyType",
} "bSerifStyle",
if (os2->strikeout_size < 0) { "bWeight",
OTS_WARNING("bad strikeout_size: %d", os2->strikeout_size); "bProportion",
os2->strikeout_size = 0; "bContrast",
} "bStrokeVariation",
"bArmStyle",
"bLetterform",
"bMidline",
"bXHeight",
};
for (unsigned i = 0; i < 10; ++i) { for (unsigned i = 0; i < 10; ++i) {
if (!table.ReadU8(&os2->panose[i])) { if (!table.ReadU8(&os2->panose[i])) {
return OTS_FAILURE_MSG("Failed to read panose in os2 table"); return OTS_FAILURE_MSG("Error reading PANOSE %s", panose_strings[i].c_str());
} }
} }
...@@ -113,7 +121,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { ...@@ -113,7 +121,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
!table.ReadS16(&os2->typo_linegap) || !table.ReadS16(&os2->typo_linegap) ||
!table.ReadU16(&os2->win_ascent) || !table.ReadU16(&os2->win_ascent) ||
!table.ReadU16(&os2->win_descent)) { !table.ReadU16(&os2->win_descent)) {
return OTS_FAILURE_MSG("Failed to read more basic os2 fields"); return OTS_FAILURE_MSG("Error reading more basic table fields");
} }
// If bit 6 is set, then bits 0 and 5 must be clear. // If bit 6 is set, then bits 0 and 5 must be clear.
...@@ -124,7 +132,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { ...@@ -124,7 +132,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
// the settings of bits 0 and 1 must be reflected in the macStyle bits // the settings of bits 0 and 1 must be reflected in the macStyle bits
// in the 'head' table. // in the 'head' table.
if (!file->head) { if (!file->head) {
return OTS_FAILURE_MSG("Head table missing from font as needed by os2 table"); return OTS_FAILURE_MSG("Needed head table is missing from the font");
} }
if ((os2->selection & 0x1) && if ((os2->selection & 0x1) &&
!(file->head->mac_style & 0x2)) { !(file->head->mac_style & 0x2)) {
...@@ -148,7 +156,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { ...@@ -148,7 +156,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
if ((os2->version < 4) && if ((os2->version < 4) &&
(os2->selection & 0x300)) { (os2->selection & 0x300)) {
// bit 8 and 9 must be unset in OS/2 table versions less than 4. // bit 8 and 9 must be unset in OS/2 table versions less than 4.
return OTS_FAILURE_MSG("OS2 version %d incompatible with selection %d", os2->version, os2->selection); return OTS_FAILURE_MSG("Version %d incompatible with selection %d", os2->version, os2->selection);
} }
// mask reserved bits. use only 0..9 bits. // mask reserved bits. use only 0..9 bits.
...@@ -198,7 +206,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { ...@@ -198,7 +206,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
!table.ReadU16(&os2->default_char) || !table.ReadU16(&os2->default_char) ||
!table.ReadU16(&os2->break_char) || !table.ReadU16(&os2->break_char) ||
!table.ReadU16(&os2->max_context)) { !table.ReadU16(&os2->max_context)) {
return OTS_FAILURE_MSG("Failed to read os2 version 2 information"); return OTS_FAILURE_MSG("Failed to read version 2-specific fields");
} }
if (os2->x_height < 0) { if (os2->x_height < 0) {
...@@ -210,6 +218,26 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { ...@@ -210,6 +218,26 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
os2->cap_height = 0; os2->cap_height = 0;
} }
if (os2->version < 5) {
// http://www.microsoft.com/typography/otspec/os2ver4.htm
return true;
}
if (!table.ReadU16(&os2->lower_optical_pointsize) ||
!table.ReadU16(&os2->upper_optical_pointsize)) {
return OTS_FAILURE_MSG("Failed to read version 5-specific fields");
}
if (os2->lower_optical_pointsize > 0xFFFE) {
OTS_WARNING("'usLowerOpticalPointSize' is bigger than 0xFFFE: %d", os2->lower_optical_pointsize);
os2->lower_optical_pointsize = 0xFFFE;
}
if (os2->upper_optical_pointsize < 2) {
OTS_WARNING("'usUpperOpticalPointSize' is lower than 2: %d", os2->upper_optical_pointsize);
os2->upper_optical_pointsize = 2;
}
return true; return true;
} }
...@@ -258,7 +286,7 @@ bool ots_os2_serialise(OTSStream *out, OpenTypeFile *file) { ...@@ -258,7 +286,7 @@ bool ots_os2_serialise(OTSStream *out, OpenTypeFile *file) {
!out->WriteS16(os2->typo_linegap) || !out->WriteS16(os2->typo_linegap) ||
!out->WriteU16(os2->win_ascent) || !out->WriteU16(os2->win_ascent) ||
!out->WriteU16(os2->win_descent)) { !out->WriteU16(os2->win_descent)) {
return OTS_FAILURE_MSG("Failed to write os2 version 1 information"); return OTS_FAILURE_MSG("Failed to write version 1-specific fields");
} }
if (os2->version < 1) { if (os2->version < 1) {
...@@ -279,7 +307,16 @@ bool ots_os2_serialise(OTSStream *out, OpenTypeFile *file) { ...@@ -279,7 +307,16 @@ bool ots_os2_serialise(OTSStream *out, OpenTypeFile *file) {
!out->WriteU16(os2->default_char) || !out->WriteU16(os2->default_char) ||
!out->WriteU16(os2->break_char) || !out->WriteU16(os2->break_char) ||
!out->WriteU16(os2->max_context)) { !out->WriteU16(os2->max_context)) {
return OTS_FAILURE_MSG("Failed to write os2 version 2 information"); return OTS_FAILURE_MSG("Failed to write version 2-specific fields");
}
if (os2->version < 2) {
return true;
}
if (!out->WriteU16(os2->lower_optical_pointsize) ||
!out->WriteU16(os2->upper_optical_pointsize)) {
return OTS_FAILURE_MSG("Failed to write version 5-specific fields");
} }
return true; return true;
......
...@@ -47,6 +47,8 @@ struct OpenTypeOS2 { ...@@ -47,6 +47,8 @@ struct OpenTypeOS2 {
uint16_t default_char; uint16_t default_char;
uint16_t break_char; uint16_t break_char;
uint16_t max_context; uint16_t max_context;
uint16_t lower_optical_pointsize;
uint16_t upper_optical_pointsize;
}; };
} // namespace ots } // namespace ots
......
...@@ -24,6 +24,7 @@ namespace { ...@@ -24,6 +24,7 @@ namespace {
// Generate a message with or without a table tag, when 'header' is the OpenTypeFile pointer // Generate a message with or without a table tag, when 'header' is the OpenTypeFile pointer
#define OTS_FAILURE_MSG_TAG(msg_,tag_) OTS_FAILURE_MSG_TAG_(header, msg_, tag_) #define OTS_FAILURE_MSG_TAG(msg_,tag_) OTS_FAILURE_MSG_TAG_(header, msg_, tag_)
#define OTS_FAILURE_MSG_HDR(msg_) OTS_FAILURE_MSG_(header, msg_) #define OTS_FAILURE_MSG_HDR(msg_) OTS_FAILURE_MSG_(header, msg_)
#define OTS_WARNING_MSG_HDR(msg_) OTS_WARNING_MSG_(header, msg_)
struct OpenTypeTable { struct OpenTypeTable {
...@@ -472,7 +473,7 @@ bool ProcessGeneric(ots::OpenTypeFile *header, uint32_t signature, ...@@ -472,7 +473,7 @@ bool ProcessGeneric(ots::OpenTypeFile *header, uint32_t signature,
const uint32_t this_tag = ntohl(tables[i].tag); const uint32_t this_tag = ntohl(tables[i].tag);
const uint32_t prev_tag = ntohl(tables[i - 1].tag); const uint32_t prev_tag = ntohl(tables[i - 1].tag);
if (this_tag <= prev_tag) { if (this_tag <= prev_tag) {
return OTS_FAILURE_MSG_HDR("table directory not correctly ordered"); OTS_WARNING_MSG_HDR("Table directory is not correctly ordered");
} }
} }
...@@ -818,10 +819,4 @@ bool OTSContext::Process(OTSStream *output, ...@@ -818,10 +819,4 @@ bool OTSContext::Process(OTSStream *output,
return result; return result;
} }
// For backward compatibility
bool Process(OTSStream *output, const uint8_t *data, size_t length) {
static OTSContext context;
return context.Process(output, data, length);
}
} // namespace ots } // namespace ots
...@@ -45,7 +45,7 @@ const size_t kCompositeGlyphBegin = 10; ...@@ -45,7 +45,7 @@ const size_t kCompositeGlyphBegin = 10;
// Note that the byte order is big-endian, not the same as ots.cc // Note that the byte order is big-endian, not the same as ots.cc
#define TAG(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d) #define TAG(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
#define CHR(t) (t >> 24), (t >> 16), (t >> 8), (t >> 0) #define UNTAG(t) (t >> 24), (t >> 16), (t >> 8), (t >> 0)
const unsigned int kWoff2FlagsTransform = 1 << 5; const unsigned int kWoff2FlagsTransform = 1 << 5;
...@@ -772,17 +772,6 @@ bool FixChecksums(const std::vector<Table>& tables, uint8_t* dst) { ...@@ -772,17 +772,6 @@ bool FixChecksums(const std::vector<Table>& tables, uint8_t* dst) {
return true; return true;
} }
bool Woff2Uncompress(uint8_t* dst_buf, size_t dst_size,
const uint8_t* src_buf, size_t src_size) {
size_t uncompressed_size = dst_size;
int ok = BrotliDecompressBuffer(src_size, src_buf,
&uncompressed_size, dst_buf);
if (!ok || uncompressed_size != dst_size) {
return OTS_FAILURE();
}
return true;
}
bool ReadTableDirectory(ots::OpenTypeFile* file, bool ReadTableDirectory(ots::OpenTypeFile* file,
ots::Buffer* buffer, std::vector<Table>* tables, ots::Buffer* buffer, std::vector<Table>* tables,
size_t num_tables) { size_t num_tables) {
...@@ -812,12 +801,16 @@ bool ReadTableDirectory(ots::OpenTypeFile* file, ...@@ -812,12 +801,16 @@ bool ReadTableDirectory(ots::OpenTypeFile* file,
} }
uint32_t dst_length; uint32_t dst_length;
if (!ReadBase128(buffer, &dst_length)) { if (!ReadBase128(buffer, &dst_length)) {
return OTS_FAILURE_MSG("Failed to read 'origLength' for table '%c%c%c%c'", CHR(tag)); return OTS_FAILURE_MSG("Failed to read 'origLength' for table '%c%c%c%c'", UNTAG(tag));
} }
uint32_t transform_length = dst_length; uint32_t transform_length = dst_length;
if ((flags & kWoff2FlagsTransform) != 0) { if ((flags & kWoff2FlagsTransform) != 0) {
if (!ReadBase128(buffer, &transform_length)) { if (!ReadBase128(buffer, &transform_length)) {
return OTS_FAILURE_MSG("Failed to read 'transformLength' for table '%c%c%c%c'", CHR(tag)); return OTS_FAILURE_MSG("Failed to read 'transformLength' for table '%c%c%c%c'", UNTAG(tag));
}
if (tag == TAG('l', 'o', 'c', 'a') && transform_length != 0) {
return OTS_FAILURE_MSG("The 'transformLength' of 'loca' table must be zero: %d", transform_length);
} }
} }
// Disallow huge numbers (> 1GB) for sanity. // Disallow huge numbers (> 1GB) for sanity.
...@@ -1020,13 +1013,16 @@ bool ConvertWOFF2ToSFNT(ots::OpenTypeFile* file, ...@@ -1020,13 +1013,16 @@ bool ConvertWOFF2ToSFNT(ots::OpenTypeFile* file,
if (total_size > 30 * 1024 * 1024) { if (total_size > 30 * 1024 * 1024) {
return OTS_FAILURE(); return OTS_FAILURE();
} }
const size_t total_size_size_t = static_cast<size_t>(total_size); size_t uncompressed_size = static_cast<size_t>(total_size);
uncompressed_buf.resize(total_size_size_t); uncompressed_buf.resize(uncompressed_size);
const uint8_t* src_buf = data + compressed_offset; const uint8_t* compressed_buf = data + compressed_offset;
if (!Woff2Uncompress(&uncompressed_buf[0], total_size_size_t, if (!BrotliDecompressBuffer(compressed_length, compressed_buf,
src_buf, compressed_length)) { &uncompressed_size, &uncompressed_buf[0])) {
return OTS_FAILURE_MSG("Failed to uncompress font data"); return OTS_FAILURE_MSG("Failed to uncompress font data");
} }
if (uncompressed_size != static_cast<size_t>(total_size)) {
return OTS_FAILURE_MSG("Decompressed font data size does not match the sum of 'origLength' and 'transformLength'");
}
transform_buf = &uncompressed_buf[0]; transform_buf = &uncompressed_buf[0];
for (uint16_t i = 0; i < num_tables; ++i) { for (uint16_t i = 0; i < num_tables; ++i) {
...@@ -1047,7 +1043,7 @@ bool ConvertWOFF2ToSFNT(ots::OpenTypeFile* file, ...@@ -1047,7 +1043,7 @@ bool ConvertWOFF2ToSFNT(ots::OpenTypeFile* file,
} else { } else {
if (!ReconstructTransformed(file, tables, table->tag, if (!ReconstructTransformed(file, tables, table->tag,
transform_buf, transform_length, result, result_length)) { transform_buf, transform_length, result, result_length)) {
return OTS_FAILURE_MSG("Failed to reconstruct '%c%c%c%c' table", CHR(table->tag)); return OTS_FAILURE_MSG("Failed to reconstruct '%c%c%c%c' table", UNTAG(table->tag));
} }
} }
......
...@@ -49,18 +49,18 @@ class Context: public ots::OTSContext { ...@@ -49,18 +49,18 @@ class Context: public ots::OTSContext {
} }
virtual ots::TableAction GetTableAction(uint32_t tag) { virtual ots::TableAction GetTableAction(uint32_t tag) {
#define TAG(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
switch (tag) { switch (tag) {
case TAG('S','i','l','f'): case OTS_TAG('S','i','l','f'):
case TAG('S','i','l','l'): case OTS_TAG('S','i','l','l'):
case TAG('G','l','o','c'): case OTS_TAG('G','l','o','c'):
case TAG('G','l','a','t'): case OTS_TAG('G','l','a','t'):
case TAG('F','e','a','t'): case OTS_TAG('F','e','a','t'):
case OTS_TAG('C','B','D','T'):
case OTS_TAG('C','B','L','C'):
return ots::TABLE_ACTION_PASSTHRU; return ots::TABLE_ACTION_PASSTHRU;
default: default:
return ots::TABLE_ACTION_DEFAULT; return ots::TABLE_ACTION_DEFAULT;
} }
#undef TAG
} }
}; };
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
namespace { namespace {
void DumpBitmap(const FT_Bitmap *bitmap) { void DumpBitmap(const FT_Bitmap *bitmap) {
for (int i = 0; i < bitmap->rows * bitmap->width; ++i) { for (unsigned int i = 0; i < bitmap->rows * bitmap->width; ++i) {
if (bitmap->buffer[i] > 192) { if (bitmap->buffer[i] > 192) {
std::fprintf(stderr, "#"); std::fprintf(stderr, "#");
} else if (bitmap->buffer[i] > 128) { } else if (bitmap->buffer[i] > 128) {
...@@ -44,7 +44,7 @@ int CompareBitmaps(const FT_Bitmap *orig, const FT_Bitmap *trans) { ...@@ -44,7 +44,7 @@ int CompareBitmaps(const FT_Bitmap *orig, const FT_Bitmap *trans) {
if (orig->width == trans->width && if (orig->width == trans->width &&
orig->rows == trans->rows) { orig->rows == trans->rows) {
for (int i = 0; i < orig->rows * orig->width; ++i) { for (unsigned int i = 0; i < orig->rows * orig->width; ++i) {
if (orig->buffer[i] != trans->buffer[i]) { if (orig->buffer[i] != trans->buffer[i]) {
std::fprintf(stderr, "bitmap data doesn't match!\n"); std::fprintf(stderr, "bitmap data doesn't match!\n");
ret = 1; ret = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment