Guard remaining IPDF_JSPLATFORM call-outs with in_active_ffi_callback_ Set in_active_ffi_callback_ across the remaining IPDF_JSPLATFORM call-outs in CPDFSDK_FormFillEnvironment: JS_fieldBrowse(), JS_docmailForm(), JS_docprint(), JS_docgotoPage(), GetFilePath(), and SubmitForm(). Also route CPDFXFA_DocEnvironment::Print() through CPDFSDK_FormFillEnvironment::JS_docprint() so XFA printing shares the same guard. Defense-in-depth for embedders; none of these call-out paths should be reachable for synchronous environment destruction from the Chromium embedder. Fixed: 586732845 Change-Id: I15e99ecf1ee6cf64a993e40bf0a306341f55a528 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165290 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index 124f504..4453c82 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -263,6 +263,7 @@ return WideString(); } + AutoRestorer<bool> restorer(&in_active_ffi_callback_, true); const int required_len = js_platform->Field_browse(js_platform, nullptr, 0); if (required_len <= 0) { return WideString(); @@ -300,6 +301,7 @@ ByteString bsCC = CC.ToUTF16LE(); ByteString bsBcc = BCC.ToUTF16LE(); ByteString bsMsg = Msg.ToUTF16LE(); + AutoRestorer<bool> restorer(&in_active_ffi_callback_, true); js_platform->Doc_mail(js_platform, const_cast<uint8_t*>(mailData.data()), pdfium::checked_cast<int>(mailData.size()), bUI, AsFPDFWideString(&bsTo), AsFPDFWideString(&bsSubject), @@ -320,6 +322,7 @@ return; } + AutoRestorer<bool> restorer(&in_active_ffi_callback_, true); js_platform->Doc_print(js_platform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations); } @@ -330,6 +333,7 @@ return; } + AutoRestorer<bool> restorer(&in_active_ffi_callback_, true); js_platform->Doc_gotoPage(js_platform, nPageNum); } @@ -338,12 +342,13 @@ } #endif // PDF_ENABLE_V8 -WideString CPDFSDK_FormFillEnvironment::GetFilePath() const { +WideString CPDFSDK_FormFillEnvironment::GetFilePath() { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); if (!js_platform || !js_platform->Doc_getFilePath) { return WideString(); } + AutoRestorer<bool> restorer(&in_active_ffi_callback_, true); const int required_len = js_platform->Doc_getFilePath(js_platform, nullptr, 0); if (required_len <= 0) { @@ -373,6 +378,7 @@ } ByteString bsUrl = URL.ToUTF16LE(); + AutoRestorer<bool> restorer(&in_active_ffi_callback_, true); js_platform->Doc_submitForm( js_platform, const_cast<uint8_t*>(form_data.data()), fxcrt::CollectionSize<int>(form_data), AsFPDFWideString(&bsUrl));
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h index a25cc62..02a9520 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/fpdfsdk/cpdfsdk_formfillenvironment.h
@@ -236,7 +236,7 @@ #endif // PDF_ENABLE_XFA #endif // PDF_ENABLE_V8 - WideString GetFilePath() const; + WideString GetFilePath(); ByteString GetAppName() const { return ByteString(); } void SubmitForm(pdfium::span<const uint8_t> form_data, const WideString& URL);
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 062c387..b46ade7 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -657,18 +657,13 @@ return; } - IPDF_JSPLATFORM* js_platform = pFormFillEnv->GetJSPlatform(); - if (!js_platform || !js_platform->Doc_print) { - return; - } - - js_platform->Doc_print(js_platform, !!(dwOptions & XFA_PrintOpt::kShowDialog), - nStartPage, nEndPage, - !!(dwOptions & XFA_PrintOpt::kCanCancel), - !!(dwOptions & XFA_PrintOpt::kShrinkPage), - !!(dwOptions & XFA_PrintOpt::kAsImage), - !!(dwOptions & XFA_PrintOpt::kReverseOrder), - !!(dwOptions & XFA_PrintOpt::kPrintAnnot)); + pFormFillEnv->JS_docprint(!!(dwOptions & XFA_PrintOpt::kShowDialog), + nStartPage, nEndPage, + !!(dwOptions & XFA_PrintOpt::kCanCancel), + !!(dwOptions & XFA_PrintOpt::kShrinkPage), + !!(dwOptions & XFA_PrintOpt::kAsImage), + !!(dwOptions & XFA_PrintOpt::kReverseOrder), + !!(dwOptions & XFA_PrintOpt::kPrintAnnot)); } FX_ARGB CPDFXFA_DocEnvironment::GetHighlightColor(