From 3f3c39d04fd68d8ce11f52baa3acae8e0522a2c4 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 1 May 2018 17:46:34 +0000 Subject: Check for NULL XFA context even when XFA Use strict typing for FPDF_Page to ensure we don't fall into code that expects the other page type when continuing from null context case. Change-Id: I7f028ef3e3d733f5557620030a87e22997da00d5 Reviewed-on: https://pdfium-review.googlesource.com/31770 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- fpdfsdk/fpdf_editpage.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'fpdfsdk/fpdf_editpage.cpp') diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp index 3acbe76d10..19a61bcdc6 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp @@ -156,14 +156,17 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_Delete(FPDF_DOCUMENT document, auto* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return; + #ifdef PDF_ENABLE_XFA CPDFXFA_Context* pContext = static_cast(pDoc->GetExtension()); - if (pContext) + if (pContext) { pContext->DeletePage(page_index); -#else + return; + } +#endif // PDF_ENABLE_XFA + pDoc->DeletePage(page_index); -#endif } FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDFPage_New(FPDF_DOCUMENT document, @@ -184,14 +187,18 @@ FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDFPage_New(FPDF_DOCUMENT document, pPageDict->SetNewFor("Resources"); #ifdef PDF_ENABLE_XFA - auto pXFAPage = pdfium::MakeRetain( - static_cast(pDoc->GetExtension()), page_index); - pXFAPage->LoadPDFPage(pPageDict); - return pXFAPage.Leak(); // Caller takes ownership. + auto* pContext = static_cast(pDoc->GetExtension()); + if (pContext) { + auto pXFAPage = pdfium::MakeRetain(pContext, page_index); + pXFAPage->LoadPDFPage(pPageDict); + return FPDFPageFromUnderlying(pXFAPage.Leak()); // Caller takes ownership. + } + // Eventually, fallthru into non-XFA case once page type is consistent. + return nullptr; #else // PDF_ENABLE_XFA auto pPage = pdfium::MakeUnique(pDoc, pPageDict, true); pPage->ParseContent(); - return pPage.release(); // Caller takes ownership. + return FPDFPageFromUnderlying(pPage.release()); // Caller takes ownership. #endif // PDF_ENABLE_XFA } -- cgit v1.2.3