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 "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | 7 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
8 | 8 |
9 #include <limits.h> | 9 #include <limits.h> |
| 10 #include <utility> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h" | 13 #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
15 #include "core/fpdfapi/include/cpdf_modulemgr.h" | 16 #include "core/fpdfapi/include/cpdf_modulemgr.h" |
16 #include "core/fxcodec/include/fx_codec.h" | 17 #include "core/fxcodec/include/fx_codec.h" |
17 #include "core/fxcrt/include/fx_ext.h" | 18 #include "core/fxcrt/include/fx_ext.h" |
18 #include "third_party/base/stl_util.h" | 19 #include "third_party/base/stl_util.h" |
19 | 20 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 CFX_ByteString& ImageEncoding, | 336 CFX_ByteString& ImageEncoding, |
336 CPDF_Dictionary*& pImageParms, | 337 CPDF_Dictionary*& pImageParms, |
337 uint32_t last_estimated_size, | 338 uint32_t last_estimated_size, |
338 FX_BOOL bImageAcc) { | 339 FX_BOOL bImageAcc) { |
339 CPDF_Object* pDecoder = pDict ? pDict->GetDirectObjectBy("Filter") : nullptr; | 340 CPDF_Object* pDecoder = pDict ? pDict->GetDirectObjectBy("Filter") : nullptr; |
340 if (!pDecoder || (!pDecoder->IsArray() && !pDecoder->IsName())) | 341 if (!pDecoder || (!pDecoder->IsArray() && !pDecoder->IsName())) |
341 return FALSE; | 342 return FALSE; |
342 | 343 |
343 CPDF_Object* pParams = | 344 CPDF_Object* pParams = |
344 pDict ? pDict->GetDirectObjectBy("DecodeParms") : nullptr; | 345 pDict ? pDict->GetDirectObjectBy("DecodeParms") : nullptr; |
345 std::vector<CFX_ByteString> DecoderList; | 346 |
346 CFX_ArrayTemplate<CPDF_Object*> ParamList; | 347 std::vector<std::pair<CFX_ByteString, CPDF_Object*>> DecoderArray; |
347 if (CPDF_Array* pDecoders = pDecoder->AsArray()) { | 348 if (CPDF_Array* pDecoders = pDecoder->AsArray()) { |
348 CPDF_Array* pParamsArray = ToArray(pParams); | 349 CPDF_Array* pParamsArray = ToArray(pParams); |
349 if (!pParamsArray) | |
350 pParams = nullptr; | |
351 | |
352 for (size_t i = 0; i < pDecoders->GetCount(); i++) { | 350 for (size_t i = 0; i < pDecoders->GetCount(); i++) { |
353 DecoderList.push_back(pDecoders->GetStringAt(i)); | 351 DecoderArray.push_back( |
354 ParamList.Add(pParams ? pParamsArray->GetDictAt(i) : nullptr); | 352 {pDecoders->GetStringAt(i), |
| 353 pParamsArray ? pParamsArray->GetDictAt(i) : nullptr}); |
355 } | 354 } |
356 } else { | 355 } else { |
357 DecoderList.push_back(pDecoder->GetString()); | 356 DecoderArray.push_back( |
358 ParamList.Add(pParams ? pParams->GetDict() : nullptr); | 357 {pDecoder->GetString(), pParams ? pParams->GetDict() : nullptr}); |
359 } | 358 } |
360 uint8_t* last_buf = (uint8_t*)src_buf; | 359 uint8_t* last_buf = const_cast<uint8_t*>(src_buf); |
361 uint32_t last_size = src_size; | 360 uint32_t last_size = src_size; |
362 int nSize = pdfium::CollectionSize<int>(DecoderList); | 361 int nSize = pdfium::CollectionSize<int>(DecoderArray); |
363 for (int i = 0; i < nSize; i++) { | 362 for (int i = 0; i < nSize; i++) { |
364 int estimated_size = i == nSize - 1 ? last_estimated_size : 0; | 363 int estimated_size = i == nSize - 1 ? last_estimated_size : 0; |
365 CFX_ByteString decoder = DecoderList[i]; | 364 CFX_ByteString decoder = DecoderArray[i].first; |
366 // Use ToDictionary here because we can push nullptr into the ParamList. | 365 CPDF_Dictionary* pParam = ToDictionary(DecoderArray[i].second); |
367 CPDF_Dictionary* pParam = ToDictionary(ParamList[i]); | |
368 uint8_t* new_buf = nullptr; | 366 uint8_t* new_buf = nullptr; |
369 uint32_t new_size = (uint32_t)-1; | 367 uint32_t new_size = (uint32_t)-1; |
370 int offset = -1; | 368 int offset = -1; |
371 if (decoder == "FlateDecode" || decoder == "Fl") { | 369 if (decoder == "FlateDecode" || decoder == "Fl") { |
372 if (bImageAcc && i == nSize - 1) { | 370 if (bImageAcc && i == nSize - 1) { |
373 ImageEncoding = "FlateDecode"; | 371 ImageEncoding = "FlateDecode"; |
374 dest_buf = (uint8_t*)last_buf; | 372 dest_buf = (uint8_t*)last_buf; |
375 dest_size = last_size; | 373 dest_size = last_size; |
376 pImageParms = pParam; | 374 pImageParms = pParam; |
377 return TRUE; | 375 return TRUE; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 uint32_t src_size, | 578 uint32_t src_size, |
581 uint8_t*& dest_buf, | 579 uint8_t*& dest_buf, |
582 uint32_t& dest_size) { | 580 uint32_t& dest_size) { |
583 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 581 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
584 if (pEncoders) { | 582 if (pEncoders) { |
585 return pEncoders->GetFlateModule()->FlateOrLZWDecode( | 583 return pEncoders->GetFlateModule()->FlateOrLZWDecode( |
586 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 584 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
587 } | 585 } |
588 return 0; | 586 return 0; |
589 } | 587 } |
OLD | NEW |