Fix regression in FPDF_CountNamedDests().

The function did not have enough test coverage, and
https://pdfium-review.googlesource.com/68251 caused
FPDF_CountNamedDests() to return early instead of continuing and
counting the "old style" dests.

Change-Id: Ifeaca253fb8d2ab45236ee28825624ec691119a8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/68331
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index d7b808a..1344265 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -996,18 +996,12 @@
     return 0;
 
   auto name_tree = CPDF_NameTree::Create(pDoc, "Dests");
-  if (!name_tree)
-    return 0;
-
-  pdfium::base::CheckedNumeric<FPDF_DWORD> count = name_tree->GetCount();
+  pdfium::base::CheckedNumeric<FPDF_DWORD> count =
+      name_tree ? name_tree->GetCount() : 0;
   const CPDF_Dictionary* pDest = pRoot->GetDictFor("Dests");
   if (pDest)
     count += pDest->size();
-
-  if (!count.IsValid())
-    return 0;
-
-  return count.ValueOrDie();
+  return count.ValueOrDefault(0);
 }
 
 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV
diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp
index e5701a3..2185e71 100644
--- a/fpdfsdk/fpdf_view_embeddertest.cpp
+++ b/fpdfsdk/fpdf_view_embeddertest.cpp
@@ -669,7 +669,7 @@
 
 TEST_F(FPDFViewEmbedderTest, NamedDestsOldStyle) {
   EXPECT_TRUE(OpenDocument("named_dests_old_style.pdf"));
-  EXPECT_EQ(0u, FPDF_CountNamedDests(document()));
+  EXPECT_EQ(2u, FPDF_CountNamedDests(document()));
 }
 
 // The following tests pass if the document opens without crashing.