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 "../../../include/fpdfapi/fpdf_parser.h" | 7 #include "../../../include/fpdfapi/fpdf_parser.h" |
8 #include "../../../include/fpdfapi/fpdf_module.h" | 8 #include "../../../include/fpdfapi/fpdf_module.h" |
9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
10 #include <limits.h> | 10 #include <limits.h> |
(...skipping 22 matching lines...) Expand all Loading... |
33 if (pos == 0) { | 33 if (pos == 0) { |
34 return 0; | 34 return 0; |
35 } | 35 } |
36 if (zcount > UINT_MAX / 4) { | 36 if (zcount > UINT_MAX / 4) { |
37 return (FX_DWORD) - 1; | 37 return (FX_DWORD) - 1; |
38 } | 38 } |
39 if (zcount * 4 > UINT_MAX - (pos - zcount)) { | 39 if (zcount * 4 > UINT_MAX - (pos - zcount)) { |
40 return (FX_DWORD) - 1; | 40 return (FX_DWORD) - 1; |
41 } | 41 } |
42 dest_buf = FX_Alloc(FX_BYTE, zcount * 4 + (pos - zcount)); | 42 dest_buf = FX_Alloc(FX_BYTE, zcount * 4 + (pos - zcount)); |
| 43 if (dest_buf == NULL) { |
| 44 return (FX_DWORD) - 1; |
| 45 } |
43 int state = 0; | 46 int state = 0; |
44 FX_UINT32 res = 0; | 47 FX_UINT32 res = 0; |
45 pos = dest_size = 0; | 48 pos = dest_size = 0; |
46 while (pos < src_size) { | 49 while (pos < src_size) { |
47 FX_BYTE ch = src_buf[pos++]; | 50 FX_BYTE ch = src_buf[pos++]; |
48 if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') { | 51 if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') { |
49 continue; | 52 continue; |
50 } | 53 } |
51 if (ch == 'z') { | 54 if (ch == 'z') { |
52 FXSYS_memset32(dest_buf + dest_size, 0, 4); | 55 FXSYS_memset32(dest_buf + dest_size, 0, 4); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 } | 146 } |
144 i += 2; | 147 i += 2; |
145 } else { | 148 } else { |
146 break; | 149 break; |
147 } | 150 } |
148 } | 151 } |
149 if (dest_size >= _STREAM_MAX_SIZE_) { | 152 if (dest_size >= _STREAM_MAX_SIZE_) { |
150 return -1; | 153 return -1; |
151 } | 154 } |
152 dest_buf = FX_Alloc( FX_BYTE, dest_size); | 155 dest_buf = FX_Alloc( FX_BYTE, dest_size); |
| 156 if (!dest_buf) { |
| 157 return -1; |
| 158 } |
153 i = 0; | 159 i = 0; |
154 int dest_count = 0; | 160 int dest_count = 0; |
155 while (i < src_size) { | 161 while (i < src_size) { |
156 if (src_buf[i] < 128) { | 162 if (src_buf[i] < 128) { |
157 FX_DWORD copy_len = src_buf[i] + 1; | 163 FX_DWORD copy_len = src_buf[i] + 1; |
158 FX_DWORD buf_left = src_size - i - 1; | 164 FX_DWORD buf_left = src_size - i - 1; |
159 if (buf_left < copy_len) { | 165 if (buf_left < copy_len) { |
160 FX_DWORD delta = copy_len - buf_left; | 166 FX_DWORD delta = copy_len - buf_left; |
161 copy_len = buf_left; | 167 copy_len = buf_left; |
162 FXSYS_memset8(dest_buf + dest_count + copy_len, '\0', delta); | 168 FXSYS_memset8(dest_buf + dest_count + copy_len, '\0', delta); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 } | 527 } |
522 } | 528 } |
523 FX_DWORD FlateDecode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_
buf, FX_DWORD& dest_size) | 529 FX_DWORD FlateDecode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_
buf, FX_DWORD& dest_size) |
524 { | 530 { |
525 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); | 531 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); |
526 if (pEncoders) { | 532 if (pEncoders) { |
527 return pEncoders->GetFlateModule()->FlateOrLZWDecode(FALSE, src_buf, src
_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); | 533 return pEncoders->GetFlateModule()->FlateOrLZWDecode(FALSE, src_buf, src
_size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); |
528 } | 534 } |
529 return 0; | 535 return 0; |
530 } | 536 } |
OLD | NEW |