Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#3831 closed Bugs (fixed)

property_tree::read_json unable to handle large integers.

Reported by: Michael Anderson <drmikeando@…> Owned by: cornedbee
Milestone: Boost 1.42.0 Component: property_tree
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:


Trying to read json that contains a value outside the range of an int into a property tree produces the following error

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::property_tree::json_parser::json_parser_error> >'
  what():  <unspecified file>(1): expected value

This is due to the use of a int_p parser in the spirit parsing code. Applying the following patch

Index: boost/property_tree/detail/json_parser_read.hpp
--- boost/property_tree/detail/json_parser_read.hpp	(revision 58794)
+++ boost/property_tree/detail/json_parser_read.hpp	(working copy)
@@ -233,7 +233,7 @@
                     =   strict_real_p 
-                        | int_p
+                        | ( ! ( (ch_p('+') | ch_p('-') ) ) ) >> *digit_p 

Seems to fix this.

The following example demonstrates the issue.

#include "boost/property_tree/json_parser.hpp"
#include "boost/property_tree/info_parser.hpp"

int main()
  boost::property_tree::ptree pt;
  std::string s("{\"v1\":124567890123,\"v2\":+124567890123,\"v3\":-124567890123}");
  std::stringstream ss;
  boost::property_tree::read_json( ss, pt );
  boost::property_tree::write_json( std::cout, pt );

This outputs

    "v1": "124567890123",
    "v2": "+124567890123",
    "v3": "-124567890123"

When the patch is applied.

Attachments (0)

Change History (2)

comment:1 Changed 7 years ago by cornedbee

  • Resolution set to fixed
  • Status changed from new to closed

(In [59740]) Make the JSON parser's number production fit the JSON spec instead of doing stupid things. Fixes bug 3831.

comment:2 Changed 6 years ago by marshall

This fix was copied to the release branch in [65975], and was part of boost 1.45.0

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain cornedbee.
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.