diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-10-09 21:02:15 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-09 21:02:15 +0000 |
commit | 8c62883bdb9d695069a483133ddc96d5b85ec472 (patch) | |
tree | ab72aee5c8ca38d60b1a3085290669c5d66828d5 | |
parent | 6ab93f59c336942ffd6cffc05a179aa0c6b2c8f1 (diff) | |
download | pdfium-8c62883bdb9d695069a483133ddc96d5b85ec472.tar.xz |
Cover some more NULL-arg FPDFBookmark_* test cases
Change-Id: I0a3db5368852eeed68bac317f8adaac4f54d023b
Reviewed-on: https://pdfium-review.googlesource.com/c/43751
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | fpdfsdk/fpdf_doc.cpp | 19 | ||||
-rw-r--r-- | fpdfsdk/fpdf_doc_embeddertest.cpp | 10 |
2 files changed, 21 insertions, 8 deletions
diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp index e7b9042479..e79c36e3e0 100644 --- a/fpdfsdk/fpdf_doc.cpp +++ b/fpdfsdk/fpdf_doc.cpp @@ -72,13 +72,13 @@ FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { - if (!pDict) - return nullptr; - CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return nullptr; + if (!pDict) + return nullptr; + CPDF_BookmarkTree tree(pDoc); CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict)); return FPDFBookmarkFromCPDFDictionary( @@ -96,11 +96,13 @@ FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, void* buffer, unsigned long buflen) { FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title) { - if (!title || title[0] == 0) - return nullptr; CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return nullptr; + + if (!title || title[0] == 0) + return nullptr; + CPDF_BookmarkTree tree(pDoc); size_t len = WideString::WStringLength(title); WideString encodedTitle = WideString::FromUTF16LE(title, len); @@ -111,11 +113,13 @@ FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title) { FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { - if (!pDict) - return nullptr; CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return nullptr; + + if (!pDict) + return nullptr; + CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict)); CPDF_Dest dest = bookmark.GetDest(pDoc); if (dest.GetArray()) @@ -132,6 +136,7 @@ FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) { if (!pDict) return nullptr; + CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict)); return FPDFActionFromCPDFDictionary(bookmark.GetAction().GetDict()); } diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp index 3ba86006d0..dc367d8e26 100644 --- a/fpdfsdk/fpdf_doc_embeddertest.cpp +++ b/fpdfsdk/fpdf_doc_embeddertest.cpp @@ -247,8 +247,16 @@ TEST_F(FPDFDocEmbeddertest, NoBookmarks) { unsigned short buf[128]; EXPECT_EQ(0u, FPDFBookmark_GetTitle(nullptr, buf, sizeof(buf))); - // The non-existent top-level bookmark has no children. + // NULL argument cases. + EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(nullptr, nullptr)); EXPECT_EQ(nullptr, FPDFBookmark_GetFirstChild(document(), nullptr)); + EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(nullptr, nullptr)); + EXPECT_EQ(nullptr, FPDFBookmark_GetNextSibling(document(), nullptr)); + EXPECT_EQ(nullptr, FPDFBookmark_Find(nullptr, nullptr)); + EXPECT_EQ(nullptr, FPDFBookmark_Find(document(), nullptr)); + EXPECT_EQ(nullptr, FPDFBookmark_GetDest(nullptr, nullptr)); + EXPECT_EQ(nullptr, FPDFBookmark_GetDest(document(), nullptr)); + EXPECT_EQ(nullptr, FPDFBookmark_GetAction(nullptr)); } TEST_F(FPDFDocEmbeddertest, Bookmarks) { |