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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, | 42 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, |
43 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x00f0, 0x00f1, 0x00f2, | 43 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x00f0, 0x00f1, 0x00f2, |
44 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, | 44 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, |
45 0x00fc, 0x00fd, 0x00fe, 0x00ff}; | 45 0x00fc, 0x00fd, 0x00fe, 0x00ff}; |
46 | 46 |
47 FX_DWORD A85Decode(const uint8_t* src_buf, | 47 FX_DWORD A85Decode(const uint8_t* src_buf, |
48 FX_DWORD src_size, | 48 FX_DWORD src_size, |
49 uint8_t*& dest_buf, | 49 uint8_t*& dest_buf, |
50 FX_DWORD& dest_size) { | 50 FX_DWORD& dest_size) { |
51 dest_size = 0; | 51 dest_size = 0; |
52 dest_buf = NULL; | 52 dest_buf = nullptr; |
53 if (src_size == 0) { | 53 if (src_size == 0) { |
54 return 0; | 54 return 0; |
55 } | 55 } |
56 FX_DWORD zcount = 0; | 56 FX_DWORD zcount = 0; |
57 FX_DWORD pos = 0; | 57 FX_DWORD pos = 0; |
58 while (pos < src_size) { | 58 while (pos < src_size) { |
59 uint8_t ch = src_buf[pos]; | 59 uint8_t ch = src_buf[pos]; |
60 if (ch < '!' && ch != '\n' && ch != '\r' && ch != ' ' && ch != '\t') { | 60 if (ch < '!' && ch != '\n' && ch != '\r' && ch != ' ' && ch != '\t') { |
61 break; | 61 break; |
62 } | 62 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 K = pParams->GetIntegerBy("K"); | 234 K = pParams->GetIntegerBy("K"); |
235 EndOfLine = pParams->GetIntegerBy("EndOfLine"); | 235 EndOfLine = pParams->GetIntegerBy("EndOfLine"); |
236 ByteAlign = pParams->GetIntegerBy("EncodedByteAlign"); | 236 ByteAlign = pParams->GetIntegerBy("EncodedByteAlign"); |
237 BlackIs1 = pParams->GetIntegerBy("BlackIs1"); | 237 BlackIs1 = pParams->GetIntegerBy("BlackIs1"); |
238 Columns = pParams->GetIntegerBy("Columns", 1728); | 238 Columns = pParams->GetIntegerBy("Columns", 1728); |
239 Rows = pParams->GetIntegerBy("Rows"); | 239 Rows = pParams->GetIntegerBy("Rows"); |
240 if (Rows > USHRT_MAX) { | 240 if (Rows > USHRT_MAX) { |
241 Rows = 0; | 241 Rows = 0; |
242 } | 242 } |
243 if (Columns <= 0 || Rows < 0 || Columns > USHRT_MAX || Rows > USHRT_MAX) { | 243 if (Columns <= 0 || Rows < 0 || Columns > USHRT_MAX || Rows > USHRT_MAX) { |
244 return NULL; | 244 return nullptr; |
245 } | 245 } |
246 } | 246 } |
247 return CPDF_ModuleMgr::Get()->GetFaxModule()->CreateDecoder( | 247 return CPDF_ModuleMgr::Get()->GetFaxModule()->CreateDecoder( |
248 src_buf, src_size, width, height, K, EndOfLine, ByteAlign, BlackIs1, | 248 src_buf, src_size, width, height, K, EndOfLine, ByteAlign, BlackIs1, |
249 Columns, Rows); | 249 Columns, Rows); |
250 } | 250 } |
251 static FX_BOOL CheckFlateDecodeParams(int Colors, | 251 static FX_BOOL CheckFlateDecodeParams(int Colors, |
252 int BitsPerComponent, | 252 int BitsPerComponent, |
253 int Columns) { | 253 int Columns) { |
254 if (Columns < 0) { | 254 if (Columns < 0) { |
(...skipping 23 matching lines...) Expand all Loading... |
278 int bpc, | 278 int bpc, |
279 const CPDF_Dictionary* pParams) { | 279 const CPDF_Dictionary* pParams) { |
280 int predictor = 0; | 280 int predictor = 0; |
281 int Colors = 0, BitsPerComponent = 0, Columns = 0; | 281 int Colors = 0, BitsPerComponent = 0, Columns = 0; |
282 if (pParams) { | 282 if (pParams) { |
283 predictor = pParams->GetIntegerBy("Predictor"); | 283 predictor = pParams->GetIntegerBy("Predictor"); |
284 Colors = pParams->GetIntegerBy("Colors", 1); | 284 Colors = pParams->GetIntegerBy("Colors", 1); |
285 BitsPerComponent = pParams->GetIntegerBy("BitsPerComponent", 8); | 285 BitsPerComponent = pParams->GetIntegerBy("BitsPerComponent", 8); |
286 Columns = pParams->GetIntegerBy("Columns", 1); | 286 Columns = pParams->GetIntegerBy("Columns", 1); |
287 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { | 287 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { |
288 return NULL; | 288 return nullptr; |
289 } | 289 } |
290 } | 290 } |
291 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder( | 291 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder( |
292 src_buf, src_size, width, height, nComps, bpc, predictor, Colors, | 292 src_buf, src_size, width, height, nComps, bpc, predictor, Colors, |
293 BitsPerComponent, Columns); | 293 BitsPerComponent, Columns); |
294 } | 294 } |
295 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, | 295 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, |
296 const uint8_t* src_buf, | 296 const uint8_t* src_buf, |
297 FX_DWORD src_size, | 297 FX_DWORD src_size, |
298 CPDF_Dictionary* pParams, | 298 CPDF_Dictionary* pParams, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } else { | 346 } else { |
347 DecoderList.Add(pDecoder->GetConstString()); | 347 DecoderList.Add(pDecoder->GetConstString()); |
348 ParamList.Add(pParams ? pParams->GetDict() : nullptr); | 348 ParamList.Add(pParams ? pParams->GetDict() : nullptr); |
349 } | 349 } |
350 uint8_t* last_buf = (uint8_t*)src_buf; | 350 uint8_t* last_buf = (uint8_t*)src_buf; |
351 FX_DWORD last_size = src_size; | 351 FX_DWORD last_size = src_size; |
352 for (int i = 0; i < DecoderList.GetSize(); i++) { | 352 for (int i = 0; i < DecoderList.GetSize(); i++) { |
353 int estimated_size = | 353 int estimated_size = |
354 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0; | 354 i == DecoderList.GetSize() - 1 ? last_estimated_size : 0; |
355 CFX_ByteString decoder = DecoderList[i]; | 355 CFX_ByteString decoder = DecoderList[i]; |
356 // Use ToDictionary here because we can push NULL into the ParamList. | 356 // Use ToDictionary here because we can push nullptr into the ParamList. |
357 CPDF_Dictionary* pParam = ToDictionary(ParamList[i]); | 357 CPDF_Dictionary* pParam = ToDictionary(ParamList[i]); |
358 uint8_t* new_buf = nullptr; | 358 uint8_t* new_buf = nullptr; |
359 FX_DWORD new_size = (FX_DWORD)-1; | 359 FX_DWORD new_size = (FX_DWORD)-1; |
360 int offset = -1; | 360 int offset = -1; |
361 if (decoder == "FlateDecode" || decoder == "Fl") { | 361 if (decoder == "FlateDecode" || decoder == "Fl") { |
362 if (bImageAcc && i == DecoderList.GetSize() - 1) { | 362 if (bImageAcc && i == DecoderList.GetSize() - 1) { |
363 ImageEncoding = "FlateDecode"; | 363 ImageEncoding = "FlateDecode"; |
364 dest_buf = (uint8_t*)last_buf; | 364 dest_buf = (uint8_t*)last_buf; |
365 dest_size = last_size; | 365 dest_size = last_size; |
366 pImageParms = pParam; | 366 pImageParms = pParam; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 FX_DWORD src_size, | 566 FX_DWORD src_size, |
567 uint8_t*& dest_buf, | 567 uint8_t*& dest_buf, |
568 FX_DWORD& dest_size) { | 568 FX_DWORD& dest_size) { |
569 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 569 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
570 if (pEncoders) { | 570 if (pEncoders) { |
571 return pEncoders->GetFlateModule()->FlateOrLZWDecode( | 571 return pEncoders->GetFlateModule()->FlateOrLZWDecode( |
572 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 572 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
573 } | 573 } |
574 return 0; | 574 return 0; |
575 } | 575 } |
OLD | NEW |