Remove a NOTREACHED() in CPDF_Font::GetAdobeCharName().

It is reachable. Add a unit test to exercise this code path.

BUG=chromium:920636

Change-Id: I57c9102fe215ae48fc46d496bae4efc399629e0b
Reviewed-on: https://pdfium-review.googlesource.com/c/48134
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/BUILD.gn b/core/fpdfapi/font/BUILD.gn
index 5a025c1..1e8c76e 100644
--- a/core/fpdfapi/font/BUILD.gn
+++ b/core/fpdfapi/font/BUILD.gn
@@ -58,12 +58,15 @@
 
 pdfium_unittest_source_set("unittests") {
   sources = [
+    "cpdf_cidfont_unittest.cpp",
     "cpdf_cmapparser_unittest.cpp",
     "cpdf_fontencoding_unittest.cpp",
     "cpdf_tounicodemap_unittest.cpp",
   ]
   deps = [
     ":font",
+    "../../fpdfapi",
+    "../parser",
   ]
   pdfium_root_dir = "../../../"
 }
diff --git a/core/fpdfapi/font/cpdf_cidfont_unittest.cpp b/core/fpdfapi/font/cpdf_cidfont_unittest.cpp
new file mode 100644
index 0000000..2e40357
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_cidfont_unittest.cpp
@@ -0,0 +1,56 @@
+// Copyright 2019 PDFium 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 "core/fpdfapi/font/cpdf_cidfont.h"
+
+#include <utility>
+
+#include "core/fpdfapi/cpdf_modulemgr.h"
+#include "core/fpdfapi/parser/cpdf_array.h"
+#include "core/fpdfapi/parser/cpdf_dictionary.h"
+#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_name.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class CPDF_CIDFontTest : public testing::Test {
+ protected:
+  void SetUp() override { CPDF_ModuleMgr::Get()->Init(); }
+
+  void TearDown() override { CPDF_ModuleMgr::Destroy(); }
+};
+
+TEST_F(CPDF_CIDFontTest, BUG_920636) {
+  CPDF_Document doc;
+  CPDF_Dictionary font_dict;
+  font_dict.SetNewFor<CPDF_Name>("Encoding", "Identity−H");
+
+  {
+    auto descendant_fonts = pdfium::MakeUnique<CPDF_Array>();
+    {
+      auto descendant_font = pdfium::MakeUnique<CPDF_Dictionary>();
+      descendant_font->SetNewFor<CPDF_Name>("BaseFont", "CourierStd");
+      descendant_fonts->Add(std::move(descendant_font));
+    }
+    font_dict.SetFor("DescendantFonts", std::move(descendant_fonts));
+  }
+
+  CPDF_CIDFont font(&doc, &font_dict);
+  ASSERT_TRUE(font.Load());
+
+  // It would be nice if we can test more values here. However, the glyph
+  // indices are sometimes machine dependent.
+  struct {
+    uint32_t charcode;
+    int glyph;
+  } static constexpr kTestCases[] = {
+      {0, 31},
+      {256, 287},
+      {34661, 34692},
+  };
+
+  for (const auto& test_case : kTestCases) {
+    EXPECT_EQ(test_case.glyph,
+              font.GlyphFromCharCode(test_case.charcode, nullptr));
+  }
+}
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index b07208c..a5727d7 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -349,10 +349,8 @@
     int iBaseEncoding,
     const std::vector<ByteString>& charnames,
     int charcode) {
-  if (charcode < 0 || charcode >= 256) {
-    NOTREACHED();
+  if (charcode < 0 || charcode >= 256)
     return nullptr;
-  }
 
   if (!charnames.empty() && !charnames[charcode].IsEmpty())
     return charnames[charcode].c_str();