diff options
author | Jane Liu <janeliulwq@google.com> | 2017-06-07 11:31:27 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-07 16:02:17 +0000 |
commit | eda6525eaef97a354e52dbe2e7f454129325d36b (patch) | |
tree | c7cde6f6f517b400ef5ad278da61673dbe8e7fe2 | |
parent | 20eafda108cf9b0ab336fb8ab5d83a011f7b8307 (diff) | |
download | pdfium-eda6525eaef97a354e52dbe2e7f454129325d36b.tar.xz |
Fixing FPDFPage_TransformAnnots
Came across this error in FPDFPage_TransformAnnots, where SetNewAt()
would fail on a bound assertion when a newly created array calls it.
This CL contains a fix in the function and adds an embedder test for
this.
Bug=pdfium:745
Change-Id: I569f225598d956d270ef8f11ee3225acf48aadc7
Reviewed-on: https://pdfium-review.googlesource.com/6353
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Jane Liu <janeliulwq@google.com>
-rw-r--r-- | fpdfsdk/fpdfannot_embeddertest.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/fpdfedit_embeddertest.cpp | 18 | ||||
-rw-r--r-- | fpdfsdk/fpdfeditpage.cpp | 12 |
3 files changed, 26 insertions, 6 deletions
diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp index 1f56d22c28..e1da7cc2cd 100644 --- a/fpdfsdk/fpdfannot_embeddertest.cpp +++ b/fpdfsdk/fpdfannot_embeddertest.cpp @@ -153,7 +153,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { ASSERT_TRUE(page); EXPECT_EQ(0, FPDFPage_GetAnnotCount(page)); - // Add an underline annotation to the page. + // Add a text annotation to the page. FPDF_ANNOTATION annot; ASSERT_TRUE(FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT, &annot)); diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index 25377fe6f8..40081e6d75 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -15,6 +15,7 @@ #include "core/fxcrt/fx_system.h" #include "fpdfsdk/fsdk_define.h" #include "public/cpp/fpdf_deleters.h" +#include "public/fpdf_annot.h" #include "public/fpdf_edit.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" @@ -838,6 +839,23 @@ TEST_F(FPDFEditEmbeddertest, AddTrueTypeFontText) { FPDF_CloseDocument(new_doc); } +TEST_F(FPDFEditEmbeddertest, TransformAnnot) { + // Open a file with one annotation and load its first page. + ASSERT_TRUE(OpenDocument("annotation_highlight_long_content.pdf")); + FPDF_PAGE page = FPDF_LoadPage(document(), 0); + ASSERT_TRUE(page); + + // Add an underline annotation to the page without specifying its rectangle. + FPDF_ANNOTATION annot; + ASSERT_TRUE(FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE, &annot)); + + // FPDFPage_TransformAnnots() should run without errors when modifying + // annotation rectangles. + FPDFPage_TransformAnnots(page, 1, 2, 3, 4, 5, 6); + + UnloadPage(page); +} + // TODO(npm): Add tests using Japanese fonts in other OS. #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ TEST_F(FPDFEditEmbeddertest, AddCIDFontText) { diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index da156cd790..22b2261c6f 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -298,13 +298,15 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page, matrix.TransformRect(rect); CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect"); - if (!pRectArray) + if (pRectArray) + pRectArray->RemoveAt(0, pRectArray->GetCount()); + else pRectArray = pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("Rect"); - pRectArray->SetNewAt<CPDF_Number>(0, rect.left); - pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom); - pRectArray->SetNewAt<CPDF_Number>(2, rect.right); - pRectArray->SetNewAt<CPDF_Number>(3, rect.top); + pRectArray->AddNew<CPDF_Number>(rect.left); + pRectArray->AddNew<CPDF_Number>(rect.bottom); + pRectArray->AddNew<CPDF_Number>(rect.right); + pRectArray->AddNew<CPDF_Number>(rect.top); // TODO(unknown): Transform AP's rectangle } |