OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../../include/fpdfapi/fpdf_parser.h" | 7 #include "../../../include/fpdfapi/fpdf_parser.h" |
8 #include "../../../include/fpdfapi/fpdf_module.h" | 8 #include "../../../include/fpdfapi/fpdf_module.h" |
9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
10 #include <limits.h> | 10 #include <limits.h> |
(...skipping 27 matching lines...) Expand all Loading... |
38 return (FX_DWORD) - 1; | 38 return (FX_DWORD) - 1; |
39 } | 39 } |
40 if (zcount * 4 > UINT_MAX - (pos - zcount)) { | 40 if (zcount * 4 > UINT_MAX - (pos - zcount)) { |
41 return (FX_DWORD) - 1; | 41 return (FX_DWORD) - 1; |
42 } | 42 } |
43 dest_buf = FX_Alloc(FX_BYTE, zcount * 4 + (pos - zcount)); | 43 dest_buf = FX_Alloc(FX_BYTE, zcount * 4 + (pos - zcount)); |
44 if (dest_buf == NULL) { | 44 if (dest_buf == NULL) { |
45 return (FX_DWORD) - 1; | 45 return (FX_DWORD) - 1; |
46 } | 46 } |
47 int state = 0; | 47 int state = 0; |
48 » FX_UINT32 res = 0; | 48 FX_UINT32 res = 0; |
49 pos = dest_size = 0; | 49 pos = dest_size = 0; |
50 while (pos < src_size) { | 50 while (pos < src_size) { |
51 FX_BYTE ch = src_buf[pos++]; | 51 FX_BYTE ch = src_buf[pos++]; |
52 if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') { | 52 if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') { |
53 continue; | 53 continue; |
54 } | 54 } |
55 if (ch == 'z') { | 55 if (ch == 'z') { |
56 FXSYS_memset32(dest_buf + dest_size, 0, 4); | 56 FXSYS_memset32(dest_buf + dest_size, 0, 4); |
57 state = 0; | 57 state = 0; |
58 res = 0; | 58 res = 0; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 274 } |
275 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(bLZW, src_b
uf, src_size, | 275 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(bLZW, src_b
uf, src_size, |
276 bEarlyChange, predictor, Colors, BitsPerComponent, Columns, estimate
d_size, | 276 bEarlyChange, predictor, Colors, BitsPerComponent, Columns, estimate
d_size, |
277 dest_buf, dest_size); | 277 dest_buf, dest_size); |
278 } | 278 } |
279 FX_BOOL PDF_DataDecode(FX_LPCBYTE src_buf, FX_DWORD src_size, const CPDF_Diction
ary* pDict, | 279 FX_BOOL PDF_DataDecode(FX_LPCBYTE src_buf, FX_DWORD src_size, const CPDF_Diction
ary* pDict, |
280 FX_LPBYTE& dest_buf, FX_DWORD& dest_size, CFX_ByteString&
ImageEncoding, | 280 FX_LPBYTE& dest_buf, FX_DWORD& dest_size, CFX_ByteString&
ImageEncoding, |
281 CPDF_Dictionary*& pImageParms, FX_DWORD last_estimated_si
ze, FX_BOOL bImageAcc) | 281 CPDF_Dictionary*& pImageParms, FX_DWORD last_estimated_si
ze, FX_BOOL bImageAcc) |
282 | 282 |
283 { | 283 { |
284 CPDF_Object* pDecoder = pDict->GetElementValue(FX_BSTRC("Filter")); | 284 CPDF_Object* pDecoder = pDict ? pDict->GetElementValue(FX_BSTRC("Filter")) :
NULL; |
285 if (pDecoder == NULL || (pDecoder->GetType() != PDFOBJ_ARRAY && pDecoder->Ge
tType() != PDFOBJ_NAME)) { | 285 if (pDecoder == NULL || (pDecoder->GetType() != PDFOBJ_ARRAY && pDecoder->Ge
tType() != PDFOBJ_NAME)) { |
286 return FALSE; | 286 return FALSE; |
287 } | 287 } |
288 CPDF_Object* pParams = pDict->GetElementValue(FX_BSTRC("DecodeParms")); | 288 CPDF_Object* pParams = pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms"
)) : NULL; |
289 CFX_ByteStringArray DecoderList; | 289 CFX_ByteStringArray DecoderList; |
290 CFX_PtrArray ParamList; | 290 CFX_PtrArray ParamList; |
291 if (pDecoder->GetType() == PDFOBJ_ARRAY) { | 291 if (pDecoder->GetType() == PDFOBJ_ARRAY) { |
292 if (pParams && pParams->GetType() != PDFOBJ_ARRAY) { | 292 if (pParams && pParams->GetType() != PDFOBJ_ARRAY) { |
293 pParams = NULL; | 293 pParams = NULL; |
294 } | 294 } |
295 CPDF_Array* pDecoders = (CPDF_Array*)pDecoder; | 295 CPDF_Array* pDecoders = (CPDF_Array*)pDecoder; |
296 for (FX_DWORD i = 0; i < pDecoders->GetCount(); i ++) { | 296 for (FX_DWORD i = 0; i < pDecoders->GetCount(); i ++) { |
297 CFX_ByteStringC str = pDecoders->GetConstString(i); | 297 CFX_ByteStringC str = pDecoders->GetConstString(i); |
298 DecoderList.Add(str); | 298 DecoderList.Add(str); |
299 if (pParams) { | 299 if (pParams) { |
300 ParamList.Add(((CPDF_Array*)pParams)->GetDict(i)); | 300 ParamList.Add(((CPDF_Array*)pParams)->GetDict(i)); |
301 } else { | 301 } else { |
302 ParamList.Add(NULL); | 302 ParamList.Add(NULL); |
303 } | 303 } |
304 } | 304 } |
305 } else { | 305 } else { |
306 DecoderList.Add(pDecoder->GetConstString()); | 306 DecoderList.Add(pDecoder->GetConstString()); |
307 ParamList.Add(pParams->GetDict()); | 307 ParamList.Add(pParams ? pParams->GetDict() : NULL); |
308 } | 308 } |
309 FX_LPBYTE last_buf = (FX_LPBYTE)src_buf; | 309 FX_LPBYTE last_buf = (FX_LPBYTE)src_buf; |
310 FX_DWORD last_size = src_size; | 310 FX_DWORD last_size = src_size; |
311 for (int i = 0; i < DecoderList.GetSize(); i ++) { | 311 for (int i = 0; i < DecoderList.GetSize(); i ++) { |
312 int estimated_size = i == DecoderList.GetSize() - 1 ? last_estimated_siz
e : 0; | 312 int estimated_size = i == DecoderList.GetSize() - 1 ? last_estimated_siz
e : 0; |
313 CFX_ByteString decoder = DecoderList[i]; | 313 CFX_ByteString decoder = DecoderList[i]; |
314 CPDF_Dictionary* pParam = (CPDF_Dictionary*)ParamList[i]; | 314 CPDF_Dictionary* pParam = (CPDF_Dictionary*)ParamList[i]; |
315 FX_LPBYTE new_buf = NULL; | 315 FX_LPBYTE new_buf = NULL; |
316 FX_DWORD new_size = (FX_DWORD) - 1; | 316 FX_DWORD new_size = (FX_DWORD) - 1; |
317 int offset = -1; | 317 int offset = -1; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 } | 534 } |
535 } | 535 } |
536 FX_DWORD FlateDecode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_
buf, FX_DWORD& dest_size) | 536 FX_DWORD FlateDecode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_
buf, FX_DWORD& dest_size) |
537 { | 537 { |
538 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 538 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
539 if (pEncoders) { | 539 if (pEncoders) { |
540 return pEncoders->GetFlateModule()->FlateOrLZWDecode(FALSE, src_buf, src
_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 540 return pEncoders->GetFlateModule()->FlateOrLZWDecode(FALSE, src_buf, src
_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
541 } | 541 } |
542 return 0; | 542 return 0; |
543 } | 543 } |
OLD | NEW |