Skip to content

Commit 4eea95e

Browse files
authored
MONGOCRYPT-888 update libbson to 2.3.0 (#1149)
* note in changelog * bump libbson from 2.1.0 to 2.3.0 * replace deprecated calls of bson_append_array_begin with bson_append_array_unsafe_begin Opt into the unsafe API since the generated keys are expected to be correct. * update patches To account for formatting changes * remove ASan tasks on arm64 To address observed compiler errors.
1 parent f78ca9f commit 4eea95e

23 files changed

Lines changed: 93 additions & 76 deletions

.evergreen/config.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,6 @@ buildvariants:
15881588
tasks:
15891589
- build-and-test-and-upload
15901590
- build-and-test-shared-bson
1591-
- build-and-test-asan
15921591
- build-packages
15931592
- name: publish-packages
15941593
distros:
@@ -1842,7 +1841,6 @@ buildvariants:
18421841
tasks:
18431842
- build-and-test-and-upload
18441843
- build-and-test-shared-bson
1845-
- build-and-test-asan
18461844
- build-packages
18471845
- name: publish-packages
18481846
distros:
@@ -1882,7 +1880,6 @@ buildvariants:
18821880
tasks:
18831881
- build-and-test-and-upload
18841882
- build-and-test-shared-bson
1885-
- build-and-test-asan
18861883
- build-packages
18871884
- name: publish-packages
18881885
distros:
@@ -1910,7 +1907,6 @@ buildvariants:
19101907
tasks:
19111908
- build-and-test-and-upload
19121909
- build-and-test-shared-bson
1913-
- build-and-test-asan
19141910
- build-packages
19151911
- name: publish-packages
19161912
distros:
@@ -1967,7 +1963,6 @@ buildvariants:
19671963
tasks:
19681964
- build-and-test-and-upload
19691965
- build-and-test-shared-bson
1970-
- build-and-test-asan
19711966
- build-packages
19721967
- name: publish-packages
19731968
distros:

.evergreen/linker_tests_deps/bson_patches/libbson1.patch

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ Adds a printf to bson_malloc0 to test linking scenarios with two forms of libbso
22
See linker-tests.sh. If this patch fails to apply, regenerate from libbson's source.
33

44
diff --git a/src/libbson/src/bson/memory.c b/src/libbson/src/bson/memory.c
5-
index 0e1523331..aa7112305 100644
5+
index 0d84ea53e5..ad0f8eb0aa 100644
66
--- a/src/libbson/src/bson/memory.c
77
+++ b/src/libbson/src/bson/memory.c
8-
@@ -104,6 +104,7 @@ bson_malloc0 (size_t num_bytes) /* IN */
8+
@@ -140,6 +140,7 @@ bson_malloc0(size_t num_bytes) /* IN */
99
{
1010
void *mem = NULL;
1111

12-
+ printf (".from libbson1.");
13-
if (BSON_LIKELY (num_bytes)) {
14-
if (BSON_UNLIKELY (!(mem = gMemVtable.calloc (1, num_bytes)))) {
15-
fprintf (stderr, "Failure to allocate memory in bson_malloc0(). errno: %d.\n", errno);
12+
+ printf(".from libbson1.");
13+
if (BSON_LIKELY(num_bytes)) {
14+
if (BSON_UNLIKELY(!(mem = gMemVtable.calloc(1, num_bytes)))) {
15+
fprintf(stderr, "Failure to allocate memory in bson_malloc0(). errno: %d.\n", errno);
16+

.evergreen/linker_tests_deps/bson_patches/libbson2.patch

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ Adds a printf to bson_malloc0 to test linking scenarios with two forms of libbso
22
See linker-tests.sh. If this patch fails to apply, regenerate from libbson's source.
33

44
diff --git a/src/libbson/src/bson/memory.c b/src/libbson/src/bson/memory.c
5-
index 0e1523331..aa7112305 100644
5+
index 0d84ea53e5..ad0f8eb0aa 100644
66
--- a/src/libbson/src/bson/memory.c
77
+++ b/src/libbson/src/bson/memory.c
8-
@@ -104,6 +104,7 @@ bson_malloc0 (size_t num_bytes) /* IN */
8+
@@ -140,6 +140,7 @@ bson_malloc0(size_t num_bytes) /* IN */
99
{
1010
void *mem = NULL;
1111

12-
+ printf (".from libbson2.\n");
13-
if (BSON_LIKELY (num_bytes)) {
14-
if (BSON_UNLIKELY (!(mem = gMemVtable.calloc (1, num_bytes)))) {
15-
fprintf (stderr, "Failure to allocate memory in bson_malloc0(). errno: %d.\n", errno);
12+
+ printf(".from libbson2.");
13+
if (BSON_LIKELY(num_bytes)) {
14+
if (BSON_UNLIKELY(!(mem = gMemVtable.calloc(1, num_bytes)))) {
15+
fprintf(stderr, "Failure to allocate memory in bson_malloc0(). errno: %d.\n", errno);
16+

.evergreen/prep_c_driver_source.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -euxo pipefail
44

55
# Clone mongo-c-driver and check out to a tagged version.
6-
MONGO_C_DRIVER_VERSION=2.1.0
6+
MONGO_C_DRIVER_VERSION=2.3.0
77

88
# Force checkout with lf endings since .sh must have lf, not crlf on Windows
99
git clone https://github.com/mongodb/mongo-c-driver.git --config core.eol=lf --config core.autocrlf=false --depth=1 --branch $MONGO_C_DRIVER_VERSION

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### Changed
1212

1313
- Final release packages in the PPA are now available by specifying `release` in the repository configuration in place of the major/minor version (e.g., `1.17`). Details in `README.md`.
14+
- Bump downloaded libbson version from 2.1.0 to 2.3.0.
1415

1516
### Deprecated
1617
- RHEL 6.2 builds are deprecated and may be removed in the future. The `linux-x86_64-glibc_2_7-nocrypto` release build may be used instead and has equivalent glibc requirements.

cmake/FetchMongoC.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ include (FetchContent)
22

33
# Set the tag that we will fetch.
44
# When updating the version of libbson, also update the version in etc/purls.txt and .evergreen/prep_c_driver_source.sh
5-
set (MONGOC_FETCH_TAG_FOR_LIBBSON "2.1.0" CACHE STRING "The Git tag of mongo-c-driver that will be fetched to obtain libbson")
5+
set (MONGOC_FETCH_TAG_FOR_LIBBSON "2.3.0" CACHE STRING "The Git tag of mongo-c-driver that will be fetched to obtain libbson")
66

77
# Add an option to disable patching if a patch command is unavailable.
88
option (LIBBSON_PATCH_ENABLED "Whether to apply patches to the libbson library" ON)

etc/cyclonedx.sbom.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"components": [
33
{
4-
"bom-ref": "pkg:github/mongodb/mongo-c-driver@v2.1.0#src/libbson",
4+
"bom-ref": "pkg:github/mongodb/mongo-c-driver@v2.3.0#src/libbson",
55
"copyright": "Copyright 2009-present MongoDB, Inc.",
66
"externalReferences": [
77
{
88
"type": "distribution",
9-
"url": "https://github.com/mongodb/mongo-c-driver/archive/refs/tags/v2.1.0.tar.gz"
9+
"url": "https://github.com/mongodb/mongo-c-driver/archive/v2.3.0.tar.gz"
1010
},
1111
{
1212
"type": "website",
13-
"url": "https://github.com/mongodb/mongo-c-driver/tree/v2.1.0"
13+
"url": "https://github.com/mongodb/mongo-c-driver/tree/v2.3.0"
1414
}
1515
],
1616
"group": "mongodb",
@@ -22,9 +22,9 @@
2222
}
2323
],
2424
"name": "mongo-c-driver",
25-
"purl": "pkg:github/mongodb/mongo-c-driver@v2.1.0#src/libbson",
25+
"purl": "pkg:github/mongodb/mongo-c-driver@v2.3.0#src/libbson",
2626
"type": "library",
27-
"version": "v2.1.0"
27+
"version": "v2.3.0"
2828
},
2929
{
3030
"bom-ref": "pkg:generic/IntelRDFPMathLib@20U2?download_url=https://www.netlib.org/misc/intel/IntelRDFPMathLib20U2.tar.gz",
@@ -53,11 +53,11 @@
5353
"ref": "pkg:generic/IntelRDFPMathLib@20U2?download_url=https://www.netlib.org/misc/intel/IntelRDFPMathLib20U2.tar.gz"
5454
},
5555
{
56-
"ref": "pkg:github/mongodb/mongo-c-driver@v2.1.0#src/libbson"
56+
"ref": "pkg:github/mongodb/mongo-c-driver@v2.3.0#src/libbson"
5757
}
5858
],
5959
"metadata": {
60-
"timestamp": "2025-11-10T20:52:37.547279+00:00",
60+
"timestamp": "2026-04-21T13:26:40.166707+00:00",
6161
"tools": [
6262
{
6363
"externalReferences": [

etc/libbson-remove-GCC-diagnostic-pragma.patch

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,54 @@
11
diff --git a/src/common/src/common-bson-dsl-private.h b/src/common/src/common-bson-dsl-private.h
2-
index b6cb7a2705..c2cb0bcaf2 100644
2+
index 748ba54046..67a6a4f194 100644
33
--- a/src/common/src/common-bson-dsl-private.h
44
+++ b/src/common/src/common-bson-dsl-private.h
55
@@ -31,6 +31,13 @@ enum {
6-
BSON_IF_WINDOWS (__declspec (selectany)) \
7-
BSON_IF_POSIX (__attribute__ ((weak)))
6+
BSON_IF_WINDOWS(__declspec(selectany)) \
7+
BSON_IF_POSIX(__attribute__((weak)))
88

99
+#if defined(__GNUC__) && !defined(__clang__) && ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))
1010
+// Using GCC < 4.6
1111
+// Do not define `GCC diagnostic` pragma for GCC < 4.6.
12-
+#define _bsonDSL_disableWarnings() ((void) 0)
13-
+#define _bsonDSL_restoreWarnings() ((void) 0)
12+
+#define _bsonDSL_disableWarnings() ((void)0)
13+
+#define _bsonDSL_restoreWarnings() ((void)0)
1414
+#else
1515
+// Not using GCC < 4.6
1616
#ifdef __GNUC__
1717
// GCC has a bug handling pragma statements that disable warnings within complex
1818
// nested macro expansions. If we're GCC, just disable -Wshadow outright:
19-
@@ -50,7 +57,7 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
20-
mlib_diagnostic_pop (); \
19+
@@ -50,7 +57,7 @@ BSON_IF_GNU_LIKE(_Pragma("GCC diagnostic ignored \"-Wshadow\""))
20+
mlib_diagnostic_pop(); \
2121
} else \
22-
((void) 0)
22+
((void)0)
2323
-
2424
+#endif
2525
/**
2626
* @brief Parse the given BSON document.
2727
*
28+
diff --git a/src/common/src/common-macros-private.h b/src/common/src/common-macros-private.h
29+
index 068b09470f..b5c94c5c9d 100644
30+
--- a/src/common/src/common-macros-private.h
31+
+++ b/src/common/src/common-macros-private.h
32+
@@ -97,7 +97,13 @@
33+
#endif
34+
35+
// Disable the -Wcast-qual warning
36+
-#if defined(__GNUC__)
37+
+#if defined(__GNUC__) && !defined(__clang__) && ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))
38+
+// Using GCC < 4.6
39+
+// Do not define `GCC diagnostic` pragma for GCC < 4.6.
40+
+#define MC_DISABLE_CAST_QUAL_WARNING_BEGIN
41+
+#define MC_DISABLE_CAST_QUAL_WARNING_END
42+
+#elif defined(__GNUC__)
43+
+// Not using GCC < 4.6
44+
#define MC_DISABLE_CAST_QUAL_WARNING_BEGIN MC_PRAGMA_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
45+
#define MC_DISABLE_CAST_QUAL_WARNING_END MC_PRAGMA_DIAGNOSTIC_POP
46+
#elif defined(__clang__)
2847
diff --git a/src/common/src/mlib/config.h b/src/common/src/mlib/config.h
29-
index 6a1e45275b..797f278250 100644
48+
index a95f917efb..d1494797cd 100644
3049
--- a/src/common/src/mlib/config.h
3150
+++ b/src/common/src/mlib/config.h
32-
@@ -175,7 +175,13 @@
51+
@@ -204,7 +204,13 @@
3352
* @brief Expands to `noexcept` when compiled as C++, otherwise expands to
3453
* nothing
3554
*/
@@ -38,25 +57,25 @@ index 6a1e45275b..797f278250 100644
3857
+// Don't define this expansion for the older gcc/g++
3958
+#define mlib_noexcept
4059
+#else
41-
#define mlib_noexcept MLIB_IF_CXX (noexcept)
60+
#define mlib_noexcept MLIB_IF_CXX(noexcept)
4261
+#endif
4362

4463
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
4564
#define mlib_is_little_endian() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
46-
@@ -253,15 +259,29 @@
65+
@@ -282,15 +288,29 @@
4766

48-
#define MLIB_FUNC MLIB_IF_GNU_LIKE (__func__) MLIB_IF_MSVC (__FUNCTION__)
67+
#define MLIB_FUNC MLIB_IF_GNU_LIKE(__func__) MLIB_IF_MSVC(__FUNCTION__)
4968

5069
+#if defined(__GNUC__) && !defined(__clang__) && ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))
5170
+// Using GCC < 4.6
5271
+// Do not define `GCC diagnostic` pragma for GCC < 4.6.
5372
+#define mlib_diagnostic_push()
5473
+#else
5574
+// Not using GCC < 4.6
56-
#define mlib_diagnostic_push() \
57-
MLIB_IF_GNU_LIKE (mlib_pragma (GCC diagnostic push);) \
58-
MLIB_IF_MSVC (mlib_pragma (warning (push));) \
59-
mlib_static_assert (1, "")
75+
#define mlib_diagnostic_push() \
76+
MLIB_IF_GNU_LIKE(mlib_pragma(GCC diagnostic push);) \
77+
MLIB_IF_MSVC(mlib_pragma(warning(push));) \
78+
mlib_static_assert(1, "")
6079
+#endif
6180

6281
+#if defined(__GNUC__) && !defined(__clang__) && ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))
@@ -65,15 +84,15 @@ index 6a1e45275b..797f278250 100644
6584
+#define mlib_diagnostic_pop()
6685
+#else
6786
+// Not using GCC < 4.6
68-
#define mlib_diagnostic_pop() \
69-
MLIB_IF_GNU_LIKE (mlib_pragma (GCC diagnostic pop);) \
70-
MLIB_IF_MSVC (mlib_pragma (warning (pop));) \
71-
mlib_static_assert (1, "")
87+
#define mlib_diagnostic_pop() \
88+
MLIB_IF_GNU_LIKE(mlib_pragma(GCC diagnostic pop);) \
89+
MLIB_IF_MSVC(mlib_pragma(warning(pop));) \
90+
mlib_static_assert(1, "")
7291
+#endif
7392

74-
#define mlib_gcc_warning_disable(Warning) \
75-
MLIB_IF_GCC (mlib_pragma (GCC diagnostic ignored Warning);) \
76-
@@ -315,9 +335,15 @@
93+
#define mlib_gcc_warning_disable(Warning) \
94+
MLIB_IF_GCC(mlib_pragma(GCC diagnostic ignored Warning);) \
95+
@@ -344,9 +364,15 @@
7796
/**
7897
* @brief Emit a _Pragma that will disable warnings about the use of deprecated entities.
7998
*/
@@ -82,9 +101,9 @@ index 6a1e45275b..797f278250 100644
82101
+#define mlib_disable_deprecation_warnings()
83102
+#else
84103
+// Not using GCC < 4.6
85-
#define mlib_disable_deprecation_warnings() \
86-
mlib_gnu_warning_disable ("-Wdeprecated-declarations"); \
87-
mlib_msvc_warning (disable : 4996)
104+
#define mlib_disable_deprecation_warnings() \
105+
mlib_gnu_warning_disable("-Wdeprecated-declarations"); \
106+
mlib_msvc_warning(disable : 4996)
88107
+#endif
89108

90109
/**

etc/purls.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# `copyright` property. This information can be manually added.
99

1010
# libbson is obtained via `cmake/FetchMongoC.cmake`.
11-
pkg:github/mongodb/mongo-c-driver@v2.1.0?#src/libbson
11+
pkg:github/mongodb/mongo-c-driver@v2.3.0?#src/libbson
1212

1313
# IntelDFP is obtained via `cmake/IntelDFP.cmake`
1414
pkg:generic/IntelRDFPMathLib@20U2?download_url=https://www.netlib.org/misc/intel/IntelRDFPMathLib20U2.tar.gz

src/mc-fle2-find-range-payload-v2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bool mc_FLE2FindRangePayloadV2_serialize(const mc_FLE2FindRangePayloadV2_t *payl
6767
}
6868
// Append "payload.g" array of EdgeTokenSets.
6969
bson_t g_bson;
70-
if (!BSON_APPEND_ARRAY_BEGIN(&payload_bson, "g", &g_bson)) {
70+
if (!BSON_APPEND_ARRAY_UNSAFE_BEGIN(&payload_bson, "g", &g_bson)) {
7171
return false;
7272
}
7373

0 commit comments

Comments
 (0)