Ignore attempts to set document properties via JS.
Various document properties are specified as read-only (always, or in
Acrobat Reader) in the spec. Match the Acrobat Reader behavior and
ignore calls to set them.
Bug: pdfium:1820
Change-Id: I131fc715a7a1b692dbce0c1c6fbfdd9a4f614dae
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/93253
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index a0bcf86..83e61eb 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -654,7 +654,8 @@
CJS_Result CJS_Document::set_author(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp) {
- return setPropertyInternal(pRuntime, vp, "Author");
+ // Read-only.
+ return CJS_Result::Success();
}
CJS_Result CJS_Document::get_info(CJS_Runtime* pRuntime) {
@@ -734,33 +735,14 @@
pDictionary->GetUnicodeTextFor(propName).AsStringView()));
}
-CJS_Result CJS_Document::setPropertyInternal(CJS_Runtime* pRuntime,
- v8::Local<v8::Value> vp,
- const ByteString& propName) {
- if (!m_pFormFillEnv)
- return CJS_Result::Failure(JSMessage::kBadObjectError);
-
- CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo();
- if (!pDictionary)
- return CJS_Result::Failure(JSMessage::kBadObjectError);
-
- using pdfium::access_permissions::kModifyContent;
- if (!m_pFormFillEnv->HasPermissions(kModifyContent))
- return CJS_Result::Failure(JSMessage::kPermissionError);
-
- pDictionary->SetNewFor<CPDF_String>(
- propName, pRuntime->ToWideString(vp).AsStringView());
- m_pFormFillEnv->SetChangeMark();
- return CJS_Result::Success();
-}
-
CJS_Result CJS_Document::get_creation_date(CJS_Runtime* pRuntime) {
return getPropertyInternal(pRuntime, "CreationDate");
}
CJS_Result CJS_Document::set_creation_date(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp) {
- return setPropertyInternal(pRuntime, vp, "CreationDate");
+ // Read-only.
+ return CJS_Result::Success();
}
CJS_Result CJS_Document::get_creator(CJS_Runtime* pRuntime) {
@@ -769,7 +751,8 @@
CJS_Result CJS_Document::set_creator(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp) {
- return setPropertyInternal(pRuntime, vp, "Creator");
+ // Read-only.
+ return CJS_Result::Success();
}
CJS_Result CJS_Document::get_delay(CJS_Runtime* pRuntime) {
@@ -807,7 +790,8 @@
CJS_Result CJS_Document::set_keywords(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp) {
- return setPropertyInternal(pRuntime, vp, "Keywords");
+ // Read-only.
+ return CJS_Result::Success();
}
CJS_Result CJS_Document::get_mod_date(CJS_Runtime* pRuntime) {
@@ -816,7 +800,8 @@
CJS_Result CJS_Document::set_mod_date(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp) {
- return setPropertyInternal(pRuntime, vp, "ModDate");
+ // Read-only.
+ return CJS_Result::Success();
}
CJS_Result CJS_Document::get_producer(CJS_Runtime* pRuntime) {
@@ -825,7 +810,8 @@
CJS_Result CJS_Document::set_producer(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp) {
- return setPropertyInternal(pRuntime, vp, "Producer");
+ // Read-only.
+ return CJS_Result::Success();
}
CJS_Result CJS_Document::get_subject(CJS_Runtime* pRuntime) {
@@ -834,7 +820,8 @@
CJS_Result CJS_Document::set_subject(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp) {
- return setPropertyInternal(pRuntime, vp, "Subject");
+ // Read-only.
+ return CJS_Result::Success();
}
CJS_Result CJS_Document::get_title(CJS_Runtime* pRuntime) {
@@ -845,9 +832,8 @@
CJS_Result CJS_Document::set_title(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp) {
- if (!m_pFormFillEnv)
- return CJS_Result::Failure(JSMessage::kBadObjectError);
- return setPropertyInternal(pRuntime, vp, "Title");
+ // Read-only.
+ return CJS_Result::Success();
}
CJS_Result CJS_Document::get_num_pages(CJS_Runtime* pRuntime) {
diff --git a/fxjs/cjs_document.h b/fxjs/cjs_document.h
index 860c5e9..789aa83 100644
--- a/fxjs/cjs_document.h
+++ b/fxjs/cjs_document.h
@@ -302,9 +302,6 @@
CJS_Result getPropertyInternal(CJS_Runtime* pRuntime,
const ByteString& propName);
- CJS_Result setPropertyInternal(CJS_Runtime* pRuntime,
- v8::Local<v8::Value> vp,
- const ByteString& propName);
CPDF_InteractiveForm* GetCoreInteractiveForm();
CPDFSDK_InteractiveForm* GetSDKInteractiveForm();
diff --git a/testing/resources/javascript/document_properties_expected.txt b/testing/resources/javascript/document_properties_expected.txt
index 5bab82f..ba89da0 100644
--- a/testing/resources/javascript/document_properties_expected.txt
+++ b/testing/resources/javascript/document_properties_expected.txt
@@ -237,13 +237,13 @@
Alert: this.zoomType = 3; yields 3
Alert: *** Getting properties ***
Alert: this.ADBE is undefined undefined
-Alert: this.author is string 3
+Alert: this.author is string Joe Random Author
Alert: this.baseURL is string 3
Alert: this.bookmarkRoot is undefined undefined
Alert: this.calculate is boolean true
Alert: this.Collab is undefined undefined
-Alert: this.creationDate is string 3
-Alert: this.creator is string 3
+Alert: this.creationDate is string
+Alert: this.creator is string Joe Random Creator
Alert: this.delay is boolean true
Alert: this.dirty is boolean true
Alert: this.documentFileName is string
@@ -251,10 +251,10 @@
Alert: this.filesize is number 0
Alert: this.icons is undefined undefined
Alert: this.info is object [object Object]
-Alert: this.keywords is string 3
+Alert: this.keywords is string
Alert: this.layout is undefined undefined
Alert: this.media is undefined undefined
-Alert: this.modDate is string 3
+Alert: this.modDate is string
Alert: this.mouseX is undefined undefined
Alert: this.mouseY is undefined undefined
Alert: this.numFields is number 0
@@ -262,9 +262,9 @@
Alert: this.pageNum is undefined undefined
Alert: this.pageWindowRect is undefined undefined
Alert: this.path is string /myfile.pdf
-Alert: this.producer is string 3
-Alert: this.subject is string 3
-Alert: this.title is string 3
+Alert: this.producer is string
+Alert: this.subject is string
+Alert: this.title is string
Alert: this.URL is string myfile.pdf
Alert: this.zoom is undefined undefined
Alert: this.zoomType is undefined undefined