summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-11 17:55:40 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-11 17:55:40 -0800
commit6e1d6032b7990cdf580c99ff491a1b761ee39ca6 (patch)
treec880c69a8ef1372511a0fecac0bf3d61b1eabe75 /fpdfsdk
parent211d4edbe2f71ca62c76f36ce25090342c58e43c (diff)
downloadpdfium-6e1d6032b7990cdf580c99ff491a1b761ee39ca6.tar.xz
Fix unique ptrs in fpdfppo.cpp
There's a path out that deletes a pointer whose ownership was passed off earlier. This will get simpler once more APIs take unique_ptr. BUG=664284 Review-Url: https://codereview.chromium.org/2495003006
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdfppo.cpp6
-rw-r--r--fpdfsdk/fpdfppo_embeddertest.cpp14
-rw-r--r--fpdfsdk/fpdfsave_embeddertest.cpp20
3 files changed, 36 insertions, 4 deletions
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp
index f8b96de1f3..786bc46611 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -285,12 +285,12 @@ uint32_t CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc,
return 0;
}
}
- dwNewObjNum = pDoc->AddIndirectObject(pClone.get());
+ CPDF_Object* pUnownedClone = pClone.get();
+ dwNewObjNum = pDoc->AddIndirectObject(pClone.release());
(*pObjNumberMap)[dwObjnum] = dwNewObjNum;
- if (!UpdateReference(pClone.get(), pDoc, pObjNumberMap))
+ if (!UpdateReference(pUnownedClone, pDoc, pObjNumberMap))
return 0;
- pClone.release(); // TODO(tsepez): figure out ownership.
return dwNewObjNum;
}
diff --git a/fpdfsdk/fpdfppo_embeddertest.cpp b/fpdfsdk/fpdfppo_embeddertest.cpp
index 3149f072f5..0972316534 100644
--- a/fpdfsdk/fpdfppo_embeddertest.cpp
+++ b/fpdfsdk/fpdfppo_embeddertest.cpp
@@ -90,3 +90,17 @@ TEST_F(FPDFPPOEmbeddertest, GoodRanges) {
UnloadPage(page);
}
+
+TEST_F(FPDFPPOEmbeddertest, BUG_664284) {
+ EXPECT_TRUE(OpenDocument("bug_664284.pdf"));
+
+ FPDF_PAGE page = LoadPage(0);
+ EXPECT_TRUE(page);
+
+ FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument();
+ EXPECT_TRUE(output_doc);
+ EXPECT_TRUE(FPDF_ImportPages(output_doc, document(), "1", 0));
+ FPDF_CloseDocument(output_doc);
+
+ UnloadPage(page);
+}
diff --git a/fpdfsdk/fpdfsave_embeddertest.cpp b/fpdfsdk/fpdfsave_embeddertest.cpp
index 55a58c2de3..918727027f 100644
--- a/fpdfsdk/fpdfsave_embeddertest.cpp
+++ b/fpdfsdk/fpdfsave_embeddertest.cpp
@@ -2,10 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "public/fpdf_save.h"
+
#include <string.h>
#include "core/fxcrt/fx_string.h"
-#include "public/fpdf_save.h"
+#include "public/fpdf_edit.h"
+#include "public/fpdf_ppo.h"
#include "public/fpdfview.h"
#include "testing/embedder_test.h"
#include "testing/fx_string_testhelpers.h"
@@ -43,6 +46,21 @@ TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) {
EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
}
+TEST_F(FPDFSaveEmbedderTest, SaveCopiedDoc) {
+ EXPECT_TRUE(OpenDocument("hello_world.pdf"));
+
+ FPDF_PAGE page = LoadPage(0);
+ EXPECT_TRUE(page);
+
+ FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument();
+ EXPECT_TRUE(output_doc);
+ EXPECT_TRUE(FPDF_ImportPages(output_doc, document(), "1", 0));
+ EXPECT_TRUE(FPDF_SaveAsCopy(output_doc, this, 0));
+ FPDF_CloseDocument(output_doc);
+
+ UnloadPage(page);
+}
+
TEST_F(FPDFSaveEmbedderTest, BUG_342) {
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));