Opened 12 years ago

Last modified 7 years ago

#5446 new Bugs

Exception thrown by tz_database::load_from_file() on linux 2.6.37, boost1.46.1,gcc4.5.2

Reported by: frankrq2009@… Owned by: az_sw_dude
Milestone: To Be Determined Component: date_time
Version: Boost 1.46.1 Severity: Problem
Keywords: Cc:

Description

Hi, I tried to run the Flight Time Example in boost_1_46_1/doc/html/date_time/examples.html#date_time.examples.simple_time_zone, and an exception was thrown with error message: terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast> >'

what(): bad lexical cast: source type value could not be interpreted as target

When I debug with step into, I found it happened on line "Africa/Cairo" of the date_time_zonespec.csv, because this is the first timezone which needs to call dst_adjustment_offsets(), and there was a '\r' at the end of the line, then when str_from_delimited_time_duration() called boost::lexical_cast<unsigned short>(*beg) the '\r' made the exception being raised. On linux, std::getline(ifs, buff) in load_from_file() will leave the '\r' in buff, which caused the exception. On win32 this would not happen. So the line ends '\r' needs to be removed in load_from_file() or at the beginning of parse_string().

Attachments (1)

date_time.diff (505 bytes ) - added by anonymous 11 years ago.
timezone_db DOS newline support

Download all attachments as: .zip

Change History (5)

comment:1 by anonymous, 11 years ago

Please raise the severity of this bug, I have encountered it as well.

The fallout from this is that tz_database is completely broken on linux, causing your application to crash, this is a very serious bug.

The explanation above is 100% accurate, boost::lexical_cast is being called with an extra '\r' on lines which need DST adjustments.

Here is a GDB snapshot from my application:


#6  0x000000000041a14f in boost::throw_exception<boost::bad_lexical_cast> (e=...) at /usr/include/boost/throw_exception.hpp:61
#7  0x0000000000417dd1 in boost::detail::lexical_cast<unsigned short, std::basic_string<char>, false, char> (arg=..., buf=0x7fffffffda20 "P\337\377\377\377\177", src_len=1)
    at /usr/include/boost/lexical_cast.hpp:1152

#8  0x0000000000415889 in boost::lexical_cast<unsigned short, std::basic_string<char> > (arg=...) at /usr/include/boost/lexical_cast.hpp:1174

#9  0x0000000000415a9f in boost::date_time::str_from_delimited_time_duration<boost::posix_time::time_duration, char> (s=...) at /usr/include/boost/date_time/time_parsing.hpp:79

#10 0x0000000000416606 in boost::date_time::tz_db_base<boost::local_time::custom_time_zone_base<char>, boost::date_time::day_calc_dst_rule<boost::local_time::nth_kday_rule_spec> >::parse_string (this=0x6d76e0, s=...) at /usr/include/boost/date_time/tz_db_base.hpp:358

#11 0x0000000000414426 in boost::date_time::tz_db_base<boost::local_time::custom_time_zone_base<char>, boost::date_time::day_calc_dst_rule<boost::local_time::nth_kday_rule_spec> >::load_from_file (this=0x6d76e0, pathspec=...) at /usr/include/boost/date_time/tz_db_base.hpp:183
------------

comment:2 by anonymous, 11 years ago

Digging further, the cause of this problem is that the date_time_zonespec.csv file is shipped with DOS newlines.

If you run: dos2unix date_time_zonespec.csv

The file works properly.

I have attached a diff vs. trunk which allows DOS newlines.

by anonymous, 11 years ago

Attachment: date_time.diff added

timezone_db DOS newline support

comment:3 by Marshall Clow, 11 years ago

I've checked the 1.47.0 release, and the svn repo. The svn:eol-style is 'native' (in both trunk and release), and the file in the release tarball has unix line endings. The same is true in the 1.46.1 .tar.bz2 file - so I'm not sure how you got DOS line endings.

comment:4 by nil@…, 7 years ago

For the Internet searchers. The load_from_file method differs from load_from_stream, as the former ignores one line from the input and the latter does not. I've learnt it the hard way.

Note: See TracTickets for help on using tickets.