[CDRIVER-1377] bson_ascii_strtoll() does not detect ERANGE errors Created: 13/Jul/16  Updated: 18/Aug/21  Resolved: 15/Nov/16

Status: Closed
Project: C Driver
Component/s: libbson
Affects Version/s: 1.3.5
Fix Version/s: 1.5.0

Type: Bug Priority: Major - P3
Reporter: Jeremy Mikola Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by PHPC-1957 Add tests for out-of-range UTCDateTim... Backlog
Related
related to CDRIVER-1378 Accept NULL endptr in bson_ascii_strt... Closed

 Description   

In _bson_json_read_string(), bson_ascii_strtoll() is called and errno is later compared with ERANGE to check for an out-of-range value. Internally, bson_ascii_strtoll() never actually sets ERANGE and appears to have no logic for detecting range errors.



 Comments   
Comment by Githook User [ 30/Jan/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: Merge branch 'r1.5'

Comment by Githook User [ 30/Jan/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1377 use INT64_MAX, not LLONG_MAX, in bson_stroll
Branch: master
https://github.com/mongodb/libbson/commit/2738c74d3c5a2fdaeef2de603d2e32534ad8f76e

Comment by Githook User [ 25/Nov/16 ]

Author:

{u'username': u'jmikola', u'name': u'Jeremy Mikola', u'email': u'jmikola@gmail.com'}

Message: Use consistent string parsing for Timestamp and UTCDateTime init

bson_ascii_strtoll() will support range checking in libbson 1.5.0 (CDRIVER-1377), so there is no longer any benefit of using _atoi64() on Windows. This will make parsing consistent across both platforms, since _atoi64() does not report errors for non-integer strings (e.g. "1.2").
Branch: master
https://github.com/mongodb/mongo-php-driver/commit/1f785d2cb101f6ac322b0218eb8cb27019078bfb

Comment by Githook User [ 15/Nov/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1377 use INT64_MAX, not LLONG_MAX, in bson_stroll
Branch: master
https://github.com/mongodb/libbson/commit/f307befe8e66c210a5844a552cf3b6b1731bdd20

Comment by Hannes Magnusson [ 15/Nov/16 ]

This broke build on RHEL5.5

 
[2016/11/14 17:13:04.041] tests/test-string.c: In function 'test_bson_ascii_strtoll':
[2016/11/14 17:13:04.041] tests/test-string.c:258: error: 'LLONG_MAX' undeclared (first use in this function)
[2016/11/14 17:13:04.041] tests/test-string.c:258: error: (Each undeclared identifier is reported only once
[2016/11/14 17:13:04.041] tests/test-string.c:258: error: for each function it appears in.)
[2016/11/14 17:13:04.041] tests/test-string.c:259: error: 'LLONG_MIN' undeclared (first use in this function)
[2016/11/14 17:13:04.044] make: *** [tests/test_libbson-test-string.o] Error 1
[2016/11/14 17:13:04.045] Command failed: exit status 2

Comment by Bernie Hackett [ 14/Nov/16 ]

Changed fix version to 1.5, since this just landed in master.

Comment by Githook User [ 14/Nov/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1377 bson_stroll detects range errors
Branch: master
https://github.com/mongodb/libbson/commit/877c4652bc032e960b712d7829fa1b8fe47c5552

Comment by Jeremy Mikola [ 13/Jul/16 ]

Based on my testing, out-of-range values are returned "9223372036854775807" and "-9223372036854775808" (i.e. largest and smallest 64-bit signed integers) are parsed correctly. Behavior is broken for values with greater magnitude:

  • "9223372036854775808" is parsed as -9223372036854775808
  • "-9223372036854775809" is parsed as 9223372036854775807
  • "18446744073709551615" is parsed as -1
Generated at Wed Feb 07 21:12:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.