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

Side by Side Diff: core/fpdfapi/page/fpdf_page_func.cpp

Issue 2415483002: Check for more undefined behavior in CPDF_PSEngine. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "core/fpdfapi/page/pageint.h" 7 #include "core/fpdfapi/page/pageint.h"
8 8
9 #include <limits.h> 9 #include <limits.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "core/fpdfapi/page/cpdf_psengine.h" 16 #include "core/fpdfapi/page/cpdf_psengine.h"
17 #include "core/fpdfapi/parser/cpdf_array.h" 17 #include "core/fpdfapi/parser/cpdf_array.h"
18 #include "core/fpdfapi/parser/cpdf_dictionary.h" 18 #include "core/fpdfapi/parser/cpdf_dictionary.h"
19 #include "core/fpdfapi/parser/cpdf_simple_parser.h" 19 #include "core/fpdfapi/parser/cpdf_simple_parser.h"
20 #include "core/fpdfapi/parser/cpdf_stream.h" 20 #include "core/fpdfapi/parser/cpdf_stream.h"
21 #include "core/fpdfapi/parser/cpdf_stream_acc.h" 21 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
22 #include "core/fxcrt/fx_safe_types.h" 22 #include "core/fxcrt/fx_safe_types.h"
23 #include "third_party/base/numerics/safe_conversions_impl.h"
24 23
25 class CPDF_PSOP { 24 class CPDF_PSOP {
26 public: 25 public:
27 explicit CPDF_PSOP(PDF_PSOP op) : m_op(op), m_value(0) { 26 explicit CPDF_PSOP(PDF_PSOP op) : m_op(op), m_value(0) {
28 ASSERT(m_op != PSOP_CONST); 27 ASSERT(m_op != PSOP_CONST);
29 ASSERT(m_op != PSOP_PROC); 28 ASSERT(m_op != PSOP_PROC);
30 } 29 }
31 explicit CPDF_PSOP(FX_FLOAT value) : m_op(PSOP_CONST), m_value(value) {} 30 explicit CPDF_PSOP(FX_FLOAT value) : m_op(PSOP_CONST), m_value(value) {}
32 explicit CPDF_PSOP(std::unique_ptr<CPDF_PSProc> proc) 31 explicit CPDF_PSOP(std::unique_ptr<CPDF_PSProc> proc)
33 : m_op(PSOP_PROC), m_value(0), m_proc(std::move(proc)) {} 32 : m_op(PSOP_PROC), m_value(0), m_proc(std::move(proc)) {}
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 172 }
174 if (!found) { 173 if (!found) {
175 std::unique_ptr<CPDF_PSOP> op(new CPDF_PSOP(FX_atof(word))); 174 std::unique_ptr<CPDF_PSOP> op(new CPDF_PSOP(FX_atof(word)));
176 m_Operators.push_back(std::move(op)); 175 m_Operators.push_back(std::move(op));
177 } 176 }
178 } 177 }
179 } 178 }
180 } 179 }
181 180
182 FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) { 181 FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) {
183 int i1, i2; 182 int i1;
184 FX_FLOAT d1, d2; 183 int i2;
184 FX_FLOAT d1;
185 FX_FLOAT d2;
186 FX_SAFE_INT32 result;
185 switch (op) { 187 switch (op) {
186 case PSOP_ADD: 188 case PSOP_ADD:
187 d1 = Pop(); 189 d1 = Pop();
188 d2 = Pop(); 190 d2 = Pop();
189 Push(d1 + d2); 191 Push(d1 + d2);
190 break; 192 break;
191 case PSOP_SUB: 193 case PSOP_SUB:
192 d2 = Pop(); 194 d2 = Pop();
193 d1 = Pop(); 195 d1 = Pop();
194 Push(d1 - d2); 196 Push(d1 - d2);
195 break; 197 break;
196 case PSOP_MUL: 198 case PSOP_MUL:
197 d1 = Pop(); 199 d1 = Pop();
198 d2 = Pop(); 200 d2 = Pop();
199 Push(d1 * d2); 201 Push(d1 * d2);
200 break; 202 break;
201 case PSOP_DIV: 203 case PSOP_DIV:
202 d2 = Pop(); 204 d2 = Pop();
203 d1 = Pop(); 205 d1 = Pop();
204 Push(d1 / d2); 206 Push(d1 / d2);
205 break; 207 break;
206 case PSOP_IDIV: 208 case PSOP_IDIV:
207 i2 = (int)Pop(); 209 i2 = static_cast<int>(Pop());
208 i1 = (int)Pop(); 210 i1 = static_cast<int>(Pop());
209 Push(i2 ? i1 / i2 : 0); 211 if (i2) {
212 result = i1;
213 result /= i2;
214 Push(result.IsValid() ? result.ValueOrDie() : 0);
215 } else {
Tom Sepez 2016/10/12 16:08:42 nit: ValueOrDefault(0)
Lei Zhang 2016/10/12 16:47:33 Done.
216 Push(0);
217 }
210 break; 218 break;
211 case PSOP_MOD: 219 case PSOP_MOD:
212 i2 = (int)Pop(); 220 i2 = static_cast<int>(Pop());
213 i1 = (int)Pop(); 221 i1 = static_cast<int>(Pop());
214 Push(i2 ? i1 % i2 : 0); 222 if (i2) {
223 result = i1;
224 result %= i2;
225 Push(result.IsValid() ? result.ValueOrDie() : 0);
226 } else {
227 Push(0);
228 }
215 break; 229 break;
216 case PSOP_NEG: 230 case PSOP_NEG:
217 d1 = Pop(); 231 d1 = Pop();
218 Push(-d1); 232 Push(-d1);
219 break; 233 break;
220 case PSOP_ABS: 234 case PSOP_ABS:
221 d1 = Pop(); 235 d1 = Pop();
222 Push((FX_FLOAT)FXSYS_fabs(d1)); 236 Push((FX_FLOAT)FXSYS_fabs(d1));
223 break; 237 break;
224 case PSOP_CEILING: 238 case PSOP_CEILING:
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 return m_Type == Type::kType2ExpotentialInterpolation 850 return m_Type == Type::kType2ExpotentialInterpolation
837 ? static_cast<const CPDF_ExpIntFunc*>(this) 851 ? static_cast<const CPDF_ExpIntFunc*>(this)
838 : nullptr; 852 : nullptr;
839 } 853 }
840 854
841 const CPDF_StitchFunc* CPDF_Function::ToStitchFunc() const { 855 const CPDF_StitchFunc* CPDF_Function::ToStitchFunc() const {
842 return m_Type == Type::kType3Stitching 856 return m_Type == Type::kType3Stitching
843 ? static_cast<const CPDF_StitchFunc*>(this) 857 ? static_cast<const CPDF_StitchFunc*>(this)
844 : nullptr; 858 : nullptr;
845 } 859 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698