Chromium Code Reviews| 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 #include "../../../include/fpdfapi/fpdf_parser.h" | 8 #include "../../../include/fpdfapi/fpdf_parser.h" |
| 9 #include "../../../include/fpdfapi/fpdf_module.h" | 9 #include "../../../include/fpdfapi/fpdf_module.h" |
| 10 #include "../../../include/fxcodec/fx_codec.h" | 10 #include "../../../include/fxcodec/fx_codec.h" |
| 11 #include "../../../include/fxcrt/fx_ext.h" | |
| 11 | 12 |
| 12 #define _STREAM_MAX_SIZE_ 20 * 1024 * 1024 | 13 #define _STREAM_MAX_SIZE_ 20 * 1024 * 1024 |
| 13 | 14 |
| 14 const FX_WORD PDFDocEncoding[256] = { | 15 const FX_WORD PDFDocEncoding[256] = { |
| 15 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, | 16 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, |
| 16 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, | 17 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011, |
| 17 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x02d8, 0x02c7, 0x02c6, | 18 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x02d8, 0x02c7, 0x02c6, |
| 18 0x02d9, 0x02dd, 0x02db, 0x02da, 0x02dc, 0x0020, 0x0021, 0x0022, 0x0023, | 19 0x02d9, 0x02dd, 0x02db, 0x02da, 0x02dc, 0x0020, 0x0021, 0x0022, 0x0023, |
| 19 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, | 20 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, |
| 20 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, | 21 0x002d, 0x002e, 0x002f, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 } | 111 } |
| 111 for (i = 0; i < state - 1; i++) { | 112 for (i = 0; i < state - 1; i++) { |
| 112 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); | 113 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 if (pos < src_size && src_buf[pos] == '>') { | 116 if (pos < src_size && src_buf[pos] == '>') { |
| 116 pos++; | 117 pos++; |
| 117 } | 118 } |
| 118 return pos; | 119 return pos; |
| 119 } | 120 } |
| 120 FX_DWORD _HexDecode(const uint8_t* src_buf, | 121 FX_DWORD _HexDecode(const uint8_t* src_buf, |
|
Tom Sepez
2015/10/29 19:28:31
test
dsinclair
2015/11/03 15:59:02
https://codereview.chromium.org/1410873009/
| |
| 121 FX_DWORD src_size, | 122 FX_DWORD src_size, |
| 122 uint8_t*& dest_buf, | 123 uint8_t*& dest_buf, |
| 123 FX_DWORD& dest_size) { | 124 FX_DWORD& dest_size) { |
| 124 FX_DWORD i; | 125 FX_DWORD i; |
| 125 for (i = 0; i < src_size; i++) | 126 for (i = 0; i < src_size; i++) |
| 126 if (src_buf[i] == '>') { | 127 if (src_buf[i] == '>') { |
| 127 break; | 128 break; |
| 128 } | 129 } |
| 129 dest_buf = FX_Alloc(uint8_t, i / 2 + 1); | 130 dest_buf = FX_Alloc(uint8_t, i / 2 + 1); |
| 130 dest_size = 0; | 131 dest_size = 0; |
| 131 FX_BOOL bFirstDigit = TRUE; | 132 FX_BOOL bFirstDigit = TRUE; |
| 132 for (i = 0; i < src_size; i++) { | 133 for (i = 0; i < src_size; i++) { |
| 133 uint8_t ch = src_buf[i]; | 134 uint8_t ch = src_buf[i]; |
| 134 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') | 135 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') |
| 135 continue; | 136 continue; |
| 136 | 137 |
| 137 int digit; | 138 int digit; |
| 138 if (ch <= '9' && ch >= '0') { | 139 if (std::isxdigit(ch)) { |
| 139 digit = ch - '0'; | 140 digit = HexCharToDigit(ch); |
| 140 } else if (ch <= 'f' && ch >= 'a') { | |
| 141 digit = ch - 'a' + 10; | |
| 142 } else if (ch <= 'F' && ch >= 'A') { | |
| 143 digit = ch - 'A' + 10; | |
| 144 } else if (ch == '>') { | 141 } else if (ch == '>') { |
| 145 i++; | 142 i++; |
| 146 break; | 143 break; |
| 147 } else { | 144 } else { |
| 148 continue; | 145 continue; |
| 149 } | 146 } |
| 150 if (bFirstDigit) { | 147 |
| 148 if (bFirstDigit) | |
| 151 dest_buf[dest_size] = digit * 16; | 149 dest_buf[dest_size] = digit * 16; |
| 152 } else { | 150 else |
| 153 dest_buf[dest_size++] += digit; | 151 dest_buf[dest_size++] += digit; |
| 154 } | 152 |
| 155 bFirstDigit = !bFirstDigit; | 153 bFirstDigit = !bFirstDigit; |
| 156 } | 154 } |
| 157 if (!bFirstDigit) { | 155 if (!bFirstDigit) { |
| 158 dest_size++; | 156 dest_size++; |
| 159 } | 157 } |
| 160 return i; | 158 return i; |
| 161 } | 159 } |
| 162 FX_DWORD RunLengthDecode(const uint8_t* src_buf, | 160 FX_DWORD RunLengthDecode(const uint8_t* src_buf, |
| 163 FX_DWORD src_size, | 161 FX_DWORD src_size, |
| 164 uint8_t*& dest_buf, | 162 uint8_t*& dest_buf, |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 FX_DWORD src_size, | 571 FX_DWORD src_size, |
| 574 uint8_t*& dest_buf, | 572 uint8_t*& dest_buf, |
| 575 FX_DWORD& dest_size) { | 573 FX_DWORD& dest_size) { |
| 576 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 574 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
| 577 if (pEncoders) { | 575 if (pEncoders) { |
| 578 return pEncoders->GetFlateModule()->FlateOrLZWDecode( | 576 return pEncoders->GetFlateModule()->FlateOrLZWDecode( |
| 579 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 577 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
| 580 } | 578 } |
| 581 return 0; | 579 return 0; |
| 582 } | 580 } |
| OLD | NEW |