Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp

Issue 1142713005: Remove FX_Alloc() null checks now that it can't return NULL. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix missing FX_Alloc2D, check overflow on add, remove unused enum. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 }
46 int state = 0; 43 int state = 0;
47 FX_UINT32 res = 0; 44 FX_UINT32 res = 0;
48 pos = dest_size = 0; 45 pos = dest_size = 0;
49 while (pos < src_size) { 46 while (pos < src_size) {
50 FX_BYTE ch = src_buf[pos++]; 47 FX_BYTE ch = src_buf[pos++];
51 if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') { 48 if (ch == '\n' || ch == '\r' || ch == ' ' || ch == '\t') {
52 continue; 49 continue;
53 } 50 }
54 if (ch == 'z') { 51 if (ch == 'z') {
55 FXSYS_memset32(dest_buf + dest_size, 0, 4); 52 FXSYS_memset32(dest_buf + dest_size, 0, 4);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 143 }
147 i += 2; 144 i += 2;
148 } else { 145 } else {
149 break; 146 break;
150 } 147 }
151 } 148 }
152 if (dest_size >= _STREAM_MAX_SIZE_) { 149 if (dest_size >= _STREAM_MAX_SIZE_) {
153 return -1; 150 return -1;
154 } 151 }
155 dest_buf = FX_Alloc( FX_BYTE, dest_size); 152 dest_buf = FX_Alloc( FX_BYTE, dest_size);
156 if (!dest_buf) {
157 return -1;
158 }
159 i = 0; 153 i = 0;
160 int dest_count = 0; 154 int dest_count = 0;
161 while (i < src_size) { 155 while (i < src_size) {
162 if (src_buf[i] < 128) { 156 if (src_buf[i] < 128) {
163 FX_DWORD copy_len = src_buf[i] + 1; 157 FX_DWORD copy_len = src_buf[i] + 1;
164 FX_DWORD buf_left = src_size - i - 1; 158 FX_DWORD buf_left = src_size - i - 1;
165 if (buf_left < copy_len) { 159 if (buf_left < copy_len) {
166 FX_DWORD delta = copy_len - buf_left; 160 FX_DWORD delta = copy_len - buf_left;
167 copy_len = buf_left; 161 copy_len = buf_left;
168 FXSYS_memset8(dest_buf + dest_count + copy_len, '\0', delta); 162 FXSYS_memset8(dest_buf + dest_count + copy_len, '\0', delta);
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 521 }
528 } 522 }
529 FX_DWORD FlateDecode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_ buf, FX_DWORD& dest_size) 523 FX_DWORD FlateDecode(const FX_BYTE* src_buf, FX_DWORD src_size, FX_LPBYTE& dest_ buf, FX_DWORD& dest_size)
530 { 524 {
531 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule(); 525 CCodec_ModuleMgr* pEncoders = CPDF_ModuleMgr::Get()->GetCodecModule();
532 if (pEncoders) { 526 if (pEncoders) {
533 return pEncoders->GetFlateModule()->FlateOrLZWDecode(FALSE, src_buf, src _size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size); 527 return pEncoders->GetFlateModule()->FlateOrLZWDecode(FALSE, src_buf, src _size, FALSE, 0, 0, 0, 0, 0, dest_buf, dest_size);
534 } 528 }
535 return 0; 529 return 0;
536 } 530 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698