Skip to content

Commit 2233791

Browse files
authored
CXX-3251 remove workaround for big_string length in API examples (#1357)
* remove workaround for big_string length in API examples (CDRIVER-5732, CDRIVER-5915) * CXX-3103 set MONGOC_VERSION_MINIMUM to 57bffac1 * CXX-3251 include narrowing conversion range check for key length in core::append * CXX-3103 Add workaround for incompatible VERSION_CURRENT in upstream C Driver
1 parent 22987e4 commit 2233791

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

.evergreen/config_generator/components/funcs/install_c_driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Only LIBMONGOC_DOWNLOAD_VERSION needs to be updated when pinning to an unreleased commit.
1515
# If pinning to an unreleased commit, create a "Blocked" JIRA ticket with
1616
# a "depends on" link to the appropriate C Driver version release ticket.
17-
MONGOC_VERSION_MINIMUM = '1.30.1'
17+
MONGOC_VERSION_MINIMUM = '57bffac11fde38d1ce097bb22fb5322a6114d644' # CXX-3103: bump to 2.0.0 once released.
1818

1919

2020
class InstallCDriver(Function):

.evergreen/generated_configs/functions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ functions:
398398
type: setup
399399
params:
400400
updates:
401-
- { key: mongoc_version_minimum, value: 1.30.1 }
401+
- { key: mongoc_version_minimum, value: 57bffac11fde38d1ce097bb22fb5322a6114d644 }
402402
- command: subprocess.exec
403403
type: setup
404404
params:

.evergreen/scripts/install-c-driver.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ tar xzf mongo-c-driver.tar.gz --directory "${mongoc_dir}" --strip-components=1
4040
# C Driver needs VERSION_CURRENT to compute BUILD_VERSION.
4141
if [[ -f "${mongoc_dir}/VERSION_CURRENT" ]]; then
4242
: # Use the existing VERSION_CURRENT bundled with the release tarball.
43+
44+
# CXX-3103: overwrite incompatible build versions to support the upcoming 2.0.0 release.
45+
echo "1.31.0-pre" >|"${mongoc_dir}/VERSION_CURRENT"
4346
else
4447
# RegEx pattern to match SemVer strings. See https://semver.org/.
4548
declare -r semver_regex="^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ set(LIBBSON_REQUIRED_ABI_VERSION 1.0)
5454

5555
# Also update etc/purls.txt.
5656
set(LIBMONGOC_REQUIRED_VERSION 1.30.0)
57-
set(LIBMONGOC_DOWNLOAD_VERSION 1.30.1)
57+
set(LIBMONGOC_DOWNLOAD_VERSION 57bffac11fde38d1ce097bb22fb5322a6114d644)
5858
set(LIBMONGOC_REQUIRED_ABI_VERSION 1.0)
5959

6060
set(NEED_DOWNLOAD_C_DRIVER false)

examples/api/bsoncxx/examples/bson_errors/big_string.hh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ namespace examples {
2727
// Used to trigger builder append failure.
2828
struct big_string {
2929
// BSON_SIZE_MAX == 0x7FFFFFFF
30-
// Leave some room for CDRIVER-5732.
31-
std::size_t length{static_cast<std::size_t>(std::numeric_limits<std::int32_t>::max() - 32u)};
30+
std::size_t length{static_cast<std::size_t>(std::numeric_limits<std::int32_t>::max())};
3231

3332
// Allocate an UNINITIALIZED blob of data that will not be accessed due to length checks.
3433
// Leaving memory unitialized (rather than zero-init) should hopefully avoid slow and expensive

src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/builder/core.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,14 @@ core& core::append(types::b_double const& value) {
298298

299299
core& core::append(types::b_string const& value) {
300300
stdx::string_view key = _impl->next_key();
301-
302-
if (!bson_append_utf8(
303-
_impl->back(),
304-
key.data(),
305-
static_cast<std::int32_t>(key.length()),
306-
value.value.data(),
307-
static_cast<std::int32_t>(value.value.length()))) {
301+
std::size_t value_length = value.value.length();
302+
303+
if (value_length > std::size_t{INT32_MAX} || !bson_append_utf8(
304+
_impl->back(),
305+
key.data(),
306+
static_cast<std::int32_t>(key.length()),
307+
value.value.data(),
308+
static_cast<std::int32_t>(value_length))) {
308309
throw bsoncxx::v_noabi::exception{error_code::k_cannot_append_string};
309310
}
310311

0 commit comments

Comments
 (0)