Modify

Ticket #3831 (closed Bugs: fixed)

Opened 4 years ago

Last modified 3 years ago

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:

Description

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 @@
                 
                 number 
                     =   strict_real_p 
-                        | int_p
+                        | ( ! ( (ch_p('+') | ch_p('-') ) ) ) >> *digit_p 
                         ;
                 
                 string 

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;
  ss<<s;
  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

Change History

comment:1 Changed 4 years ago by cornedbee

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

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

comment:2 Changed 3 years ago by marshall

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.