blob: f03f2b1d6e55f00435f13fbceac3d2493afad1c6 [file] [log] [blame]
Dan Sinclair7aba4722018-03-28 17:04:16 +00001// Copyright 2018 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclair00d47a62018-03-28 18:39:04 +00007#include "fpdfsdk/cpdfsdk_helpers.h"
Dan Sinclair7aba4722018-03-28 17:04:16 +00008
Lei Zhangbc106482019-05-30 23:55:19 +00009#include "build/build_config.h"
Lei Zhang865ffb12019-02-26 20:18:19 +000010#include "constants/form_fields.h"
Lei Zhang26170562018-04-17 17:01:52 +000011#include "constants/stream_dict_common.h"
Tom Sepeza1d34422018-04-24 20:54:41 +000012#include "core/fpdfapi/page/cpdf_page.h"
Dan Sinclair7aba4722018-03-28 17:04:16 +000013#include "core/fpdfapi/parser/cpdf_array.h"
Lei Zhang81535612018-10-09 21:15:17 +000014#include "core/fpdfapi/parser/cpdf_dictionary.h"
Dan Sinclair7aba4722018-03-28 17:04:16 +000015#include "core/fpdfapi/parser/cpdf_document.h"
Artem Strygineababa12018-06-06 12:31:18 +000016#include "core/fpdfapi/parser/cpdf_stream_acc.h"
Dan Sinclair7aba4722018-03-28 17:04:16 +000017#include "core/fpdfdoc/cpdf_annot.h"
Lei Zhangc3450652018-10-11 16:54:42 +000018#include "core/fpdfdoc/cpdf_interactiveform.h"
Dan Sinclair7aba4722018-03-28 17:04:16 +000019#include "core/fpdfdoc/cpdf_metadata.h"
Lei Zhange6fcdfa2019-02-14 04:07:09 +000020#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
Dan Sinclair7aba4722018-03-28 17:04:16 +000021
22namespace {
23
Ralf Sippl16381792018-04-12 21:20:26 +000024constexpr char kQuadPoints[] = "QuadPoints";
25
Lei Zhang65a8d5e2018-12-20 19:13:21 +000026// 0 bit: FPDF_POLICY_MACHINETIME_ACCESS
Lei Zhangbc106482019-05-30 23:55:19 +000027uint32_t g_sandbox_policy = 0xFFFFFFFF;
Lei Zhang65a8d5e2018-12-20 19:13:21 +000028
Tom Sepez20c946f2019-07-31 19:33:21 +000029UNSUPPORT_INFO* g_unsupport_info = nullptr;
30
Lei Zhangb7d09ca2019-02-27 23:50:44 +000031bool RaiseUnsupportedError(int nError) {
Tom Sepez20c946f2019-07-31 19:33:21 +000032 if (!g_unsupport_info)
Dan Sinclair7aba4722018-03-28 17:04:16 +000033 return false;
34
Tom Sepez20c946f2019-07-31 19:33:21 +000035 if (g_unsupport_info->FSDK_UnSupport_Handler)
36 g_unsupport_info->FSDK_UnSupport_Handler(g_unsupport_info, nError);
Dan Sinclair7aba4722018-03-28 17:04:16 +000037 return true;
38}
39
Jeremy Chinsen617a2e82019-06-20 00:11:12 +000040unsigned long GetStreamMaybeCopyAndReturnLengthImpl(const CPDF_Stream* stream,
41 void* buffer,
42 unsigned long buflen,
43 bool decode) {
44 ASSERT(stream);
45 auto stream_acc = pdfium::MakeRetain<CPDF_StreamAcc>(stream);
46
47 if (decode)
48 stream_acc->LoadAllDataFiltered();
49 else
50 stream_acc->LoadAllDataRaw();
51
52 const auto stream_data_size = stream_acc->GetSize();
53 if (!buffer || buflen < stream_data_size)
54 return stream_data_size;
55
56 memcpy(buffer, stream_acc->GetData(), stream_data_size);
57 return stream_data_size;
58}
59
Dan Sinclair7aba4722018-03-28 17:04:16 +000060#ifdef PDF_ENABLE_XFA
Tom Sepez55865452018-08-27 20:18:04 +000061class FPDF_FileHandlerContext final : public IFX_SeekableStream {
Dan Sinclair7aba4722018-03-28 17:04:16 +000062 public:
63 template <typename T, typename... Args>
64 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
65
Dan Sinclair7aba4722018-03-28 17:04:16 +000066 // IFX_SeekableStream:
67 FX_FILESIZE GetSize() override;
68 bool IsEOF() override;
69 FX_FILESIZE GetPosition() override;
Lei Zhangf6a79212018-11-15 20:17:49 +000070 bool ReadBlockAtOffset(void* buffer,
71 FX_FILESIZE offset,
72 size_t size) override;
Dan Sinclair7aba4722018-03-28 17:04:16 +000073 size_t ReadBlock(void* buffer, size_t size) override;
Lei Zhang59f76232018-11-15 20:22:59 +000074 bool WriteBlockAtOffset(const void* buffer,
75 FX_FILESIZE offset,
76 size_t size) override;
Dan Sinclair7aba4722018-03-28 17:04:16 +000077 bool Flush() override;
78
79 void SetPosition(FX_FILESIZE pos) { m_nCurPos = pos; }
80
Tom Sepezcb798252018-09-17 18:25:32 +000081 private:
Dan Sinclair7aba4722018-03-28 17:04:16 +000082 explicit FPDF_FileHandlerContext(FPDF_FILEHANDLER* pFS);
Lei Zhang86688de2018-05-22 22:06:49 +000083 ~FPDF_FileHandlerContext() override;
Dan Sinclair7aba4722018-03-28 17:04:16 +000084
85 FPDF_FILEHANDLER* m_pFS;
86 FX_FILESIZE m_nCurPos;
87};
88
89FPDF_FileHandlerContext::FPDF_FileHandlerContext(FPDF_FILEHANDLER* pFS) {
90 m_pFS = pFS;
91 m_nCurPos = 0;
92}
93
94FPDF_FileHandlerContext::~FPDF_FileHandlerContext() {
95 if (m_pFS && m_pFS->Release)
96 m_pFS->Release(m_pFS->clientData);
97}
98
99FX_FILESIZE FPDF_FileHandlerContext::GetSize() {
100 if (m_pFS && m_pFS->GetSize)
101 return (FX_FILESIZE)m_pFS->GetSize(m_pFS->clientData);
102 return 0;
103}
104
105bool FPDF_FileHandlerContext::IsEOF() {
106 return m_nCurPos >= GetSize();
107}
108
109FX_FILESIZE FPDF_FileHandlerContext::GetPosition() {
110 return m_nCurPos;
111}
112
Lei Zhangf6a79212018-11-15 20:17:49 +0000113bool FPDF_FileHandlerContext::ReadBlockAtOffset(void* buffer,
114 FX_FILESIZE offset,
115 size_t size) {
Dan Sinclair7aba4722018-03-28 17:04:16 +0000116 if (!buffer || !size || !m_pFS->ReadBlock)
117 return false;
118
119 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer,
120 (FPDF_DWORD)size) == 0) {
121 m_nCurPos = offset + size;
122 return true;
123 }
124 return false;
125}
126
127size_t FPDF_FileHandlerContext::ReadBlock(void* buffer, size_t size) {
128 if (!buffer || !size || !m_pFS->ReadBlock)
129 return 0;
130
131 FX_FILESIZE nSize = GetSize();
132 if (m_nCurPos >= nSize)
133 return 0;
134 FX_FILESIZE dwAvail = nSize - m_nCurPos;
135 if (dwAvail < (FX_FILESIZE)size)
136 size = static_cast<size_t>(dwAvail);
137 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)m_nCurPos, buffer,
138 (FPDF_DWORD)size) == 0) {
139 m_nCurPos += size;
140 return size;
141 }
142
143 return 0;
144}
145
Lei Zhang59f76232018-11-15 20:22:59 +0000146bool FPDF_FileHandlerContext::WriteBlockAtOffset(const void* buffer,
147 FX_FILESIZE offset,
148 size_t size) {
Dan Sinclair7aba4722018-03-28 17:04:16 +0000149 if (!m_pFS || !m_pFS->WriteBlock)
150 return false;
151
152 if (m_pFS->WriteBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer,
153 (FPDF_DWORD)size) == 0) {
154 m_nCurPos = offset + size;
155 return true;
156 }
157 return false;
158}
159
160bool FPDF_FileHandlerContext::Flush() {
161 if (!m_pFS || !m_pFS->Flush)
162 return true;
163
164 return m_pFS->Flush(m_pFS->clientData) == 0;
165}
166#endif // PDF_ENABLE_XFA
167
168} // namespace
169
Tom Sepez101535f2018-06-12 13:36:05 +0000170IPDF_Page* IPDFPageFromFPDFPage(FPDF_PAGE page) {
171 return reinterpret_cast<IPDF_Page*>(page);
Tom Sepez3f3c39d2018-05-01 17:46:34 +0000172}
173
Tom Sepez101535f2018-06-12 13:36:05 +0000174FPDF_PAGE FPDFPageFromIPDFPage(IPDF_Page* page) {
Tom Sepez3f3c39d2018-05-01 17:46:34 +0000175 return reinterpret_cast<FPDF_PAGE>(page);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000176}
177
178CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) {
Tom Sepezfe06d512018-05-01 17:25:25 +0000179 return reinterpret_cast<CPDF_Document*>(doc);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000180}
181
182FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) {
Tom Sepezfe06d512018-05-01 17:25:25 +0000183 return reinterpret_cast<FPDF_DOCUMENT>(doc);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000184}
185
186CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) {
Tom Sepez101535f2018-06-12 13:36:05 +0000187 return page ? IPDFPageFromFPDFPage(page)->AsPDFPage() : nullptr;
Dan Sinclair7aba4722018-03-28 17:04:16 +0000188}
189
Lei Zhange6fcdfa2019-02-14 04:07:09 +0000190CPDFSDK_InteractiveForm* FormHandleToInteractiveForm(FPDF_FORMHANDLE hHandle) {
191 CPDFSDK_FormFillEnvironment* pFormFillEnv =
192 CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle);
193 return pFormFillEnv ? pFormFillEnv->GetInteractiveForm() : nullptr;
194}
195
Lei Zhangb46a7632019-01-09 02:56:16 +0000196ByteString ByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string) {
197 return WideStringFromFPDFWideString(wide_string).ToUTF8();
Dan Sinclair7aba4722018-03-28 17:04:16 +0000198}
199
Lei Zhangf5fcd9e2018-12-23 03:11:50 +0000200WideString WideStringFromFPDFWideString(FPDF_WIDESTRING wide_string) {
201 return WideString::FromUTF16LE(wide_string,
202 WideString::WStringLength(wide_string));
203}
204
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000205#ifdef PDF_ENABLE_XFA
206RetainPtr<IFX_SeekableStream> MakeSeekableStream(
207 FPDF_FILEHANDLER* pFilehandler) {
208 return pdfium::MakeRetain<FPDF_FileHandlerContext>(pFilehandler);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000209}
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000210#endif // PDF_ENABLE_XFA
Dan Sinclair7aba4722018-03-28 17:04:16 +0000211
Lei Zhang5cee3f22018-05-25 21:48:49 +0000212const CPDF_Array* GetQuadPointsArrayFromDictionary(
213 const CPDF_Dictionary* dict) {
Lei Zhangd934c642019-03-04 19:42:00 +0000214 return dict->GetArrayFor("QuadPoints");
Lei Zhang5cee3f22018-05-25 21:48:49 +0000215}
216
217CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict) {
Lei Zhangd934c642019-03-04 19:42:00 +0000218 return dict->GetArrayFor("QuadPoints");
Dan Sinclair7aba4722018-03-28 17:04:16 +0000219}
220
Ralf Sippl16381792018-04-12 21:20:26 +0000221CPDF_Array* AddQuadPointsArrayToDictionary(CPDF_Dictionary* dict) {
Ralf Sippl16381792018-04-12 21:20:26 +0000222 return dict->SetNewFor<CPDF_Array>(kQuadPoints);
223}
224
225bool IsValidQuadPointsIndex(const CPDF_Array* array, size_t index) {
Lei Zhangf40380f2018-10-12 18:31:51 +0000226 return array && index < array->size() / 8;
Ralf Sippl16381792018-04-12 21:20:26 +0000227}
228
229bool GetQuadPointsAtIndex(const CPDF_Array* array,
230 size_t quad_index,
231 FS_QUADPOINTSF* quad_points) {
232 ASSERT(quad_points);
233 ASSERT(array);
234
235 if (!IsValidQuadPointsIndex(array, quad_index))
236 return false;
237
238 quad_index *= 8;
239 quad_points->x1 = array->GetNumberAt(quad_index);
240 quad_points->y1 = array->GetNumberAt(quad_index + 1);
241 quad_points->x2 = array->GetNumberAt(quad_index + 2);
242 quad_points->y2 = array->GetNumberAt(quad_index + 3);
243 quad_points->x3 = array->GetNumberAt(quad_index + 4);
244 quad_points->y3 = array->GetNumberAt(quad_index + 5);
245 quad_points->x4 = array->GetNumberAt(quad_index + 6);
246 quad_points->y4 = array->GetNumberAt(quad_index + 7);
247 return true;
248}
249
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000250CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect) {
251 return CFX_FloatRect(rect.left, rect.bottom, rect.right, rect.top);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000252}
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000253
Lei Zhang3567c612019-11-18 18:10:02 +0000254FS_RECTF FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect) {
255 return {rect.left, rect.top, rect.right, rect.bottom};
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000256}
257
Lei Zhang6fef1e42018-12-20 19:14:02 +0000258CFX_Matrix CFXMatrixFromFSMatrix(const FS_MATRIX& matrix) {
259 return CFX_Matrix(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f);
260}
261
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000262unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text,
263 void* buffer,
264 unsigned long buflen) {
265 ByteString encoded_text = text.ToUTF16LE();
266 unsigned long len = encoded_text.GetLength();
267 if (buffer && len <= buflen)
268 memcpy(buffer, encoded_text.c_str(), len);
269 return len;
270}
271
Jeremy Chinsen617a2e82019-06-20 00:11:12 +0000272unsigned long GetRawStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream,
273 void* buffer,
274 unsigned long buflen) {
275 return GetStreamMaybeCopyAndReturnLengthImpl(stream, buffer, buflen,
276 /*decode=*/false);
277}
278
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000279unsigned long DecodeStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream,
280 void* buffer,
281 unsigned long buflen) {
Jeremy Chinsen617a2e82019-06-20 00:11:12 +0000282 return GetStreamMaybeCopyAndReturnLengthImpl(stream, buffer, buflen,
283 /*decode=*/true);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000284}
285
Tom Sepez69a4a702019-07-31 17:59:49 +0000286void SetPDFSandboxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) {
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000287 switch (policy) {
288 case FPDF_POLICY_MACHINETIME_ACCESS: {
Tom Sepezfe285c32019-12-04 18:38:03 +0000289 uint32_t mask = 1 << policy;
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000290 if (enable)
Tom Sepezfe285c32019-12-04 18:38:03 +0000291 g_sandbox_policy |= mask;
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000292 else
Tom Sepezfe285c32019-12-04 18:38:03 +0000293 g_sandbox_policy &= ~mask;
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000294 } break;
295 default:
296 break;
297 }
298}
299
Tom Sepez69a4a702019-07-31 17:59:49 +0000300FPDF_BOOL IsPDFSandboxPolicyEnabled(FPDF_DWORD policy) {
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000301 switch (policy) {
Tom Sepezfe285c32019-12-04 18:38:03 +0000302 case FPDF_POLICY_MACHINETIME_ACCESS: {
303 uint32_t mask = 1 << policy;
304 return !!(g_sandbox_policy & mask);
305 }
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000306 default:
307 return false;
308 }
309}
310
Tom Sepez20c946f2019-07-31 19:33:21 +0000311void SetPDFUnsupportInfo(UNSUPPORT_INFO* unsp_info) {
312 g_unsupport_info = unsp_info;
313}
314
315UNSUPPORT_INFO* GetPDFUnssuportInto() {
316 return g_unsupport_info;
317}
318
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000319void ReportUnsupportedFeatures(CPDF_Document* pDoc) {
320 const CPDF_Dictionary* pRootDict = pDoc->GetRoot();
321 if (pRootDict) {
322 // Portfolios and Packages
323 if (pRootDict->KeyExist("Collection")) {
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000324 RaiseUnsupportedError(FPDF_UNSP_DOC_PORTABLECOLLECTION);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000325 return;
326 }
327 if (pRootDict->KeyExist("Names")) {
328 const CPDF_Dictionary* pNameDict = pRootDict->GetDictFor("Names");
329 if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) {
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000330 RaiseUnsupportedError(FPDF_UNSP_DOC_ATTACHMENT);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000331 return;
332 }
333 if (pNameDict && pNameDict->KeyExist("JavaScript")) {
334 const CPDF_Dictionary* pJSDict = pNameDict->GetDictFor("JavaScript");
335 const CPDF_Array* pArray =
336 pJSDict ? pJSDict->GetArrayFor("Names") : nullptr;
337 if (pArray) {
338 for (size_t i = 0; i < pArray->size(); i++) {
339 ByteString cbStr = pArray->GetStringAt(i);
340 if (cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0) {
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000341 RaiseUnsupportedError(FPDF_UNSP_DOC_SHAREDREVIEW);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000342 return;
343 }
344 }
345 }
346 }
347 }
348
349 // SharedForm
350 const CPDF_Stream* pStream = pRootDict->GetStreamFor("Metadata");
351 if (pStream) {
352 CPDF_Metadata metaData(pStream);
353 for (const auto& err : metaData.CheckForSharedForm())
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000354 RaiseUnsupportedError(static_cast<int>(err));
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000355 }
356 }
357
358 // XFA Forms
359 if (!pDoc->GetExtension() && CPDF_InteractiveForm(pDoc).HasXFAForm())
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000360 RaiseUnsupportedError(FPDF_UNSP_DOC_XFAFORM);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000361}
362
Lei Zhang4efdb512019-02-26 19:48:39 +0000363void CheckForUnsupportedAnnot(const CPDF_Annot* pAnnot) {
364 switch (pAnnot->GetSubtype()) {
365 case CPDF_Annot::Subtype::FILEATTACHMENT:
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000366 RaiseUnsupportedError(FPDF_UNSP_ANNOT_ATTACHMENT);
Lei Zhang4efdb512019-02-26 19:48:39 +0000367 break;
368 case CPDF_Annot::Subtype::MOVIE:
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000369 RaiseUnsupportedError(FPDF_UNSP_ANNOT_MOVIE);
Lei Zhang4efdb512019-02-26 19:48:39 +0000370 break;
371 case CPDF_Annot::Subtype::RICHMEDIA:
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000372 RaiseUnsupportedError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA);
Lei Zhang4efdb512019-02-26 19:48:39 +0000373 break;
374 case CPDF_Annot::Subtype::SCREEN: {
375 const CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
Lei Zhang6c715022019-02-26 20:16:09 +0000376 ByteString cbString = pAnnotDict->GetStringFor("IT");
377 if (cbString != "Img")
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000378 RaiseUnsupportedError(FPDF_UNSP_ANNOT_SCREEN_MEDIA);
Lei Zhang4efdb512019-02-26 19:48:39 +0000379 break;
380 }
381 case CPDF_Annot::Subtype::SOUND:
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000382 RaiseUnsupportedError(FPDF_UNSP_ANNOT_SOUND);
Lei Zhang4efdb512019-02-26 19:48:39 +0000383 break;
384 case CPDF_Annot::Subtype::THREED:
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000385 RaiseUnsupportedError(FPDF_UNSP_ANNOT_3DANNOT);
Lei Zhang4efdb512019-02-26 19:48:39 +0000386 break;
387 case CPDF_Annot::Subtype::WIDGET: {
388 const CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
Lei Zhang865ffb12019-02-26 20:18:19 +0000389 ByteString cbString = pAnnotDict->GetStringFor(pdfium::form_fields::kFT);
Lei Zhangf496e252019-02-26 20:20:19 +0000390 if (cbString == pdfium::form_fields::kSig)
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000391 RaiseUnsupportedError(FPDF_UNSP_ANNOT_SIG);
Lei Zhang4efdb512019-02-26 19:48:39 +0000392 break;
393 }
394 default:
395 break;
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000396 }
397}
398
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000399void ProcessParseError(CPDF_Parser::Error err) {
400 uint32_t err_code = FPDF_ERR_SUCCESS;
401 // Translate FPDFAPI error code to FPDFVIEW error code
402 switch (err) {
403 case CPDF_Parser::SUCCESS:
404 err_code = FPDF_ERR_SUCCESS;
405 break;
406 case CPDF_Parser::FILE_ERROR:
407 err_code = FPDF_ERR_FILE;
408 break;
409 case CPDF_Parser::FORMAT_ERROR:
410 err_code = FPDF_ERR_FORMAT;
411 break;
412 case CPDF_Parser::PASSWORD_ERROR:
413 err_code = FPDF_ERR_PASSWORD;
414 break;
415 case CPDF_Parser::HANDLER_ERROR:
416 err_code = FPDF_ERR_SECURITY;
417 break;
418 }
Tom Sepez04e3af82019-08-05 23:41:06 +0000419 FXSYS_SetLastError(err_code);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000420}