[CDRIVER-1329] maxTimeMS and maxAwaitTimeMS should be Int64, not Int32 Created: 15/Jun/16  Updated: 16/Oct/23

Status: Backlog
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0.0

Type: Improvement Priority: Minor - P4
Reporter: David Golden Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-2734 maxTimeMS command option should be ap... Closed
related to CDRIVER-4589 mongoc_stream_t interface should supp... Backlog
is related to CXX-849 Audit API usage of int32_t Backlog
Epic Link: CDRIVER-4742
Backwards Compatibility: Major Change

 Description   

The CRUD spec defines maxTimeMS and maxAwaitTimeMS as Int64. Where the C driver handles these in a typed way (as opposed to query-to-command conversion), it expects Int32.

The following functions use uint32_t for "maxTimeMS" and should be changed:

  • mongoc_cursor_get_max_await_time_ms()
  • mongoc_cursor_set_max_await_time_ms()
  • mongoc_find_and_modify_opts_get_max_time_ms()
  • mongoc_find_and_modify_opts_set_max_time_ms()


 Comments   
Comment by Jeremy Mikola [ 10/Jul/18 ]

mongoc_find_and_modify_opts_set_max_time_ms() accepts a uint32_t and the options struct internally tracks max_time_ms as uint32_t. In mongoc_collection_find_and_modify_with_opts(), the value is appended with BSON_APPEND_INT32. We should be able to cast the value as an int64_t and append as a 64-bit BSON integer, which would remove the risk of UINT32_MAX turning into INT32_MIN.

Similarly, mongoc_cursor_set_max_await_time_ms() and mongoc_cursor_get_max_await_time_ms() use uint32_t but store the value as an int64 in the cursor's options bson_t. This effectively limits the value to UINT32_MAX. However, users could theoretically pass a larger non-negative 64-bit integer as "maxAwaitTimeMS" via the find options and ignore the getter's limitation. That said, we still have a problem in mongoc_cursor_prepare_getmore_command(), as it uses the getter (which will cast down the original int64_t) and _also uses bson_append_int32 to append, which also carries the risk of UINT32_MAX turning into INT32_MIN.

I believe both of those issues related to appending can be fixed in a 1.x release without any ABI or BC concerns, as they're internal bug fixes.

Generated at Wed Feb 07 21:12:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.