From b670565abc579de5bda946b7538545aa967e6cd2 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 21 Dec 2023 17:38:49 -0500 Subject: Convert scientific notation in JSON to fixed point (fixes #1079) JSON accepts scientific notation, but PDF doesn't. --- libqpdf/QPDF_json.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libqpdf') diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index 864e1a56..7951b1e4 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -732,6 +732,15 @@ QPDF::JSONReactor::makeObject(JSON const& value) if (QUtil::is_long_long(str_v.c_str())) { result = QPDFObjectHandle::newInteger(QUtil::string_to_ll(str_v.c_str())); } else { + // JSON allows scientific notation, but PDF does not. + if (str_v.find('e') != std::string::npos || str_v.find('E') != std::string::npos) { + try { + auto v = std::stod(str_v); + str_v = QUtil::double_to_string(v); + } catch (std::exception&) { + // Keep it as it was + } + } result = QPDFObjectHandle::newReal(str_v); } } else if (value.getString(str_v)) { -- cgit v1.2.3-70-g09d2