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

Unified Diff: core/fpdfapi/page/fpdf_page_func.cpp

Issue 2415483002: Check for more undefined behavior in CPDF_PSEngine. (Closed)
Patch Set: ValueOrDefault 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/page/fpdf_page_func.cpp
diff --git a/core/fpdfapi/page/fpdf_page_func.cpp b/core/fpdfapi/page/fpdf_page_func.cpp
index 6af787ea4977f6e57d9721ea24f9ac8fc0e68548..d2e08a511c6566e583e9f7e29c0221058580ed1c 100644
--- a/core/fpdfapi/page/fpdf_page_func.cpp
+++ b/core/fpdfapi/page/fpdf_page_func.cpp
@@ -20,7 +20,6 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/fx_safe_types.h"
-#include "third_party/base/numerics/safe_conversions_impl.h"
class CPDF_PSOP {
public:
@@ -180,8 +179,11 @@ FX_BOOL CPDF_PSProc::Parse(CPDF_SimpleParser* parser, int depth) {
}
FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) {
- int i1, i2;
- FX_FLOAT d1, d2;
+ int i1;
+ int i2;
+ FX_FLOAT d1;
+ FX_FLOAT d2;
+ FX_SAFE_INT32 result;
switch (op) {
case PSOP_ADD:
d1 = Pop();
@@ -204,14 +206,26 @@ FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) {
Push(d1 / d2);
break;
case PSOP_IDIV:
- i2 = (int)Pop();
- i1 = (int)Pop();
- Push(i2 ? i1 / i2 : 0);
+ i2 = static_cast<int>(Pop());
+ i1 = static_cast<int>(Pop());
+ if (i2) {
+ result = i1;
+ result /= i2;
+ Push(result.ValueOrDefault(0));
+ } else {
+ Push(0);
+ }
break;
case PSOP_MOD:
- i2 = (int)Pop();
- i1 = (int)Pop();
- Push(i2 ? i1 % i2 : 0);
+ i2 = static_cast<int>(Pop());
+ i1 = static_cast<int>(Pop());
+ if (i2) {
+ result = i1;
+ result %= i2;
+ Push(result.ValueOrDefault(0));
+ } else {
+ Push(0);
+ }
break;
case PSOP_NEG:
d1 = Pop();
« 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