summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_doc.cpp14
-rw-r--r--fpdfsdk/fpdf_doc_embeddertest.cpp24
2 files changed, 31 insertions, 7 deletions
diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp
index 614462fa47..28c670c5dd 100644
--- a/fpdfsdk/fpdf_doc.cpp
+++ b/fpdfsdk/fpdf_doc.cpp
@@ -164,11 +164,14 @@ FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAction_GetType(FPDF_ACTION pDict) {
FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFAction_GetDest(FPDF_DOCUMENT document,
FPDF_ACTION pDict) {
- if (!pDict)
- return nullptr;
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return nullptr;
+
+ unsigned long type = FPDFAction_GetType(pDict);
+ if (type != PDFACTION_GOTO && type != PDFACTION_REMOTEGOTO)
+ return nullptr;
+
CPDF_Action action(CPDFDictionaryFromFPDFAction(pDict));
return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetArray());
}
@@ -192,11 +195,14 @@ FPDFAction_GetURIPath(FPDF_DOCUMENT document,
FPDF_ACTION pDict,
void* buffer,
unsigned long buflen) {
- if (!pDict)
- return 0;
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return 0;
+
+ unsigned long type = FPDFAction_GetType(pDict);
+ if (type != PDFACTION_URI)
+ return 0;
+
CPDF_Action action(CPDFDictionaryFromFPDFAction(pDict));
ByteString path = action.GetURI(pDoc);
unsigned long len = path.GetLength() + 1;
diff --git a/fpdfsdk/fpdf_doc_embeddertest.cpp b/fpdfsdk/fpdf_doc_embeddertest.cpp
index 3d582bcca0..91a2333241 100644
--- a/fpdfsdk/fpdf_doc_embeddertest.cpp
+++ b/fpdfsdk/fpdf_doc_embeddertest.cpp
@@ -225,7 +225,19 @@ TEST_F(FPDFDocEmbeddertest, BUG_821454) {
UnloadPage(page);
}
-TEST_F(FPDFDocEmbeddertest, ActionGetFilePath) {
+TEST_F(FPDFDocEmbeddertest, ActionBadArguments) {
+ EXPECT_TRUE(OpenDocument("launch_action.pdf"));
+ EXPECT_EQ(static_cast<unsigned long>(PDFACTION_UNSUPPORTED),
+ FPDFAction_GetType(nullptr));
+
+ EXPECT_EQ(nullptr, FPDFAction_GetDest(nullptr, nullptr));
+ EXPECT_EQ(nullptr, FPDFAction_GetDest(document(), nullptr));
+ EXPECT_EQ(0u, FPDFAction_GetFilePath(nullptr, nullptr, 0));
+ EXPECT_EQ(0u, FPDFAction_GetURIPath(nullptr, nullptr, nullptr, 0));
+ EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), nullptr, nullptr, 0));
+}
+
+TEST_F(FPDFDocEmbeddertest, ActionLaunch) {
EXPECT_TRUE(OpenDocument("launch_action.pdf"));
FPDF_PAGE page = LoadPage(0);
@@ -237,15 +249,21 @@ TEST_F(FPDFDocEmbeddertest, ActionGetFilePath) {
FPDF_ACTION action = FPDFLink_GetAction(link);
ASSERT_TRUE(action);
+ EXPECT_EQ(static_cast<unsigned long>(PDFACTION_LAUNCH),
+ FPDFAction_GetType(action));
const char kExpectedResult[] = "test.pdf";
const unsigned long kExpectedLength = sizeof(kExpectedResult);
unsigned long bufsize = FPDFAction_GetFilePath(action, nullptr, 0);
- ASSERT_EQ(kExpectedLength, bufsize);
+ EXPECT_EQ(kExpectedLength, bufsize);
char buf[kExpectedLength];
EXPECT_EQ(bufsize, FPDFAction_GetFilePath(action, buf, bufsize));
- EXPECT_EQ(std::string(kExpectedResult), std::string(buf));
+ EXPECT_STREQ(kExpectedResult, buf);
+
+ // Other public methods are not appropriate for this action type.
+ EXPECT_EQ(nullptr, FPDFAction_GetDest(document(), action));
+ EXPECT_EQ(0u, FPDFAction_GetURIPath(document(), action, buf, bufsize));
UnloadPage(page);
}