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

Unified Diff: core/fxcrt/fx_basic_util.cpp

Issue 1992023003: Correctly check for overflow in FX_atonum. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 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 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/fxcrt/fx_basic_util.cpp
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index abb2b9472a14c513ea6a60e1b1a80d8117d5fe35..aa36d56f38384a0f149bfc829f09f0b35d485abf 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -94,11 +94,12 @@ void CFX_PrivateData::ClearAll() {
}
m_DataList.RemoveAll();
}
+
void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
if (strc.Find('.') == -1) {
bInteger = TRUE;
int cc = 0;
- int integer = 0;
+ pdfium::base::CheckedNumeric<int> integer = 0;
FX_STRSIZE len = strc.GetLength();
bool bNegative = false;
if (strc[0] == '+') {
@@ -108,21 +109,21 @@ void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
cc++;
}
while (cc < len && std::isdigit(strc[cc])) {
- // TODO(dsinclair): This is not the right way to handle overflow.
integer = integer * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc));
- if (integer < 0)
+ if (!integer.IsValid())
break;
cc++;
}
if (bNegative) {
integer = -integer;
}
- *(int*)pData = integer;
+ *(int*)pData = integer.ValueOrDefault(0);
} else {
bInteger = FALSE;
*(FX_FLOAT*)pData = FX_atof(strc);
}
}
+
FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
if (strc.IsEmpty())
return 0.0;
« 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