summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-09-12 16:19:22 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-09-12 16:19:22 +0000
commit657a1aa0700b437bd159007a97c8219c50c461a7 (patch)
tree459aa2803a2115a853c07882de2aefde0402c7b8 /fpdfsdk
parent5c86fd4c5110a99606316721786f1ba9bf0d855a (diff)
downloadpdfium-657a1aa0700b437bd159007a97c8219c50c461a7.tar.xz
Set correct stream index when parsing is done in several steps.
When parsing happens in several steps (in pages with > 100 page objects), the position is reset to 0 and the start pointer is advanced. This breaks the calculation of which stream an object belongs to. Passing in the base pointer separately from the start offset allows the correct position to be calculated and the correct stream to be identified. Change-Id: Ic0d5f59f437609158aa97b3c8a18dbd48cd3b0d4 Reviewed-on: https://pdfium-review.googlesource.com/42270 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_edit_embeddertest.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 47c8f8b394..3d10ba06d9 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -1450,6 +1450,80 @@ TEST_F(FPDFEditEmbeddertest, InsertPageObjectEditAndSave) {
CloseSavedDocument();
}
+TEST_F(FPDFEditEmbeddertest, InsertAndRemoveLargeFile) {
+ const int kOriginalObjectCount = 600;
+
+ // Load document with many objects.
+ EXPECT_TRUE(OpenDocument("many_rectangles.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+ const char kOriginalMD5[] = "b0170c575b65ecb93ebafada0ff0f038";
+ {
+ ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0);
+ CompareBitmap(page_bitmap.get(), 200, 300, kOriginalMD5);
+ }
+
+ // Add a black rectangle.
+ ASSERT_EQ(kOriginalObjectCount, FPDFPage_CountObjects(page));
+ FPDF_PAGEOBJECT black_rect = FPDFPageObj_CreateNewRect(20, 100, 50, 50);
+ EXPECT_TRUE(FPDFPath_SetFillColor(black_rect, 0, 0, 0, 255));
+ EXPECT_TRUE(FPDFPath_SetDrawMode(black_rect, FPDF_FILLMODE_ALTERNATE, 0));
+ FPDFPage_InsertObject(page, black_rect);
+
+ // Verify the black rectangle was added.
+ ASSERT_EQ(kOriginalObjectCount + 1, FPDFPage_CountObjects(page));
+ const char kPlusRectangleMD5[] = "6b9396ab570754b32b04ca629e902f77";
+ {
+ ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0);
+ CompareBitmap(page_bitmap.get(), 200, 300, kPlusRectangleMD5);
+ }
+
+ // Save the file.
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
+ UnloadPage(page);
+
+ // Re-open the file and check the rectangle added is still there.
+ OpenSavedDocument(nullptr);
+ FPDF_PAGE saved_page = LoadSavedPage(0);
+ EXPECT_EQ(kOriginalObjectCount + 1, FPDFPage_CountObjects(saved_page));
+ {
+ ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(saved_page, nullptr, 0);
+ CompareBitmap(page_bitmap.get(), 200, 300, kPlusRectangleMD5);
+ }
+
+ // Remove the added rectangle.
+ FPDF_PAGEOBJECT added_object =
+ FPDFPage_GetObject(saved_page, kOriginalObjectCount);
+ EXPECT_TRUE(FPDFPage_RemoveObject(saved_page, added_object));
+ FPDFPageObj_Destroy(added_object);
+ {
+ ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(saved_page, nullptr, 0);
+ CompareBitmap(page_bitmap.get(), 200, 300, kOriginalMD5);
+ }
+ EXPECT_EQ(kOriginalObjectCount, FPDFPage_CountObjects(saved_page));
+
+ // Save the file again.
+ EXPECT_TRUE(FPDFPage_GenerateContent(saved_page));
+ EXPECT_TRUE(FPDF_SaveAsCopy(saved_document_, this, 0));
+
+ CloseSavedPage(saved_page);
+ CloseSavedDocument();
+
+ // Re-open the file (again) and check the black rectangle was removed and the
+ // rest is intact.
+ OpenSavedDocument(nullptr);
+ saved_page = LoadSavedPage(0);
+ EXPECT_EQ(kOriginalObjectCount, FPDFPage_CountObjects(saved_page));
+ {
+ ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(saved_page, nullptr, 0);
+ CompareBitmap(page_bitmap.get(), 200, 300, kOriginalMD5);
+ }
+
+ CloseSavedPage(saved_page);
+ CloseSavedDocument();
+}
+
TEST_F(FPDFEditEmbeddertest, AddAndRemovePaths) {
// Start with a blank page.
FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);