summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-12-14 05:45:57 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-14 05:45:57 -0800
commit992ecf7c189e5cabf43e5ad862511cf63d030966 (patch)
treeba38809871058e79cd4c269784772eff5b6f0081 /fpdfsdk
parent974b4a6c4bceb50bbe5bf316e9e273b62eaeceac (diff)
downloadpdfium-992ecf7c189e5cabf43e5ad862511cf63d030966.tar.xz
Verify precision length before converting to string.
This CL updates the CalculateString method to make sure the number of digits of precision is valid before doing the stringstream conversion. BUG=chromium:673336 Review-Url: https://codereview.chromium.org/2572543004
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/javascript/PublicMethods.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index bfe48d5b65..c0ea84c0ae 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -8,6 +8,7 @@
#include <algorithm>
#include <iomanip>
+#include <limits>
#include <sstream>
#include <string>
#include <vector>
@@ -95,6 +96,11 @@ CFX_ByteString CalculateString(double dValue,
*bNegative = dValue < 0;
if (*bNegative)
dValue = -dValue;
+
+ // Make sure the number of precision characters will fit.
+ if (iDec > std::numeric_limits<double>::digits10)
+ iDec = std::numeric_limits<double>::digits10;
+
std::stringstream ss;
ss << std::fixed << std::setprecision(iDec) << dValue;
std::string stringValue = ss.str();