diff options
author | zhaoqin <zhaoqin@chromium.org> | 2015-04-07 08:26:58 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-07 15:27:29 +0000 |
commit | 2a0977c4c2dfa7614f1e0eea3d0f0c21937565b3 (patch) | |
tree | 8823d4bed9f47a954aff8d292afcf4dec964e2ff /third_party | |
parent | a41990641a23ad8738881e4731022472135b2e0c (diff) | |
download | chromium_src-2a0977c4c2dfa7614f1e0eea3d0f0c21937565b3.zip chromium_src-2a0977c4c2dfa7614f1e0eea3d0f0c21937565b3.tar.gz chromium_src-2a0977c4c2dfa7614f1e0eea3d0f0c21937565b3.tar.bz2 |
Revert of Update OTS to revision 6d2e08b (patchset #1 id:1 of https://codereview.chromium.org/1062093002/)
Reason for revert:
This CL caused many tests fail on uninit read errors reported by MSan
BUG=474597
Original issue's description:
> Update OTS to revision 6d2e08b
>
> This brings in a bugfix of checksum calculation that caused assertion
> failure on debug builds.
>
> BUG=464780
>
> Committed: https://crrev.com/3a672fe050438bc787af3f9bb652048291558c6c
> Cr-Commit-Position: refs/heads/master@{#324023}
TBR=bashi@chromium.org,ksakamoto@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=464780
Review URL: https://codereview.chromium.org/1064913002
Cr-Commit-Position: refs/heads/master@{#324046}
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/ots/README.chromium | 3 | ||||
-rw-r--r-- | third_party/ots/include/opentype-sanitiser.h | 64 | ||||
-rw-r--r-- | third_party/ots/src/cmap.cc | 5 | ||||
-rw-r--r-- | third_party/ots/src/os2.cc | 119 | ||||
-rw-r--r-- | third_party/ots/src/os2.h | 2 | ||||
-rw-r--r-- | third_party/ots/src/ots.cc | 9 | ||||
-rw-r--r-- | third_party/ots/src/woff2.cc | 36 | ||||
-rw-r--r-- | third_party/ots/test/ot-sanitise.cc | 14 | ||||
-rw-r--r-- | third_party/ots/test/side-by-side.cc | 4 |
9 files changed, 131 insertions, 125 deletions
diff --git a/third_party/ots/README.chromium b/third_party/ots/README.chromium index befc3aa..ffe584d 100644 --- a/third_party/ots/README.chromium +++ b/third_party/ots/README.chromium @@ -1,9 +1,8 @@ Name: OTS URL: https://github.com/khaledhosny/ots.git -Version: 6d2e08bdc56d6739d48f5e59594669616f6b8b9d +Version: 4d011721c2eadd4e649326f8d164423db060d85e Security Critical: yes License: BSD Local Modifications: - src/woff2.cc: Changed include path to brotli/dec/decode.h. -- BUILD.gn: Added. diff --git a/third_party/ots/include/opentype-sanitiser.h b/third_party/ots/include/opentype-sanitiser.h index 285a438..1c445ae 100644 --- a/third_party/ots/include/opentype-sanitiser.h +++ b/third_party/ots/include/opentype-sanitiser.h @@ -29,9 +29,6 @@ typedef unsigned __int64 uint64_t; #include <cstddef> #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 { // ----------------------------------------------------------------------------- @@ -40,7 +37,9 @@ namespace ots { // ----------------------------------------------------------------------------- class OTSStream { public: - OTSStream() : chksum_(0) {} + OTSStream() { + ResetChecksum(); + } virtual ~OTSStream() {} @@ -52,15 +51,20 @@ class OTSStream { const size_t orig_length = length; 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; + } - size_t chksum_offset = Tell() & 3; - if (chksum_offset) { - 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); + if (chksum_buffer_offset_ == 4) { + uint32_t tmp; + std::memcpy(&tmp, chksum_buffer_, 4); chksum_ += ntohl(tmp); - length -= l; - offset += l; + chksum_buffer_offset_ = 0; } while (length >= 4) { @@ -73,11 +77,11 @@ class OTSStream { } if (length) { + if (chksum_buffer_offset_ != 0) return false; // not reached if (length > 4) return false; // not reached - uint32_t tmp = 0; - std::memcpy(&tmp, - reinterpret_cast<const uint8_t*>(data) + offset, length); - chksum_ += ntohl(tmp); + std::memcpy(chksum_buffer_, + reinterpret_cast<const uint8_t*>(data) + offset, length); + chksum_buffer_offset_ = length; } return WriteRaw(data, orig_length); @@ -138,16 +142,41 @@ class OTSStream { } void ResetChecksum() { - assert((Tell() & 3) == 0); chksum_ = 0; + chksum_buffer_offset_ = 0; } uint32_t chksum() const { + assert(chksum_buffer_offset_ == 0); 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: uint32_t chksum_; + uint8_t chksum_buffer_[4]; + unsigned chksum_buffer_offset_; }; #ifdef __GCC__ @@ -189,6 +218,9 @@ class OTSContext { 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 #endif // OPENTYPE_SANITISER_H_ diff --git a/third_party/ots/src/cmap.cc b/third_party/ots/src/cmap.cc index a238300..b1bf5fd 100644 --- a/third_party/ots/src/cmap.cc +++ b/third_party/ots/src/cmap.cc @@ -1023,6 +1023,10 @@ bool ots_cmap_serialise(OTSStream *out, OpenTypeFile *file) { } 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 if (!out->Seek(record_offset)) { @@ -1088,6 +1092,7 @@ bool ots_cmap_serialise(OTSStream *out, OpenTypeFile *file) { if (!out->Seek(table_end)) { return OTS_FAILURE(); } + out->RestoreChecksum(saved_checksum); return true; } diff --git a/third_party/ots/src/os2.cc b/third_party/ots/src/os2.cc index 3c0d1fd..915877e 100644 --- a/third_party/ots/src/os2.cc +++ b/third_party/ots/src/os2.cc @@ -2,9 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <string> - #include "os2.h" + #include "head.h" // OS/2 - OS/2 and Windows Metrics @@ -36,29 +35,26 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { !table.ReadS16(&os2->strikeout_size) || !table.ReadS16(&os2->strikeout_position) || !table.ReadS16(&os2->family_class)) { - return OTS_FAILURE_MSG("Error reading basic table elements"); + return OTS_FAILURE_MSG("Failed toi read basic os2 elements"); } - if (os2->version > 5) { - return OTS_FAILURE_MSG("Unsupported table version: %u", os2->version); + if (os2->version > 4) { + return OTS_FAILURE_MSG("os2 version too high %d", os2->version); } - // Follow WPF Font Selection Model's advice. - if (1 <= os2->weight_class && os2->weight_class <= 9) { - OTS_WARNING("Bad usWeightClass: %u, changing it to: %u", os2->weight_class, os2->weight_class * 100); - os2->weight_class *= 100; + // Some linux fonts (e.g., Kedage-t.ttf and LucidaSansDemiOblique.ttf) have + // weird weight/width classes. Overwrite them with FW_NORMAL/1/9. + if (os2->weight_class < 100 || + os2->weight_class > 900 || + 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) { - OTS_WARNING("Bad usWidthClass: %u, changing it to: %d", os2->width_class, 1); + OTS_WARNING("bad width: %u", os2->width_class); os2->width_class = 1; } else if (os2->width_class > 9) { - OTS_WARNING("Bad usWidthClass: %u, changing it to: %d", os2->width_class, 9); + OTS_WARNING("bad width: %u", os2->width_class); os2->width_class = 9; } @@ -77,34 +73,30 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { // mask reserved bits. use only 0..3, 8, 9 bits. os2->type &= 0x30f; -#define SET_TO_ZERO(a, b) \ - if (os2->b < 0) { \ - OTS_WARNING("Bad " a ": %d, setting it to zero", os2->b); \ - os2->b = 0; \ - } - - SET_TO_ZERO("ySubscriptXSize", subscript_x_size); - SET_TO_ZERO("ySubscriptYSize", subscript_y_size); - SET_TO_ZERO("ySuperscriptXSize", superscript_x_size); - SET_TO_ZERO("ySuperscriptYSize", superscript_y_size); - SET_TO_ZERO("yStrikeoutSize", strikeout_size); -#undef SET_TO_ZERO - - static std::string panose_strings[10] = { - "bFamilyType", - "bSerifStyle", - "bWeight", - "bProportion", - "bContrast", - "bStrokeVariation", - "bArmStyle", - "bLetterform", - "bMidline", - "bXHeight", - }; + if (os2->subscript_x_size < 0) { + OTS_WARNING("bad subscript_x_size: %d", os2->subscript_x_size); + os2->subscript_x_size = 0; + } + if (os2->subscript_y_size < 0) { + OTS_WARNING("bad subscript_y_size: %d", os2->subscript_y_size); + os2->subscript_y_size = 0; + } + if (os2->superscript_x_size < 0) { + OTS_WARNING("bad superscript_x_size: %d", os2->superscript_x_size); + os2->superscript_x_size = 0; + } + if (os2->superscript_y_size < 0) { + OTS_WARNING("bad superscript_y_size: %d", os2->superscript_y_size); + os2->superscript_y_size = 0; + } + if (os2->strikeout_size < 0) { + OTS_WARNING("bad strikeout_size: %d", os2->strikeout_size); + os2->strikeout_size = 0; + } + for (unsigned i = 0; i < 10; ++i) { if (!table.ReadU8(&os2->panose[i])) { - return OTS_FAILURE_MSG("Error reading PANOSE %s", panose_strings[i].c_str()); + return OTS_FAILURE_MSG("Failed to read panose in os2 table"); } } @@ -121,7 +113,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { !table.ReadS16(&os2->typo_linegap) || !table.ReadU16(&os2->win_ascent) || !table.ReadU16(&os2->win_descent)) { - return OTS_FAILURE_MSG("Error reading more basic table fields"); + return OTS_FAILURE_MSG("Failed to read more basic os2 fields"); } // If bit 6 is set, then bits 0 and 5 must be clear. @@ -132,7 +124,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 // in the 'head' table. if (!file->head) { - return OTS_FAILURE_MSG("Needed head table is missing from the font"); + return OTS_FAILURE_MSG("Head table missing from font as needed by os2 table"); } if ((os2->selection & 0x1) && !(file->head->mac_style & 0x2)) { @@ -156,7 +148,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { if ((os2->version < 4) && (os2->selection & 0x300)) { // bit 8 and 9 must be unset in OS/2 table versions less than 4. - return OTS_FAILURE_MSG("Version %d incompatible with selection %d", os2->version, os2->selection); + return OTS_FAILURE_MSG("OS2 version %d incompatible with selection %d", os2->version, os2->selection); } // mask reserved bits. use only 0..9 bits. @@ -206,7 +198,7 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { !table.ReadU16(&os2->default_char) || !table.ReadU16(&os2->break_char) || !table.ReadU16(&os2->max_context)) { - return OTS_FAILURE_MSG("Failed to read version 2-specific fields"); + return OTS_FAILURE_MSG("Failed to read os2 version 2 information"); } if (os2->x_height < 0) { @@ -218,26 +210,6 @@ bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { 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; } @@ -286,7 +258,7 @@ bool ots_os2_serialise(OTSStream *out, OpenTypeFile *file) { !out->WriteS16(os2->typo_linegap) || !out->WriteU16(os2->win_ascent) || !out->WriteU16(os2->win_descent)) { - return OTS_FAILURE_MSG("Failed to write version 1-specific fields"); + return OTS_FAILURE_MSG("Failed to write os2 version 1 information"); } if (os2->version < 1) { @@ -307,16 +279,7 @@ bool ots_os2_serialise(OTSStream *out, OpenTypeFile *file) { !out->WriteU16(os2->default_char) || !out->WriteU16(os2->break_char) || !out->WriteU16(os2->max_context)) { - 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 OTS_FAILURE_MSG("Failed to write os2 version 2 information"); } return true; diff --git a/third_party/ots/src/os2.h b/third_party/ots/src/os2.h index 01511c5..9e0fc34 100644 --- a/third_party/ots/src/os2.h +++ b/third_party/ots/src/os2.h @@ -47,8 +47,6 @@ struct OpenTypeOS2 { uint16_t default_char; uint16_t break_char; uint16_t max_context; - uint16_t lower_optical_pointsize; - uint16_t upper_optical_pointsize; }; } // namespace ots diff --git a/third_party/ots/src/ots.cc b/third_party/ots/src/ots.cc index 28d0285d..5ba8dd9 100644 --- a/third_party/ots/src/ots.cc +++ b/third_party/ots/src/ots.cc @@ -24,7 +24,6 @@ namespace { // 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_HDR(msg_) OTS_FAILURE_MSG_(header, msg_) -#define OTS_WARNING_MSG_HDR(msg_) OTS_WARNING_MSG_(header, msg_) struct OpenTypeTable { @@ -473,7 +472,7 @@ bool ProcessGeneric(ots::OpenTypeFile *header, uint32_t signature, const uint32_t this_tag = ntohl(tables[i].tag); const uint32_t prev_tag = ntohl(tables[i - 1].tag); if (this_tag <= prev_tag) { - OTS_WARNING_MSG_HDR("Table directory is not correctly ordered"); + return OTS_FAILURE_MSG_HDR("table directory not correctly ordered"); } } @@ -819,4 +818,10 @@ bool OTSContext::Process(OTSStream *output, 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 diff --git a/third_party/ots/src/woff2.cc b/third_party/ots/src/woff2.cc index 5a79598..b244aec 100644 --- a/third_party/ots/src/woff2.cc +++ b/third_party/ots/src/woff2.cc @@ -45,7 +45,7 @@ const size_t kCompositeGlyphBegin = 10; // 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 UNTAG(t) (t >> 24), (t >> 16), (t >> 8), (t >> 0) +#define CHR(t) (t >> 24), (t >> 16), (t >> 8), (t >> 0) const unsigned int kWoff2FlagsTransform = 1 << 5; @@ -772,6 +772,17 @@ bool FixChecksums(const std::vector<Table>& tables, uint8_t* dst) { 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, ots::Buffer* buffer, std::vector<Table>* tables, size_t num_tables) { @@ -801,16 +812,12 @@ bool ReadTableDirectory(ots::OpenTypeFile* file, } uint32_t dst_length; if (!ReadBase128(buffer, &dst_length)) { - return OTS_FAILURE_MSG("Failed to read 'origLength' for table '%c%c%c%c'", UNTAG(tag)); + return OTS_FAILURE_MSG("Failed to read 'origLength' for table '%c%c%c%c'", CHR(tag)); } uint32_t transform_length = dst_length; if ((flags & kWoff2FlagsTransform) != 0) { if (!ReadBase128(buffer, &transform_length)) { - 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); + return OTS_FAILURE_MSG("Failed to read 'transformLength' for table '%c%c%c%c'", CHR(tag)); } } // Disallow huge numbers (> 1GB) for sanity. @@ -1013,16 +1020,13 @@ bool ConvertWOFF2ToSFNT(ots::OpenTypeFile* file, if (total_size > 30 * 1024 * 1024) { return OTS_FAILURE(); } - size_t uncompressed_size = static_cast<size_t>(total_size); - uncompressed_buf.resize(uncompressed_size); - const uint8_t* compressed_buf = data + compressed_offset; - if (!BrotliDecompressBuffer(compressed_length, compressed_buf, - &uncompressed_size, &uncompressed_buf[0])) { + const size_t total_size_size_t = static_cast<size_t>(total_size); + uncompressed_buf.resize(total_size_size_t); + const uint8_t* src_buf = data + compressed_offset; + if (!Woff2Uncompress(&uncompressed_buf[0], total_size_size_t, + src_buf, compressed_length)) { 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]; for (uint16_t i = 0; i < num_tables; ++i) { @@ -1043,7 +1047,7 @@ bool ConvertWOFF2ToSFNT(ots::OpenTypeFile* file, } else { if (!ReconstructTransformed(file, tables, table->tag, transform_buf, transform_length, result, result_length)) { - return OTS_FAILURE_MSG("Failed to reconstruct '%c%c%c%c' table", UNTAG(table->tag)); + return OTS_FAILURE_MSG("Failed to reconstruct '%c%c%c%c' table", CHR(table->tag)); } } diff --git a/third_party/ots/test/ot-sanitise.cc b/third_party/ots/test/ot-sanitise.cc index 3204ce4..2d4526a 100644 --- a/third_party/ots/test/ot-sanitise.cc +++ b/third_party/ots/test/ot-sanitise.cc @@ -49,18 +49,18 @@ class Context: public ots::OTSContext { } virtual ots::TableAction GetTableAction(uint32_t tag) { +#define TAG(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d)) switch (tag) { - case OTS_TAG('S','i','l','f'): - case OTS_TAG('S','i','l','l'): - case OTS_TAG('G','l','o','c'): - case OTS_TAG('G','l','a','t'): - case OTS_TAG('F','e','a','t'): - case OTS_TAG('C','B','D','T'): - case OTS_TAG('C','B','L','C'): + case TAG('S','i','l','f'): + case TAG('S','i','l','l'): + case TAG('G','l','o','c'): + case TAG('G','l','a','t'): + case TAG('F','e','a','t'): return ots::TABLE_ACTION_PASSTHRU; default: return ots::TABLE_ACTION_DEFAULT; } +#undef TAG } }; diff --git a/third_party/ots/test/side-by-side.cc b/third_party/ots/test/side-by-side.cc index 8565bfe..9034a7c 100644 --- a/third_party/ots/test/side-by-side.cc +++ b/third_party/ots/test/side-by-side.cc @@ -20,7 +20,7 @@ namespace { void DumpBitmap(const FT_Bitmap *bitmap) { - for (unsigned int i = 0; i < bitmap->rows * bitmap->width; ++i) { + for (int i = 0; i < bitmap->rows * bitmap->width; ++i) { if (bitmap->buffer[i] > 192) { std::fprintf(stderr, "#"); } else if (bitmap->buffer[i] > 128) { @@ -44,7 +44,7 @@ int CompareBitmaps(const FT_Bitmap *orig, const FT_Bitmap *trans) { if (orig->width == trans->width && orig->rows == trans->rows) { - for (unsigned int i = 0; i < orig->rows * orig->width; ++i) { + for (int i = 0; i < orig->rows * orig->width; ++i) { if (orig->buffer[i] != trans->buffer[i]) { std::fprintf(stderr, "bitmap data doesn't match!\n"); ret = 1; |