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 <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_module.h" | 9 #include "core/include/fpdfapi/fpdf_module.h" |
10 #include "core/include/fpdfapi/fpdf_parser.h" | 10 #include "core/include/fpdfapi/fpdf_parser.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } | 356 } |
357 uint8_t* last_buf = (uint8_t*)src_buf; | 357 uint8_t* last_buf = (uint8_t*)src_buf; |
358 FX_DWORD last_size = src_size; | 358 FX_DWORD last_size = src_size; |
359 for (int i = 0; i < DecoderList.GetSize(); i++) { | 359 for (int i = 0; i < DecoderList.GetSize(); i++) { |
360 int estimated_size = | 360 int estimated_size = |
361 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0; | 361 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0; |
362 CFX_ByteString decoder = DecoderList[i]; | 362 CFX_ByteString decoder = DecoderList[i]; |
363 // Use ToDictionary here because we can push NULL into the ParamList. | 363 // Use ToDictionary here because we can push NULL into the ParamList. |
364 CPDF_Dictionary* pParam = | 364 CPDF_Dictionary* pParam = |
365 ToDictionary(static_cast<CPDF_Object*>(ParamList[i])); | 365 ToDictionary(static_cast<CPDF_Object*>(ParamList[i])); |
366 uint8_t* new_buf = NULL; | 366 uint8_t* new_buf = nullptr; |
367 FX_DWORD new_size = (FX_DWORD)-1; | 367 FX_DWORD new_size = (FX_DWORD)-1; |
368 int offset = -1; | 368 int offset = -1; |
369 if (decoder == FX_BSTRC("FlateDecode") || decoder == FX_BSTRC("Fl")) { | 369 if (decoder == FX_BSTRC("FlateDecode") || decoder == FX_BSTRC("Fl")) { |
370 if (bImageAcc && i == DecoderList.GetSize() - 1) { | 370 if (bImageAcc && i == DecoderList.GetSize() - 1) { |
371 ImageEncoding = FX_BSTRC("FlateDecode"); | 371 ImageEncoding = FX_BSTRC("FlateDecode"); |
372 dest_buf = (uint8_t*)last_buf; | 372 dest_buf = (uint8_t*)last_buf; |
373 dest_size = last_size; | 373 dest_size = last_size; |
374 pImageParms = pParam; | 374 pImageParms = pParam; |
375 return TRUE; | 375 return TRUE; |
376 } | 376 } |
(...skipping 11 matching lines...) Expand all Loading... |
388 } else if (decoder == FX_BSTRC("RunLengthDecode") || | 388 } else if (decoder == FX_BSTRC("RunLengthDecode") || |
389 decoder == FX_BSTRC("RL")) { | 389 decoder == FX_BSTRC("RL")) { |
390 if (bImageAcc && i == DecoderList.GetSize() - 1) { | 390 if (bImageAcc && i == DecoderList.GetSize() - 1) { |
391 ImageEncoding = FX_BSTRC("RunLengthDecode"); | 391 ImageEncoding = FX_BSTRC("RunLengthDecode"); |
392 dest_buf = (uint8_t*)last_buf; | 392 dest_buf = (uint8_t*)last_buf; |
393 dest_size = last_size; | 393 dest_size = last_size; |
394 pImageParms = pParam; | 394 pImageParms = pParam; |
395 return TRUE; | 395 return TRUE; |
396 } | 396 } |
397 offset = RunLengthDecode(last_buf, last_size, new_buf, new_size); | 397 offset = RunLengthDecode(last_buf, last_size, new_buf, new_size); |
| 398 } else if (decoder == FX_BSTRC("Crypt")) { |
| 399 continue; |
398 } else { | 400 } else { |
| 401 // If we get here, assume it's an image decoder. |
399 if (decoder == FX_BSTRC("DCT")) { | 402 if (decoder == FX_BSTRC("DCT")) { |
400 decoder = "DCTDecode"; | 403 decoder = "DCTDecode"; |
401 } else if (decoder == FX_BSTRC("CCF")) { | 404 } else if (decoder == FX_BSTRC("CCF")) { |
402 decoder = "CCITTFaxDecode"; | 405 decoder = "CCITTFaxDecode"; |
403 } else if (decoder == FX_BSTRC("Crypt")) { | |
404 continue; | |
405 } | 406 } |
406 ImageEncoding = decoder; | 407 ImageEncoding = decoder; |
407 pImageParms = pParam; | 408 pImageParms = pParam; |
408 dest_buf = (uint8_t*)last_buf; | 409 dest_buf = (uint8_t*)last_buf; |
409 dest_size = last_size; | 410 dest_size = last_size; |
| 411 if (CPDF_Array* pDecoders = pDecoder->AsArray()) |
| 412 pDecoders->RemoveAt(i + 1, pDecoders->GetCount() - i - 1); |
410 return TRUE; | 413 return TRUE; |
411 } | 414 } |
412 if (last_buf != src_buf) { | 415 if (last_buf != src_buf) { |
413 FX_Free(last_buf); | 416 FX_Free(last_buf); |
414 } | 417 } |
415 if (offset == -1) { | 418 if (offset == -1) { |
416 FX_Free(new_buf); | 419 FX_Free(new_buf); |
417 return FALSE; | 420 return FALSE; |
418 } | 421 } |
419 last_buf = new_buf; | 422 last_buf = new_buf; |
420 last_size = new_size; | 423 last_size = new_size; |
421 } | 424 } |
422 ImageEncoding = ""; | 425 ImageEncoding = ""; |
423 pImageParms = NULL; | 426 pImageParms = nullptr; |
424 dest_buf = last_buf; | 427 dest_buf = last_buf; |
425 dest_size = last_size; | 428 dest_size = last_size; |
426 return TRUE; | 429 return TRUE; |
427 } | 430 } |
428 CFX_WideString PDF_DecodeText(const uint8_t* src_data, | 431 CFX_WideString PDF_DecodeText(const uint8_t* src_data, |
429 FX_DWORD src_len, | 432 FX_DWORD src_len, |
430 CFX_CharMap* pCharMap) { | 433 CFX_CharMap* pCharMap) { |
431 CFX_WideString result; | 434 CFX_WideString result; |
432 if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) || | 435 if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) || |
433 (src_data[0] == 0xff && src_data[1] == 0xfe))) { | 436 (src_data[0] == 0xff && src_data[1] == 0xfe))) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 FX_DWORD src_size, | 577 FX_DWORD src_size, |
575 uint8_t*& dest_buf, | 578 uint8_t*& dest_buf, |
576 FX_DWORD& dest_size) { | 579 FX_DWORD& dest_size) { |
577 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 580 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
578 if (pEncoders) { | 581 if (pEncoders) { |
579 return pEncoders->GetFlateModule()->FlateOrLZWDecode( | 582 return pEncoders->GetFlateModule()->FlateOrLZWDecode( |
580 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 583 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
581 } | 584 } |
582 return 0; | 585 return 0; |
583 } | 586 } |
OLD | NEW |