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

Unified Diff: fpdfsdk/javascript/PublicMethods.cpp

Issue 2572543004: Verify precision length before converting to string. (Closed)
Patch Set: Created 4 years 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: fpdfsdk/javascript/PublicMethods.cpp
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index bfe48d5b65a9906b6b54356bdd38d79be8c32112..c0ea84c0aece0caeb73b0477709a9950e5740960 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();
« 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