From c8a235ba4d42b67fa1bfe5f7c0dd872a3b72fc5f Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 13 Jul 2018 18:46:21 +0000 Subject: Validate out-parameters in FPDF_GetPageSizeByIndex(). Change-Id: I2927ebdf0aff31193ad69dcd5542f3858ffdd6ee Reviewed-on: https://pdfium-review.googlesource.com/37790 Reviewed-by: Henrique Nakashima Commit-Queue: Lei Zhang --- fpdfsdk/fpdf_view.cpp | 3 +++ fpdfsdk/fpdf_view_embeddertest.cpp | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index 8aca6fb9f1..5fdc82af73 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp @@ -920,6 +920,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_index, double* width, double* height) { + if (!width || !height) + return false; + auto* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return false; diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp index 1eedda3d4b..8cea7de21c 100644 --- a/fpdfsdk/fpdf_view_embeddertest.cpp +++ b/fpdfsdk/fpdf_view_embeddertest.cpp @@ -593,11 +593,14 @@ TEST_F(FPDFViewEmbeddertest, FPDF_RenderPageBitmapWithMatrix) { TEST_F(FPDFViewEmbeddertest, FPDF_GetPageSizeByIndex) { EXPECT_TRUE(OpenDocument("rectangles.pdf")); - CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document()); double width = 0; double height = 0; + EXPECT_FALSE(FPDF_GetPageSizeByIndex(nullptr, 0, &width, &height)); + EXPECT_FALSE(FPDF_GetPageSizeByIndex(document(), 0, nullptr, &height)); + EXPECT_FALSE(FPDF_GetPageSizeByIndex(document(), 0, &width, nullptr)); + // Page -1 doesn't exist. EXPECT_FALSE(FPDF_GetPageSizeByIndex(document(), -1, &width, &height)); @@ -609,6 +612,7 @@ TEST_F(FPDFViewEmbeddertest, FPDF_GetPageSizeByIndex) { EXPECT_EQ(200.0, width); EXPECT_EQ(300.0, height); + CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document()); #ifdef PDF_ENABLE_XFA // TODO(tsepez): XFA must obtain this size without parsing. EXPECT_EQ(1u, pDoc->GetParsedPageCountForTesting()); -- cgit v1.2.3