aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QUtil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2020-10-21 21:29:28 +0200
committerJay Berkenbilt <ejb@ql.org>2020-10-21 22:42:51 +0200
commit98f6c00dad96d3150a9b969a0ee67addc78ac5f0 (patch)
tree2c1455f3b208275aecc1395453f3396a85eb7800 /libqpdf/QUtil.cc
parentef127001b36b42042874812e0d06dccf92cdb229 (diff)
downloadqpdf-98f6c00dad96d3150a9b969a0ee67addc78ac5f0.tar.zst
Protect numeric conversion against user's locale (fixes #459)
Diffstat (limited to 'libqpdf/QUtil.cc')
-rw-r--r--libqpdf/QUtil.cc3
1 files changed, 3 insertions, 0 deletions
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index 072a939c..366365f1 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -21,6 +21,7 @@
#include <string.h>
#include <fcntl.h>
#include <memory>
+#include <locale>
#ifndef QPDF_NO_WCHAR_T
# include <cwchar>
#endif
@@ -267,6 +268,7 @@ int_to_string_base_internal(T num, int base, int length)
"int_to_string_base called with unsupported base");
}
std::ostringstream buf;
+ buf.imbue(std::locale::classic());
buf << std::setbase(base) << std::nouppercase << num;
std::string result;
int str_length = QIntC::to_int(buf.str().length());
@@ -318,6 +320,7 @@ QUtil::double_to_string(double num, int decimal_places)
decimal_places = 6;
}
std::ostringstream buf;
+ buf.imbue(std::locale::classic());
buf << std::setprecision(decimal_places) << std::fixed << num;
return buf.str();
}