diff options
author | arthurhsu <arthurhsu@google.com> | 2012-07-09 18:35:41 +0000 |
---|---|---|
committer | arthurhsu <arthurhsu@google.com> | 2012-07-09 18:35:41 +0000 |
commit | 527079d528241244db13664597d53e445913ced5 (patch) | |
tree | 5c2082f53245ab8eb84d9ab65e84f6fff23cabca /cpp | |
parent | 3835848ea07870392854d8ae9dacda1c662ee5f1 (diff) | |
download | sfntly-527079d528241244db13664597d53e445913ced5.tar.gz |
Gracefully fail when TTF name table contains a zero-length name.
Backport from b/6733065.
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/sample/chromium/subsetter_impl.cc | 5 | ||||
-rw-r--r-- | cpp/src/sfntly/table/core/name_table.cc | 6 |
2 files changed, 8 insertions, 3 deletions
diff --git a/cpp/src/sample/chromium/subsetter_impl.cc b/cpp/src/sample/chromium/subsetter_impl.cc index 3708f44..528e336 100644 --- a/cpp/src/sample/chromium/subsetter_impl.cc +++ b/cpp/src/sample/chromium/subsetter_impl.cc @@ -112,11 +112,14 @@ bool HasName(const char* font_name, Font* font) { case NameId::kPreferredSubfamily: case NameId::kWWSFamilyName: case NameId::kWWSSubfamilyName: { + UChar* name_part = name_table->Name(i); + if (name_part == NULL) { + continue; + } int32_t hash_code = HashCode(name_table->PlatformId(i), name_table->EncodingId(i), name_table->LanguageId(i), name_table->NameId(i)); - UChar* name_part = name_table->Name(i); ConstructName(name_part, &(names[hash_code]), name_table->NameId(i)); delete[] name_part; break; diff --git a/cpp/src/sfntly/table/core/name_table.cc b/cpp/src/sfntly/table/core/name_table.cc index 5f6d5a5..8d2f64f 100644 --- a/cpp/src/sfntly/table/core/name_table.cc +++ b/cpp/src/sfntly/table/core/name_table.cc @@ -472,7 +472,9 @@ void NameTable::NameAsBytes(int32_t index, ByteVector* b) { int32_t length = NameLength(index); b->clear(); b->resize(length); - data_->ReadBytes(NameOffset(index), &((*b)[0]), 0, length); + if (length > 0) { + data_->ReadBytes(NameOffset(index), &((*b)[0]), 0, length); + } } void NameTable::NameAsBytes(int32_t platform_id, @@ -674,7 +676,7 @@ void NameTable::ConvertToNameBytes(const UChar* name, UChar* NameTable::ConvertFromNameBytes(ByteVector* name_bytes, int32_t platform_id, int32_t encoding_id) { - if (name_bytes == NULL) { + if (name_bytes == NULL || name_bytes->size() == 0) { return NULL; } UConverter* cs = GetCharset(platform_id, encoding_id); |