Gracefully fail when TTF name table contains a zero-length name.

Backport from b/6733065.

git-svn-id: http://sfntly.googlecode.com/svn/trunk/cpp/src@134 672e30a5-4c29-85ac-ac6d-611c735e0a51
diff --git a/sample/chromium/subsetter_impl.cc b/sample/chromium/subsetter_impl.cc
index 3708f44..528e336 100644
--- a/sample/chromium/subsetter_impl.cc
+++ b/sample/chromium/subsetter_impl.cc
@@ -112,11 +112,14 @@
       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/sfntly/table/core/name_table.cc b/sfntly/table/core/name_table.cc
index 5f6d5a5..8d2f64f 100644
--- a/sfntly/table/core/name_table.cc
+++ b/sfntly/table/core/name_table.cc
@@ -472,7 +472,9 @@
   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 @@
 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);