| 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 <vector> | 10 #include <vector> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, | 43 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, |
| 44 0x00bd, 0x00be, 0x00bf, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, | 44 0x00bd, 0x00be, 0x00bf, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, |
| 45 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, | 45 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, |
| 46 0x00cf, 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, | 46 0x00cf, 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, |
| 47 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, 0x00e0, | 47 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, 0x00e0, |
| 48 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, | 48 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, |
| 49 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x00f0, 0x00f1, 0x00f2, | 49 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x00f0, 0x00f1, 0x00f2, |
| 50 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, | 50 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, |
| 51 0x00fc, 0x00fd, 0x00fe, 0x00ff}; | 51 0x00fc, 0x00fd, 0x00fe, 0x00ff}; |
| 52 | 52 |
| 53 FX_DWORD A85Decode(const uint8_t* src_buf, | 53 uint32_t A85Decode(const uint8_t* src_buf, |
| 54 FX_DWORD src_size, | 54 uint32_t src_size, |
| 55 uint8_t*& dest_buf, | 55 uint8_t*& dest_buf, |
| 56 FX_DWORD& dest_size) { | 56 uint32_t& dest_size) { |
| 57 dest_size = 0; | 57 dest_size = 0; |
| 58 dest_buf = nullptr; | 58 dest_buf = nullptr; |
| 59 if (src_size == 0) | 59 if (src_size == 0) |
| 60 return 0; | 60 return 0; |
| 61 | 61 |
| 62 // Count legal characters and zeros. | 62 // Count legal characters and zeros. |
| 63 FX_DWORD zcount = 0; | 63 uint32_t zcount = 0; |
| 64 FX_DWORD pos = 0; | 64 uint32_t pos = 0; |
| 65 while (pos < src_size) { | 65 while (pos < src_size) { |
| 66 uint8_t ch = src_buf[pos]; | 66 uint8_t ch = src_buf[pos]; |
| 67 if (ch == 'z') { | 67 if (ch == 'z') { |
| 68 zcount++; | 68 zcount++; |
| 69 } else if ((ch < '!' || ch > 'u') && !PDFCharIsLineEnding(ch) && | 69 } else if ((ch < '!' || ch > 'u') && !PDFCharIsLineEnding(ch) && |
| 70 ch != ' ' && ch != '\t') { | 70 ch != ' ' && ch != '\t') { |
| 71 break; | 71 break; |
| 72 } | 72 } |
| 73 pos++; | 73 pos++; |
| 74 } | 74 } |
| 75 // No content to decode. | 75 // No content to decode. |
| 76 if (pos == 0) | 76 if (pos == 0) |
| 77 return 0; | 77 return 0; |
| 78 | 78 |
| 79 // Count the space needed to contain non-zero characters. The encoding ratio | 79 // Count the space needed to contain non-zero characters. The encoding ratio |
| 80 // of Ascii85 is 4:5. | 80 // of Ascii85 is 4:5. |
| 81 FX_DWORD space_for_non_zeroes = (pos - zcount) / 5 * 4 + 4; | 81 uint32_t space_for_non_zeroes = (pos - zcount) / 5 * 4 + 4; |
| 82 if (zcount > (UINT_MAX - space_for_non_zeroes) / 4) { | 82 if (zcount > (UINT_MAX - space_for_non_zeroes) / 4) { |
| 83 return (FX_DWORD)-1; | 83 return (uint32_t)-1; |
| 84 } | 84 } |
| 85 dest_buf = FX_Alloc(uint8_t, zcount * 4 + space_for_non_zeroes); | 85 dest_buf = FX_Alloc(uint8_t, zcount * 4 + space_for_non_zeroes); |
| 86 size_t state = 0; | 86 size_t state = 0; |
| 87 uint32_t res = 0; | 87 uint32_t res = 0; |
| 88 pos = dest_size = 0; | 88 pos = dest_size = 0; |
| 89 while (pos < src_size) { | 89 while (pos < src_size) { |
| 90 uint8_t ch = src_buf[pos++]; | 90 uint8_t ch = src_buf[pos++]; |
| 91 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') | 91 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') |
| 92 continue; | 92 continue; |
| 93 | 93 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 116 for (size_t i = state; i < 5; i++) | 116 for (size_t i = state; i < 5; i++) |
| 117 res = res * 85 + 84; | 117 res = res * 85 + 84; |
| 118 for (size_t i = 0; i < state - 1; i++) | 118 for (size_t i = 0; i < state - 1; i++) |
| 119 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); | 119 dest_buf[dest_size++] = (uint8_t)(res >> (3 - i) * 8); |
| 120 } | 120 } |
| 121 if (pos < src_size && src_buf[pos] == '>') | 121 if (pos < src_size && src_buf[pos] == '>') |
| 122 pos++; | 122 pos++; |
| 123 return pos; | 123 return pos; |
| 124 } | 124 } |
| 125 | 125 |
| 126 FX_DWORD HexDecode(const uint8_t* src_buf, | 126 uint32_t HexDecode(const uint8_t* src_buf, |
| 127 FX_DWORD src_size, | 127 uint32_t src_size, |
| 128 uint8_t*& dest_buf, | 128 uint8_t*& dest_buf, |
| 129 FX_DWORD& dest_size) { | 129 uint32_t& dest_size) { |
| 130 dest_size = 0; | 130 dest_size = 0; |
| 131 if (src_size == 0) { | 131 if (src_size == 0) { |
| 132 dest_buf = nullptr; | 132 dest_buf = nullptr; |
| 133 return 0; | 133 return 0; |
| 134 } | 134 } |
| 135 | 135 |
| 136 FX_DWORD i = 0; | 136 uint32_t i = 0; |
| 137 // Find the end of data. | 137 // Find the end of data. |
| 138 while (i < src_size && src_buf[i] != '>') | 138 while (i < src_size && src_buf[i] != '>') |
| 139 i++; | 139 i++; |
| 140 | 140 |
| 141 dest_buf = FX_Alloc(uint8_t, i / 2 + 1); | 141 dest_buf = FX_Alloc(uint8_t, i / 2 + 1); |
| 142 bool bFirst = true; | 142 bool bFirst = true; |
| 143 for (i = 0; i < src_size; i++) { | 143 for (i = 0; i < src_size; i++) { |
| 144 uint8_t ch = src_buf[i]; | 144 uint8_t ch = src_buf[i]; |
| 145 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') | 145 if (PDFCharIsLineEnding(ch) || ch == ' ' || ch == '\t') |
| 146 continue; | 146 continue; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 158 else | 158 else |
| 159 dest_buf[dest_size++] += digit; | 159 dest_buf[dest_size++] += digit; |
| 160 | 160 |
| 161 bFirst = !bFirst; | 161 bFirst = !bFirst; |
| 162 } | 162 } |
| 163 if (!bFirst) | 163 if (!bFirst) |
| 164 dest_size++; | 164 dest_size++; |
| 165 return i; | 165 return i; |
| 166 } | 166 } |
| 167 | 167 |
| 168 FX_DWORD RunLengthDecode(const uint8_t* src_buf, | 168 uint32_t RunLengthDecode(const uint8_t* src_buf, |
| 169 FX_DWORD src_size, | 169 uint32_t src_size, |
| 170 uint8_t*& dest_buf, | 170 uint8_t*& dest_buf, |
| 171 FX_DWORD& dest_size) { | 171 uint32_t& dest_size) { |
| 172 FX_DWORD i = 0; | 172 uint32_t i = 0; |
| 173 FX_DWORD old; | 173 uint32_t old; |
| 174 dest_size = 0; | 174 dest_size = 0; |
| 175 while (i < src_size) { | 175 while (i < src_size) { |
| 176 if (src_buf[i] < 128) { | 176 if (src_buf[i] < 128) { |
| 177 old = dest_size; | 177 old = dest_size; |
| 178 dest_size += src_buf[i] + 1; | 178 dest_size += src_buf[i] + 1; |
| 179 if (dest_size < old) { | 179 if (dest_size < old) { |
| 180 return static_cast<FX_DWORD>(-1); | 180 return static_cast<uint32_t>(-1); |
| 181 } | 181 } |
| 182 i += src_buf[i] + 2; | 182 i += src_buf[i] + 2; |
| 183 } else if (src_buf[i] > 128) { | 183 } else if (src_buf[i] > 128) { |
| 184 old = dest_size; | 184 old = dest_size; |
| 185 dest_size += 257 - src_buf[i]; | 185 dest_size += 257 - src_buf[i]; |
| 186 if (dest_size < old) { | 186 if (dest_size < old) { |
| 187 return static_cast<FX_DWORD>(-1); | 187 return static_cast<uint32_t>(-1); |
| 188 } | 188 } |
| 189 i += 2; | 189 i += 2; |
| 190 } else { | 190 } else { |
| 191 break; | 191 break; |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 if (dest_size >= _STREAM_MAX_SIZE_) { | 194 if (dest_size >= _STREAM_MAX_SIZE_) { |
| 195 return static_cast<FX_DWORD>(-1); | 195 return static_cast<uint32_t>(-1); |
| 196 } | 196 } |
| 197 dest_buf = FX_Alloc(uint8_t, dest_size); | 197 dest_buf = FX_Alloc(uint8_t, dest_size); |
| 198 i = 0; | 198 i = 0; |
| 199 int dest_count = 0; | 199 int dest_count = 0; |
| 200 while (i < src_size) { | 200 while (i < src_size) { |
| 201 if (src_buf[i] < 128) { | 201 if (src_buf[i] < 128) { |
| 202 FX_DWORD copy_len = src_buf[i] + 1; | 202 uint32_t copy_len = src_buf[i] + 1; |
| 203 FX_DWORD buf_left = src_size - i - 1; | 203 uint32_t buf_left = src_size - i - 1; |
| 204 if (buf_left < copy_len) { | 204 if (buf_left < copy_len) { |
| 205 FX_DWORD delta = copy_len - buf_left; | 205 uint32_t delta = copy_len - buf_left; |
| 206 copy_len = buf_left; | 206 copy_len = buf_left; |
| 207 FXSYS_memset(dest_buf + dest_count + copy_len, '\0', delta); | 207 FXSYS_memset(dest_buf + dest_count + copy_len, '\0', delta); |
| 208 } | 208 } |
| 209 FXSYS_memcpy(dest_buf + dest_count, src_buf + i + 1, copy_len); | 209 FXSYS_memcpy(dest_buf + dest_count, src_buf + i + 1, copy_len); |
| 210 dest_count += src_buf[i] + 1; | 210 dest_count += src_buf[i] + 1; |
| 211 i += src_buf[i] + 2; | 211 i += src_buf[i] + 2; |
| 212 } else if (src_buf[i] > 128) { | 212 } else if (src_buf[i] > 128) { |
| 213 int fill = 0; | 213 int fill = 0; |
| 214 if (i < src_size - 1) { | 214 if (i < src_size - 1) { |
| 215 fill = src_buf[i + 1]; | 215 fill = src_buf[i + 1]; |
| 216 } | 216 } |
| 217 FXSYS_memset(dest_buf + dest_count, fill, 257 - src_buf[i]); | 217 FXSYS_memset(dest_buf + dest_count, fill, 257 - src_buf[i]); |
| 218 dest_count += 257 - src_buf[i]; | 218 dest_count += 257 - src_buf[i]; |
| 219 i += 2; | 219 i += 2; |
| 220 } else { | 220 } else { |
| 221 break; | 221 break; |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 FX_DWORD ret = i + 1; | 224 uint32_t ret = i + 1; |
| 225 if (ret > src_size) { | 225 if (ret > src_size) { |
| 226 ret = src_size; | 226 ret = src_size; |
| 227 } | 227 } |
| 228 return ret; | 228 return ret; |
| 229 } | 229 } |
| 230 | 230 |
| 231 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( | 231 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( |
| 232 const uint8_t* src_buf, | 232 const uint8_t* src_buf, |
| 233 FX_DWORD src_size, | 233 uint32_t src_size, |
| 234 int width, | 234 int width, |
| 235 int height, | 235 int height, |
| 236 const CPDF_Dictionary* pParams) { | 236 const CPDF_Dictionary* pParams) { |
| 237 int K = 0; | 237 int K = 0; |
| 238 FX_BOOL EndOfLine = FALSE; | 238 FX_BOOL EndOfLine = FALSE; |
| 239 FX_BOOL ByteAlign = FALSE; | 239 FX_BOOL ByteAlign = FALSE; |
| 240 FX_BOOL BlackIs1 = FALSE; | 240 FX_BOOL BlackIs1 = FALSE; |
| 241 int Columns = 1728; | 241 int Columns = 1728; |
| 242 int Rows = 0; | 242 int Rows = 0; |
| 243 if (pParams) { | 243 if (pParams) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 276 } |
| 277 check *= BitsPerComponent; | 277 check *= BitsPerComponent; |
| 278 if (check > INT_MAX - 7) { | 278 if (check > INT_MAX - 7) { |
| 279 return FALSE; | 279 return FALSE; |
| 280 } | 280 } |
| 281 return TRUE; | 281 return TRUE; |
| 282 } | 282 } |
| 283 | 283 |
| 284 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( | 284 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( |
| 285 const uint8_t* src_buf, | 285 const uint8_t* src_buf, |
| 286 FX_DWORD src_size, | 286 uint32_t src_size, |
| 287 int width, | 287 int width, |
| 288 int height, | 288 int height, |
| 289 int nComps, | 289 int nComps, |
| 290 int bpc, | 290 int bpc, |
| 291 const CPDF_Dictionary* pParams) { | 291 const CPDF_Dictionary* pParams) { |
| 292 int predictor = 0; | 292 int predictor = 0; |
| 293 int Colors = 0, BitsPerComponent = 0, Columns = 0; | 293 int Colors = 0, BitsPerComponent = 0, Columns = 0; |
| 294 if (pParams) { | 294 if (pParams) { |
| 295 predictor = pParams->GetIntegerBy("Predictor"); | 295 predictor = pParams->GetIntegerBy("Predictor"); |
| 296 Colors = pParams->GetIntegerBy("Colors", 1); | 296 Colors = pParams->GetIntegerBy("Colors", 1); |
| 297 BitsPerComponent = pParams->GetIntegerBy("BitsPerComponent", 8); | 297 BitsPerComponent = pParams->GetIntegerBy("BitsPerComponent", 8); |
| 298 Columns = pParams->GetIntegerBy("Columns", 1); | 298 Columns = pParams->GetIntegerBy("Columns", 1); |
| 299 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { | 299 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { |
| 300 return nullptr; | 300 return nullptr; |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder( | 303 return CPDF_ModuleMgr::Get()->GetFlateModule()->CreateDecoder( |
| 304 src_buf, src_size, width, height, nComps, bpc, predictor, Colors, | 304 src_buf, src_size, width, height, nComps, bpc, predictor, Colors, |
| 305 BitsPerComponent, Columns); | 305 BitsPerComponent, Columns); |
| 306 } | 306 } |
| 307 | 307 |
| 308 FX_DWORD FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, | 308 uint32_t FPDFAPI_FlateOrLZWDecode(FX_BOOL bLZW, |
| 309 const uint8_t* src_buf, | 309 const uint8_t* src_buf, |
| 310 FX_DWORD src_size, | 310 uint32_t src_size, |
| 311 CPDF_Dictionary* pParams, | 311 CPDF_Dictionary* pParams, |
| 312 FX_DWORD estimated_size, | 312 uint32_t estimated_size, |
| 313 uint8_t*& dest_buf, | 313 uint8_t*& dest_buf, |
| 314 FX_DWORD& dest_size) { | 314 uint32_t& dest_size) { |
| 315 int predictor = 0; | 315 int predictor = 0; |
| 316 FX_BOOL bEarlyChange = TRUE; | 316 FX_BOOL bEarlyChange = TRUE; |
| 317 int Colors = 0, BitsPerComponent = 0, Columns = 0; | 317 int Colors = 0, BitsPerComponent = 0, Columns = 0; |
| 318 if (pParams) { | 318 if (pParams) { |
| 319 predictor = pParams->GetIntegerBy("Predictor"); | 319 predictor = pParams->GetIntegerBy("Predictor"); |
| 320 bEarlyChange = pParams->GetIntegerBy("EarlyChange", 1); | 320 bEarlyChange = pParams->GetIntegerBy("EarlyChange", 1); |
| 321 Colors = pParams->GetIntegerBy("Colors", 1); | 321 Colors = pParams->GetIntegerBy("Colors", 1); |
| 322 BitsPerComponent = pParams->GetIntegerBy("BitsPerComponent", 8); | 322 BitsPerComponent = pParams->GetIntegerBy("BitsPerComponent", 8); |
| 323 Columns = pParams->GetIntegerBy("Columns", 1); | 323 Columns = pParams->GetIntegerBy("Columns", 1); |
| 324 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { | 324 if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) { |
| 325 return (FX_DWORD)-1; | 325 return (uint32_t)-1; |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode( | 328 return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode( |
| 329 bLZW, src_buf, src_size, bEarlyChange, predictor, Colors, | 329 bLZW, src_buf, src_size, bEarlyChange, predictor, Colors, |
| 330 BitsPerComponent, Columns, estimated_size, dest_buf, dest_size); | 330 BitsPerComponent, Columns, estimated_size, dest_buf, dest_size); |
| 331 } | 331 } |
| 332 | 332 |
| 333 FX_BOOL PDF_DataDecode(const uint8_t* src_buf, | 333 FX_BOOL PDF_DataDecode(const uint8_t* src_buf, |
| 334 FX_DWORD src_size, | 334 uint32_t src_size, |
| 335 const CPDF_Dictionary* pDict, | 335 const CPDF_Dictionary* pDict, |
| 336 uint8_t*& dest_buf, | 336 uint8_t*& dest_buf, |
| 337 FX_DWORD& dest_size, | 337 uint32_t& dest_size, |
| 338 CFX_ByteString& ImageEncoding, | 338 CFX_ByteString& ImageEncoding, |
| 339 CPDF_Dictionary*& pImageParms, | 339 CPDF_Dictionary*& pImageParms, |
| 340 FX_DWORD last_estimated_size, | 340 uint32_t last_estimated_size, |
| 341 FX_BOOL bImageAcc) { | 341 FX_BOOL bImageAcc) { |
| 342 CPDF_Object* pDecoder = pDict ? pDict->GetElementValue("Filter") : nullptr; | 342 CPDF_Object* pDecoder = pDict ? pDict->GetElementValue("Filter") : nullptr; |
| 343 if (!pDecoder || (!pDecoder->IsArray() && !pDecoder->IsName())) | 343 if (!pDecoder || (!pDecoder->IsArray() && !pDecoder->IsName())) |
| 344 return FALSE; | 344 return FALSE; |
| 345 | 345 |
| 346 CPDF_Object* pParams = | 346 CPDF_Object* pParams = |
| 347 pDict ? pDict->GetElementValue("DecodeParms") : nullptr; | 347 pDict ? pDict->GetElementValue("DecodeParms") : nullptr; |
| 348 std::vector<CFX_ByteString> DecoderList; | 348 std::vector<CFX_ByteString> DecoderList; |
| 349 CFX_ArrayTemplate<CPDF_Object*> ParamList; | 349 CFX_ArrayTemplate<CPDF_Object*> ParamList; |
| 350 if (CPDF_Array* pDecoders = pDecoder->AsArray()) { | 350 if (CPDF_Array* pDecoders = pDecoder->AsArray()) { |
| 351 CPDF_Array* pParamsArray = ToArray(pParams); | 351 CPDF_Array* pParamsArray = ToArray(pParams); |
| 352 if (!pParamsArray) | 352 if (!pParamsArray) |
| 353 pParams = nullptr; | 353 pParams = nullptr; |
| 354 | 354 |
| 355 for (FX_DWORD i = 0; i < pDecoders->GetCount(); i++) { | 355 for (uint32_t i = 0; i < pDecoders->GetCount(); i++) { |
| 356 DecoderList.push_back(pDecoders->GetConstStringAt(i)); | 356 DecoderList.push_back(pDecoders->GetConstStringAt(i)); |
| 357 ParamList.Add(pParams ? pParamsArray->GetDictAt(i) : nullptr); | 357 ParamList.Add(pParams ? pParamsArray->GetDictAt(i) : nullptr); |
| 358 } | 358 } |
| 359 } else { | 359 } else { |
| 360 DecoderList.push_back(pDecoder->GetConstString()); | 360 DecoderList.push_back(pDecoder->GetConstString()); |
| 361 ParamList.Add(pParams ? pParams->GetDict() : nullptr); | 361 ParamList.Add(pParams ? pParams->GetDict() : nullptr); |
| 362 } | 362 } |
| 363 uint8_t* last_buf = (uint8_t*)src_buf; | 363 uint8_t* last_buf = (uint8_t*)src_buf; |
| 364 FX_DWORD last_size = src_size; | 364 uint32_t last_size = src_size; |
| 365 int nSize = pdfium::CollectionSize<int>(DecoderList); | 365 int nSize = pdfium::CollectionSize<int>(DecoderList); |
| 366 for (int i = 0; i < nSize; i++) { | 366 for (int i = 0; i < nSize; i++) { |
| 367 int estimated_size = i == nSize - 1 ? last_estimated_size : 0; | 367 int estimated_size = i == nSize - 1 ? last_estimated_size : 0; |
| 368 CFX_ByteString decoder = DecoderList[i]; | 368 CFX_ByteString decoder = DecoderList[i]; |
| 369 // Use ToDictionary here because we can push nullptr into the ParamList. | 369 // Use ToDictionary here because we can push nullptr into the ParamList. |
| 370 CPDF_Dictionary* pParam = ToDictionary(ParamList[i]); | 370 CPDF_Dictionary* pParam = ToDictionary(ParamList[i]); |
| 371 uint8_t* new_buf = nullptr; | 371 uint8_t* new_buf = nullptr; |
| 372 FX_DWORD new_size = (FX_DWORD)-1; | 372 uint32_t new_size = (uint32_t)-1; |
| 373 int offset = -1; | 373 int offset = -1; |
| 374 if (decoder == "FlateDecode" || decoder == "Fl") { | 374 if (decoder == "FlateDecode" || decoder == "Fl") { |
| 375 if (bImageAcc && i == nSize - 1) { | 375 if (bImageAcc && i == nSize - 1) { |
| 376 ImageEncoding = "FlateDecode"; | 376 ImageEncoding = "FlateDecode"; |
| 377 dest_buf = (uint8_t*)last_buf; | 377 dest_buf = (uint8_t*)last_buf; |
| 378 dest_size = last_size; | 378 dest_size = last_size; |
| 379 pImageParms = pParam; | 379 pImageParms = pParam; |
| 380 return TRUE; | 380 return TRUE; |
| 381 } | 381 } |
| 382 offset = FPDFAPI_FlateOrLZWDecode(FALSE, last_buf, last_size, pParam, | 382 offset = FPDFAPI_FlateOrLZWDecode(FALSE, last_buf, last_size, pParam, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 last_buf = new_buf; | 424 last_buf = new_buf; |
| 425 last_size = new_size; | 425 last_size = new_size; |
| 426 } | 426 } |
| 427 ImageEncoding = ""; | 427 ImageEncoding = ""; |
| 428 pImageParms = nullptr; | 428 pImageParms = nullptr; |
| 429 dest_buf = last_buf; | 429 dest_buf = last_buf; |
| 430 dest_size = last_size; | 430 dest_size = last_size; |
| 431 return TRUE; | 431 return TRUE; |
| 432 } | 432 } |
| 433 | 433 |
| 434 CFX_WideString PDF_DecodeText(const uint8_t* src_data, FX_DWORD src_len) { | 434 CFX_WideString PDF_DecodeText(const uint8_t* src_data, uint32_t src_len) { |
| 435 CFX_WideString result; | 435 CFX_WideString result; |
| 436 if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) || | 436 if (src_len >= 2 && ((src_data[0] == 0xfe && src_data[1] == 0xff) || |
| 437 (src_data[0] == 0xff && src_data[1] == 0xfe))) { | 437 (src_data[0] == 0xff && src_data[1] == 0xfe))) { |
| 438 bool bBE = src_data[0] == 0xfe; | 438 bool bBE = src_data[0] == 0xfe; |
| 439 FX_DWORD max_chars = (src_len - 2) / 2; | 439 uint32_t max_chars = (src_len - 2) / 2; |
| 440 if (!max_chars) { | 440 if (!max_chars) { |
| 441 return result; | 441 return result; |
| 442 } | 442 } |
| 443 if (src_data[0] == 0xff) { | 443 if (src_data[0] == 0xff) { |
| 444 bBE = !src_data[2]; | 444 bBE = !src_data[2]; |
| 445 } | 445 } |
| 446 FX_WCHAR* dest_buf = result.GetBuffer(max_chars); | 446 FX_WCHAR* dest_buf = result.GetBuffer(max_chars); |
| 447 const uint8_t* uni_str = src_data + 2; | 447 const uint8_t* uni_str = src_data + 2; |
| 448 int dest_pos = 0; | 448 int dest_pos = 0; |
| 449 for (FX_DWORD i = 0; i < max_chars * 2; i += 2) { | 449 for (uint32_t i = 0; i < max_chars * 2; i += 2) { |
| 450 uint16_t unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) | 450 uint16_t unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) |
| 451 : (uni_str[i + 1] << 8 | uni_str[i]); | 451 : (uni_str[i + 1] << 8 | uni_str[i]); |
| 452 if (unicode == 0x1b) { | 452 if (unicode == 0x1b) { |
| 453 i += 2; | 453 i += 2; |
| 454 while (i < max_chars * 2) { | 454 while (i < max_chars * 2) { |
| 455 uint16_t unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) | 455 uint16_t unicode = bBE ? (uni_str[i] << 8 | uni_str[i + 1]) |
| 456 : (uni_str[i + 1] << 8 | uni_str[i]); | 456 : (uni_str[i + 1] << 8 | uni_str[i]); |
| 457 i += 2; | 457 i += 2; |
| 458 if (unicode == 0x1b) { | 458 if (unicode == 0x1b) { |
| 459 break; | 459 break; |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 } else { | 462 } else { |
| 463 dest_buf[dest_pos++] = unicode; | 463 dest_buf[dest_pos++] = unicode; |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 result.ReleaseBuffer(dest_pos); | 466 result.ReleaseBuffer(dest_pos); |
| 467 } else { | 467 } else { |
| 468 FX_WCHAR* dest_buf = result.GetBuffer(src_len); | 468 FX_WCHAR* dest_buf = result.GetBuffer(src_len); |
| 469 for (FX_DWORD i = 0; i < src_len; i++) | 469 for (uint32_t i = 0; i < src_len; i++) |
| 470 dest_buf[i] = PDFDocEncoding[src_data[i]]; | 470 dest_buf[i] = PDFDocEncoding[src_data[i]]; |
| 471 result.ReleaseBuffer(src_len); | 471 result.ReleaseBuffer(src_len); |
| 472 } | 472 } |
| 473 return result; | 473 return result; |
| 474 } | 474 } |
| 475 | 475 |
| 476 CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr) { | 476 CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr) { |
| 477 return PDF_DecodeText((const uint8_t*)bstr.c_str(), bstr.GetLength()); | 477 return PDF_DecodeText((const uint8_t*)bstr.c_str(), bstr.GetLength()); |
| 478 } | 478 } |
| 479 | 479 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 result << "\\r"; | 547 result << "\\r"; |
| 548 continue; | 548 continue; |
| 549 } | 549 } |
| 550 result.AppendChar(ch); | 550 result.AppendChar(ch); |
| 551 } | 551 } |
| 552 result.AppendChar(')'); | 552 result.AppendChar(')'); |
| 553 return result.GetByteString(); | 553 return result.GetByteString(); |
| 554 } | 554 } |
| 555 | 555 |
| 556 void FlateEncode(const uint8_t* src_buf, | 556 void FlateEncode(const uint8_t* src_buf, |
| 557 FX_DWORD src_size, | 557 uint32_t src_size, |
| 558 uint8_t*& dest_buf, | 558 uint8_t*& dest_buf, |
| 559 FX_DWORD& dest_size) { | 559 uint32_t& dest_size) { |
| 560 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 560 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
| 561 if (pEncoders) { | 561 if (pEncoders) { |
| 562 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_size); | 562 pEncoders->GetFlateModule()->Encode(src_buf, src_size, dest_buf, dest_size); |
| 563 } | 563 } |
| 564 } | 564 } |
| 565 | 565 |
| 566 void FlateEncode(const uint8_t* src_buf, | 566 void FlateEncode(const uint8_t* src_buf, |
| 567 FX_DWORD src_size, | 567 uint32_t src_size, |
| 568 int predictor, | 568 int predictor, |
| 569 int Colors, | 569 int Colors, |
| 570 int BitsPerComponent, | 570 int BitsPerComponent, |
| 571 int Columns, | 571 int Columns, |
| 572 uint8_t*& dest_buf, | 572 uint8_t*& dest_buf, |
| 573 FX_DWORD& dest_size) { | 573 uint32_t& dest_size) { |
| 574 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 574 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
| 575 if (pEncoders) { | 575 if (pEncoders) { |
| 576 pEncoders->GetFlateModule()->Encode(src_buf, src_size, predictor, Colors, | 576 pEncoders->GetFlateModule()->Encode(src_buf, src_size, predictor, Colors, |
| 577 BitsPerComponent, Columns, dest_buf, | 577 BitsPerComponent, Columns, dest_buf, |
| 578 dest_size); | 578 dest_size); |
| 579 } | 579 } |
| 580 } | 580 } |
| 581 | 581 |
| 582 FX_DWORD FlateDecode(const uint8_t* src_buf, | 582 uint32_t FlateDecode(const uint8_t* src_buf, |
| 583 FX_DWORD src_size, | 583 uint32_t src_size, |
| 584 uint8_t*& dest_buf, | 584 uint8_t*& dest_buf, |
| 585 FX_DWORD& dest_size) { | 585 uint32_t& dest_size) { |
| 586 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 586 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
| 587 if (pEncoders) { | 587 if (pEncoders) { |
| 588 return pEncoders->GetFlateModule()->FlateOrLZWDecode( | 588 return pEncoders->GetFlateModule()->FlateOrLZWDecode( |
| 589 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 589 FALSE, src_buf, src_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
| 590 } | 590 } |
| 591 return 0; | 591 return 0; |
| 592 } | 592 } |
| OLD | NEW |