Fix a FPDF_GetMetaText() crash.
With a newly created document, there is no parser. CPDF_Document is
missing a nullptr check which can be triggered via FPDF_GetMetaText().
BUG=pdfium:915
Change-Id: If9a300a6dc2ca5914c3544eae5c27fe3139dd821
Reviewed-on: https://pdfium-review.googlesource.com/16490
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 6a8ddd1..565886a 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -377,6 +377,9 @@
}
void CPDF_Document::LoadDocumentInfo() {
+ if (!m_pParser)
+ return;
+
CPDF_Object* pInfoObj = GetOrParseIndirectObject(m_pParser->GetInfoObjNum());
if (pInfoObj)
m_pInfoDict = pInfoObj->GetDict();
diff --git a/fpdfsdk/fpdfdoc_embeddertest.cpp b/fpdfsdk/fpdfdoc_embeddertest.cpp
index 19147d4..c691a17 100644
--- a/fpdfsdk/fpdfdoc_embeddertest.cpp
+++ b/fpdfsdk/fpdfdoc_embeddertest.cpp
@@ -237,6 +237,13 @@
WideString::FromUTF16LE(buf, FXSYS_len(kExpectedModDate)));
}
+TEST_F(FPDFDocEmbeddertest, GetMetaTextFromNewDocument) {
+ FPDF_DOCUMENT empty_doc = FPDF_CreateNewDocument();
+ unsigned short buf[128];
+ EXPECT_EQ(2u, FPDF_GetMetaText(empty_doc, "Title", buf, sizeof(buf)));
+ FPDF_CloseDocument(empty_doc);
+}
+
TEST_F(FPDFDocEmbeddertest, NoPageLabels) {
EXPECT_TRUE(OpenDocument("about_blank.pdf"));
EXPECT_EQ(1, FPDF_GetPageCount(document()));