blob: f534cf7b51d9d1a608f8091228969c2f067ecb7b [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
Lei Zhang85e09df2020-02-27 14:48:07 +000040// Use the existence of the XFA array as a signal for XFA forms.
41bool DocHasXFA(const CPDF_Document* doc) {
42 const CPDF_Dictionary* root = doc->GetRoot();
43 if (!root)
44 return false;
45
46 const CPDF_Dictionary* form = root->GetDictFor("AcroForm");
47 return form && form->GetArrayFor("XFA");
48}
49
Jeremy Chinsen617a2e82019-06-20 00:11:12 +000050unsigned long GetStreamMaybeCopyAndReturnLengthImpl(const CPDF_Stream* stream,
51 void* buffer,
52 unsigned long buflen,
53 bool decode) {
54 ASSERT(stream);
55 auto stream_acc = pdfium::MakeRetain<CPDF_StreamAcc>(stream);
56
57 if (decode)
58 stream_acc->LoadAllDataFiltered();
59 else
60 stream_acc->LoadAllDataRaw();
61
62 const auto stream_data_size = stream_acc->GetSize();
63 if (!buffer || buflen < stream_data_size)
64 return stream_data_size;
65
66 memcpy(buffer, stream_acc->GetData(), stream_data_size);
67 return stream_data_size;
68}
69
Dan Sinclair7aba4722018-03-28 17:04:16 +000070#ifdef PDF_ENABLE_XFA
Tom Sepez55865452018-08-27 20:18:04 +000071class FPDF_FileHandlerContext final : public IFX_SeekableStream {
Dan Sinclair7aba4722018-03-28 17:04:16 +000072 public:
73 template <typename T, typename... Args>
74 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
75
Dan Sinclair7aba4722018-03-28 17:04:16 +000076 // IFX_SeekableStream:
77 FX_FILESIZE GetSize() override;
78 bool IsEOF() override;
79 FX_FILESIZE GetPosition() override;
Lei Zhangf6a79212018-11-15 20:17:49 +000080 bool ReadBlockAtOffset(void* buffer,
81 FX_FILESIZE offset,
82 size_t size) override;
Dan Sinclair7aba4722018-03-28 17:04:16 +000083 size_t ReadBlock(void* buffer, size_t size) override;
Lei Zhang59f76232018-11-15 20:22:59 +000084 bool WriteBlockAtOffset(const void* buffer,
85 FX_FILESIZE offset,
86 size_t size) override;
Dan Sinclair7aba4722018-03-28 17:04:16 +000087 bool Flush() override;
88
89 void SetPosition(FX_FILESIZE pos) { m_nCurPos = pos; }
90
Tom Sepezcb798252018-09-17 18:25:32 +000091 private:
Dan Sinclair7aba4722018-03-28 17:04:16 +000092 explicit FPDF_FileHandlerContext(FPDF_FILEHANDLER* pFS);
Lei Zhang86688de2018-05-22 22:06:49 +000093 ~FPDF_FileHandlerContext() override;
Dan Sinclair7aba4722018-03-28 17:04:16 +000094
95 FPDF_FILEHANDLER* m_pFS;
96 FX_FILESIZE m_nCurPos;
97};
98
99FPDF_FileHandlerContext::FPDF_FileHandlerContext(FPDF_FILEHANDLER* pFS) {
100 m_pFS = pFS;
101 m_nCurPos = 0;
102}
103
104FPDF_FileHandlerContext::~FPDF_FileHandlerContext() {
105 if (m_pFS && m_pFS->Release)
106 m_pFS->Release(m_pFS->clientData);
107}
108
109FX_FILESIZE FPDF_FileHandlerContext::GetSize() {
110 if (m_pFS && m_pFS->GetSize)
111 return (FX_FILESIZE)m_pFS->GetSize(m_pFS->clientData);
112 return 0;
113}
114
115bool FPDF_FileHandlerContext::IsEOF() {
116 return m_nCurPos >= GetSize();
117}
118
119FX_FILESIZE FPDF_FileHandlerContext::GetPosition() {
120 return m_nCurPos;
121}
122
Lei Zhangf6a79212018-11-15 20:17:49 +0000123bool FPDF_FileHandlerContext::ReadBlockAtOffset(void* buffer,
124 FX_FILESIZE offset,
125 size_t size) {
Dan Sinclair7aba4722018-03-28 17:04:16 +0000126 if (!buffer || !size || !m_pFS->ReadBlock)
127 return false;
128
129 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer,
130 (FPDF_DWORD)size) == 0) {
131 m_nCurPos = offset + size;
132 return true;
133 }
134 return false;
135}
136
137size_t FPDF_FileHandlerContext::ReadBlock(void* buffer, size_t size) {
138 if (!buffer || !size || !m_pFS->ReadBlock)
139 return 0;
140
141 FX_FILESIZE nSize = GetSize();
142 if (m_nCurPos >= nSize)
143 return 0;
144 FX_FILESIZE dwAvail = nSize - m_nCurPos;
145 if (dwAvail < (FX_FILESIZE)size)
146 size = static_cast<size_t>(dwAvail);
147 if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)m_nCurPos, buffer,
148 (FPDF_DWORD)size) == 0) {
149 m_nCurPos += size;
150 return size;
151 }
152
153 return 0;
154}
155
Lei Zhang59f76232018-11-15 20:22:59 +0000156bool FPDF_FileHandlerContext::WriteBlockAtOffset(const void* buffer,
157 FX_FILESIZE offset,
158 size_t size) {
Dan Sinclair7aba4722018-03-28 17:04:16 +0000159 if (!m_pFS || !m_pFS->WriteBlock)
160 return false;
161
162 if (m_pFS->WriteBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer,
163 (FPDF_DWORD)size) == 0) {
164 m_nCurPos = offset + size;
165 return true;
166 }
167 return false;
168}
169
170bool FPDF_FileHandlerContext::Flush() {
171 if (!m_pFS || !m_pFS->Flush)
172 return true;
173
174 return m_pFS->Flush(m_pFS->clientData) == 0;
175}
176#endif // PDF_ENABLE_XFA
177
178} // namespace
179
Tom Sepez101535f2018-06-12 13:36:05 +0000180IPDF_Page* IPDFPageFromFPDFPage(FPDF_PAGE page) {
181 return reinterpret_cast<IPDF_Page*>(page);
Tom Sepez3f3c39d2018-05-01 17:46:34 +0000182}
183
Tom Sepez101535f2018-06-12 13:36:05 +0000184FPDF_PAGE FPDFPageFromIPDFPage(IPDF_Page* page) {
Tom Sepez3f3c39d2018-05-01 17:46:34 +0000185 return reinterpret_cast<FPDF_PAGE>(page);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000186}
187
188CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) {
Tom Sepezfe06d512018-05-01 17:25:25 +0000189 return reinterpret_cast<CPDF_Document*>(doc);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000190}
191
192FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) {
Tom Sepezfe06d512018-05-01 17:25:25 +0000193 return reinterpret_cast<FPDF_DOCUMENT>(doc);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000194}
195
196CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) {
Tom Sepez101535f2018-06-12 13:36:05 +0000197 return page ? IPDFPageFromFPDFPage(page)->AsPDFPage() : nullptr;
Dan Sinclair7aba4722018-03-28 17:04:16 +0000198}
199
Lei Zhange6fcdfa2019-02-14 04:07:09 +0000200CPDFSDK_InteractiveForm* FormHandleToInteractiveForm(FPDF_FORMHANDLE hHandle) {
201 CPDFSDK_FormFillEnvironment* pFormFillEnv =
202 CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle);
203 return pFormFillEnv ? pFormFillEnv->GetInteractiveForm() : nullptr;
204}
205
Lei Zhangb46a7632019-01-09 02:56:16 +0000206ByteString ByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string) {
207 return WideStringFromFPDFWideString(wide_string).ToUTF8();
Dan Sinclair7aba4722018-03-28 17:04:16 +0000208}
209
Lei Zhangf5fcd9e2018-12-23 03:11:50 +0000210WideString WideStringFromFPDFWideString(FPDF_WIDESTRING wide_string) {
211 return WideString::FromUTF16LE(wide_string,
212 WideString::WStringLength(wide_string));
213}
214
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000215#ifdef PDF_ENABLE_XFA
216RetainPtr<IFX_SeekableStream> MakeSeekableStream(
217 FPDF_FILEHANDLER* pFilehandler) {
218 return pdfium::MakeRetain<FPDF_FileHandlerContext>(pFilehandler);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000219}
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000220#endif // PDF_ENABLE_XFA
Dan Sinclair7aba4722018-03-28 17:04:16 +0000221
Lei Zhang5cee3f22018-05-25 21:48:49 +0000222const CPDF_Array* GetQuadPointsArrayFromDictionary(
223 const CPDF_Dictionary* dict) {
Lei Zhangd934c642019-03-04 19:42:00 +0000224 return dict->GetArrayFor("QuadPoints");
Lei Zhang5cee3f22018-05-25 21:48:49 +0000225}
226
227CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict) {
Lei Zhangd934c642019-03-04 19:42:00 +0000228 return dict->GetArrayFor("QuadPoints");
Dan Sinclair7aba4722018-03-28 17:04:16 +0000229}
230
Ralf Sippl16381792018-04-12 21:20:26 +0000231CPDF_Array* AddQuadPointsArrayToDictionary(CPDF_Dictionary* dict) {
Ralf Sippl16381792018-04-12 21:20:26 +0000232 return dict->SetNewFor<CPDF_Array>(kQuadPoints);
233}
234
235bool IsValidQuadPointsIndex(const CPDF_Array* array, size_t index) {
Lei Zhangf40380f2018-10-12 18:31:51 +0000236 return array && index < array->size() / 8;
Ralf Sippl16381792018-04-12 21:20:26 +0000237}
238
239bool GetQuadPointsAtIndex(const CPDF_Array* array,
240 size_t quad_index,
241 FS_QUADPOINTSF* quad_points) {
242 ASSERT(quad_points);
243 ASSERT(array);
244
245 if (!IsValidQuadPointsIndex(array, quad_index))
246 return false;
247
248 quad_index *= 8;
249 quad_points->x1 = array->GetNumberAt(quad_index);
250 quad_points->y1 = array->GetNumberAt(quad_index + 1);
251 quad_points->x2 = array->GetNumberAt(quad_index + 2);
252 quad_points->y2 = array->GetNumberAt(quad_index + 3);
253 quad_points->x3 = array->GetNumberAt(quad_index + 4);
254 quad_points->y3 = array->GetNumberAt(quad_index + 5);
255 quad_points->x4 = array->GetNumberAt(quad_index + 6);
256 quad_points->y4 = array->GetNumberAt(quad_index + 7);
257 return true;
258}
259
Lei Zhang8da98232019-12-11 23:29:33 +0000260CFX_PointF CFXPointFFromFSPointF(const FS_POINTF& point) {
261 return CFX_PointF(point.x, point.y);
262}
263
264CFX_FloatRect CFXFloatRectFromFSRectF(const FS_RECTF& rect) {
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000265 return CFX_FloatRect(rect.left, rect.bottom, rect.right, rect.top);
Dan Sinclair7aba4722018-03-28 17:04:16 +0000266}
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000267
Lei Zhang8da98232019-12-11 23:29:33 +0000268FS_RECTF FSRectFFromCFXFloatRect(const CFX_FloatRect& rect) {
Lei Zhang3567c612019-11-18 18:10:02 +0000269 return {rect.left, rect.top, rect.right, rect.bottom};
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000270}
271
Lei Zhang6fef1e42018-12-20 19:14:02 +0000272CFX_Matrix CFXMatrixFromFSMatrix(const FS_MATRIX& matrix) {
273 return CFX_Matrix(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f);
274}
275
Lei Zhangc89c5822020-01-21 20:23:56 +0000276FS_MATRIX FSMatrixFromCFXMatrix(const CFX_Matrix& matrix) {
277 return {matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f};
Lei Zhang8da98232019-12-11 23:29:33 +0000278}
279
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000280unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text,
281 void* buffer,
282 unsigned long buflen) {
283 ByteString encoded_text = text.ToUTF16LE();
284 unsigned long len = encoded_text.GetLength();
285 if (buffer && len <= buflen)
286 memcpy(buffer, encoded_text.c_str(), len);
287 return len;
288}
289
Jeremy Chinsen617a2e82019-06-20 00:11:12 +0000290unsigned long GetRawStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream,
291 void* buffer,
292 unsigned long buflen) {
293 return GetStreamMaybeCopyAndReturnLengthImpl(stream, buffer, buflen,
294 /*decode=*/false);
295}
296
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000297unsigned long DecodeStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream,
298 void* buffer,
299 unsigned long buflen) {
Jeremy Chinsen617a2e82019-06-20 00:11:12 +0000300 return GetStreamMaybeCopyAndReturnLengthImpl(stream, buffer, buflen,
301 /*decode=*/true);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000302}
303
Tom Sepez69a4a702019-07-31 17:59:49 +0000304void SetPDFSandboxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) {
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000305 switch (policy) {
306 case FPDF_POLICY_MACHINETIME_ACCESS: {
Tom Sepezfe285c32019-12-04 18:38:03 +0000307 uint32_t mask = 1 << policy;
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000308 if (enable)
Tom Sepezfe285c32019-12-04 18:38:03 +0000309 g_sandbox_policy |= mask;
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000310 else
Tom Sepezfe285c32019-12-04 18:38:03 +0000311 g_sandbox_policy &= ~mask;
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000312 } break;
313 default:
314 break;
315 }
316}
317
Tom Sepez69a4a702019-07-31 17:59:49 +0000318FPDF_BOOL IsPDFSandboxPolicyEnabled(FPDF_DWORD policy) {
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000319 switch (policy) {
Tom Sepezfe285c32019-12-04 18:38:03 +0000320 case FPDF_POLICY_MACHINETIME_ACCESS: {
321 uint32_t mask = 1 << policy;
322 return !!(g_sandbox_policy & mask);
323 }
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000324 default:
325 return false;
326 }
327}
328
Tom Sepez20c946f2019-07-31 19:33:21 +0000329void SetPDFUnsupportInfo(UNSUPPORT_INFO* unsp_info) {
330 g_unsupport_info = unsp_info;
331}
332
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000333void ReportUnsupportedFeatures(CPDF_Document* pDoc) {
334 const CPDF_Dictionary* pRootDict = pDoc->GetRoot();
335 if (pRootDict) {
336 // Portfolios and Packages
337 if (pRootDict->KeyExist("Collection")) {
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000338 RaiseUnsupportedError(FPDF_UNSP_DOC_PORTABLECOLLECTION);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000339 return;
340 }
341 if (pRootDict->KeyExist("Names")) {
342 const CPDF_Dictionary* pNameDict = pRootDict->GetDictFor("Names");
343 if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) {
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000344 RaiseUnsupportedError(FPDF_UNSP_DOC_ATTACHMENT);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000345 return;
346 }
347 if (pNameDict && pNameDict->KeyExist("JavaScript")) {
348 const CPDF_Dictionary* pJSDict = pNameDict->GetDictFor("JavaScript");
349 const CPDF_Array* pArray =
350 pJSDict ? pJSDict->GetArrayFor("Names") : nullptr;
351 if (pArray) {
352 for (size_t i = 0; i < pArray->size(); i++) {
353 ByteString cbStr = pArray->GetStringAt(i);
354 if (cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0) {
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000355 RaiseUnsupportedError(FPDF_UNSP_DOC_SHAREDREVIEW);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000356 return;
357 }
358 }
359 }
360 }
361 }
362
363 // SharedForm
364 const CPDF_Stream* pStream = pRootDict->GetStreamFor("Metadata");
365 if (pStream) {
366 CPDF_Metadata metaData(pStream);
367 for (const auto& err : metaData.CheckForSharedForm())
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000368 RaiseUnsupportedError(static_cast<int>(err));
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000369 }
370 }
Daniel Hosseiniana793e972020-01-24 02:51:31 +0000371}
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000372
Lei Zhang85e09df2020-02-27 14:48:07 +0000373void ReportUnsupportedXFA(const CPDF_Document* pDoc) {
374 if (!pDoc->GetExtension() && DocHasXFA(pDoc))
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000375 RaiseUnsupportedError(FPDF_UNSP_DOC_XFAFORM);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000376}
377
Lei Zhang4efdb512019-02-26 19:48:39 +0000378void CheckForUnsupportedAnnot(const CPDF_Annot* pAnnot) {
379 switch (pAnnot->GetSubtype()) {
380 case CPDF_Annot::Subtype::FILEATTACHMENT:
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000381 RaiseUnsupportedError(FPDF_UNSP_ANNOT_ATTACHMENT);
Lei Zhang4efdb512019-02-26 19:48:39 +0000382 break;
383 case CPDF_Annot::Subtype::MOVIE:
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000384 RaiseUnsupportedError(FPDF_UNSP_ANNOT_MOVIE);
Lei Zhang4efdb512019-02-26 19:48:39 +0000385 break;
386 case CPDF_Annot::Subtype::RICHMEDIA:
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000387 RaiseUnsupportedError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA);
Lei Zhang4efdb512019-02-26 19:48:39 +0000388 break;
389 case CPDF_Annot::Subtype::SCREEN: {
390 const CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
Lei Zhang6c715022019-02-26 20:16:09 +0000391 ByteString cbString = pAnnotDict->GetStringFor("IT");
392 if (cbString != "Img")
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000393 RaiseUnsupportedError(FPDF_UNSP_ANNOT_SCREEN_MEDIA);
Lei Zhang4efdb512019-02-26 19:48:39 +0000394 break;
395 }
396 case CPDF_Annot::Subtype::SOUND:
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000397 RaiseUnsupportedError(FPDF_UNSP_ANNOT_SOUND);
Lei Zhang4efdb512019-02-26 19:48:39 +0000398 break;
399 case CPDF_Annot::Subtype::THREED:
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000400 RaiseUnsupportedError(FPDF_UNSP_ANNOT_3DANNOT);
Lei Zhang4efdb512019-02-26 19:48:39 +0000401 break;
402 case CPDF_Annot::Subtype::WIDGET: {
403 const CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
Lei Zhang865ffb12019-02-26 20:18:19 +0000404 ByteString cbString = pAnnotDict->GetStringFor(pdfium::form_fields::kFT);
Lei Zhangf496e252019-02-26 20:20:19 +0000405 if (cbString == pdfium::form_fields::kSig)
Lei Zhangb7d09ca2019-02-27 23:50:44 +0000406 RaiseUnsupportedError(FPDF_UNSP_ANNOT_SIG);
Lei Zhang4efdb512019-02-26 19:48:39 +0000407 break;
408 }
409 default:
410 break;
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000411 }
412}
413
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000414void ProcessParseError(CPDF_Parser::Error err) {
415 uint32_t err_code = FPDF_ERR_SUCCESS;
416 // Translate FPDFAPI error code to FPDFVIEW error code
417 switch (err) {
418 case CPDF_Parser::SUCCESS:
419 err_code = FPDF_ERR_SUCCESS;
420 break;
421 case CPDF_Parser::FILE_ERROR:
422 err_code = FPDF_ERR_FILE;
423 break;
424 case CPDF_Parser::FORMAT_ERROR:
425 err_code = FPDF_ERR_FORMAT;
426 break;
427 case CPDF_Parser::PASSWORD_ERROR:
428 err_code = FPDF_ERR_PASSWORD;
429 break;
430 case CPDF_Parser::HANDLER_ERROR:
431 err_code = FPDF_ERR_SECURITY;
432 break;
433 }
Tom Sepez04e3af82019-08-05 23:41:06 +0000434 FXSYS_SetLastError(err_code);
Lei Zhang65a8d5e2018-12-20 19:13:21 +0000435}