Improve error handling in CPDF_CIDFont::GetGlyphIndex()

- Avoid potentially allocating size 0.
- Return earlier on error.

Change-Id: I22735bd02d270653d610acbc97451551d466dc33
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/107391
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 6e0e665..d7634df 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -663,13 +663,17 @@
   if (!m_Font.GetSubData()) {
     unsigned long length = 0;
     int error = FT_Load_Sfnt_Table(face, kGsubTag, 0, nullptr, &length);
-    if (!error)
-      m_Font.AllocSubData(length);
+    if (error || !length) {
+      return index;
+    }
+
+    m_Font.AllocSubData(length);
   }
   int error =
       FT_Load_Sfnt_Table(face, kGsubTag, 0, m_Font.GetSubData(), nullptr);
-  if (error || !m_Font.GetSubData())
+  if (error) {
     return index;
+  }
 
   m_pTTGSUBTable = std::make_unique<CFX_CTTGSUBTable>(m_Font.GetSubData());
   return GetVerticalGlyph(index, pVertGlyph);