SERVER-102596: upgrade libbson to 1.28.1 (#34206)

GitOrigin-RevId: 86e52f88587862f7a0d73e7d11ad01fee416646d
This commit is contained in:
Nathan Frank 2025-03-31 13:13:43 -05:00 committed by MongoDB Bot
parent 491a4a89b7
commit dcfd5c6548
63 changed files with 254 additions and 120 deletions

View File

@ -50,7 +50,7 @@ a notice will be included in
| [LibTomCrypt] | WTFPL, Public Domain | 1.18.2 | ✗ | ✗ |
| [libunwind/libunwind] | MIT | v1.8.1 | | ✗ |
| [linenoise] | BSD-2-Clause | Unknown | | ✗ |
| [MongoDB C Driver] | Apache-2.0 | 1.27.6 | ✗ | ✗ |
| [MongoDB C Driver] | Apache-2.0 | 1.28.1 | ✗ | ✗ |
| [Mozilla Firefox] | MPL-2.0 | 128.8.0esr | unknown | ✗ |
| [nlohmann-json] | MIT | 3.11.3 | ✗ | |
| [nlohmann.json.decomposed] | MIT | 3.10.5 | unknown | |

View File

@ -1574,7 +1574,7 @@ def force_includes_hdr(package_name, name):
return []
# TODO(SERVER-102596): Stop including this flag when ASP is able to upgrade mongoc and mongocxx
# TODO(SERVER-103006): Stop including this flag when ASP is able to upgrade mongoc and mongocxx
STREAMS_THIRD_PARTY_DIR = "src/mongo/db/modules/enterprise/src/streams/third_party"
def package_specific_copt(package_name):

View File

@ -1191,7 +1191,7 @@
"name": "Organization: github"
},
"name": "MongoDB C Driver",
"version": "1.27.6",
"version": "1.28.1",
"licenses": [
{
"license": {
@ -1199,7 +1199,7 @@
}
}
],
"purl": "pkg:github/mongodb/mongo-c-driver@1.27.6",
"purl": "pkg:github/mongodb/mongo-c-driver@1.28.1",
"properties": [
{
"name": "internal:team_responsible",

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018-present MongoDB Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,3 +1,18 @@
/*
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "common-prelude.h"
@ -12,4 +27,32 @@
#define MONGOC_DEBUG_ASSERT(statement) ((void) 0)
#endif
// `MC_ENABLE_CONVERSION_WARNING_BEGIN` enables -Wconversion to check for potentially unsafe integer conversions.
// The `bson_in_range_*` functions can help address these warnings by ensuring a cast is within bounds.
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) // gcc 4.6 added support for "diagnostic push".
#define MC_ENABLE_CONVERSION_WARNING_BEGIN \
_Pragma ("GCC diagnostic push") _Pragma ("GCC diagnostic warning \"-Wconversion\"")
#define MC_ENABLE_CONVERSION_WARNING_END _Pragma ("GCC diagnostic pop")
#elif defined(__clang__)
#define MC_ENABLE_CONVERSION_WARNING_BEGIN \
_Pragma ("clang diagnostic push") _Pragma ("clang diagnostic warning \"-Wconversion\"")
#define MC_ENABLE_CONVERSION_WARNING_END _Pragma ("clang diagnostic pop")
#else
#define MC_ENABLE_CONVERSION_WARNING_BEGIN
#define MC_ENABLE_CONVERSION_WARNING_END
#endif
// Disable the -Wcast-function-type-strict warning.
#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_BEGIN
#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_END
#if defined(__clang__)
#if __has_warning("-Wcast-function-type-strict")
#undef MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_BEGIN
#undef MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_END
#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_BEGIN \
_Pragma ("clang diagnostic push") _Pragma ("clang diagnostic ignored \"-Wcast-function-type-strict\"")
#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_END _Pragma ("clang diagnostic pop")
#endif // __has_warning("-Wcast-function-type-strict")
#endif // defined(__clang__)
#endif /* COMMON_MACROS_PRIVATE_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018-present MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018-present MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-present MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2020-present MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,7 +24,7 @@ mcommon_thread_create (bson_thread_t *thread, BSON_THREAD_FUN_TYPE (func), void
{
BSON_ASSERT_PARAM (thread);
BSON_ASSERT_PARAM (func);
BSON_ASSERT (arg || true); // optional.
BSON_OPTIONAL_PARAM (arg); // optional.
return pthread_create (thread, NULL, func, arg);
}
int
@ -47,7 +47,7 @@ mcommon_thread_create (bson_thread_t *thread, BSON_THREAD_FUN_TYPE (func), void
{
BSON_ASSERT_PARAM (thread);
BSON_ASSERT_PARAM (func);
BSON_ASSERT (arg || true); // optional.
BSON_OPTIONAL_PARAM (arg); // optional.
*thread = (HANDLE) _beginthreadex (NULL, 0, func, arg, 0, NULL);
if (0 == *thread) {

View File

@ -1,3 +1,33 @@
libbson 1.28.1
==============
Fixes:
* Fix large string handling in `bson_string_truncate`.
* Fix possible crash in `bson_value_copy`.
Thanks to everyone who contributed to the development of this release.
* Joshua Siegel
* Kevin Albertson
libbson 1.28.0
==============
New features:
* Add `bson_validate_with_error_and_offset`.
Build Configuration:
* Remove automatic ccache detection and usage (CCache.cmake).
* Set [`CMAKE_<LANG>_COMPILER_LAUNCHER`](https://cmake.org/cmake/help/latest/envvar/CMAKE_LANG_COMPILER_LAUNCHER.html) to build with ccache.
* Remove `MONGO_USE_CCACHE` (no longer applicable; see above).
libbson 1.27.6
==============

View File

@ -34,7 +34,7 @@ BEGIN
VALUE "OriginalFilename", BSON_OUTPUT_BASENAME "-" BSON_API_VERSION ".dll"
VALUE "ProductName", "MongoDB C Driver"
VALUE "ProductVersion", BSON_VERSION_S
VALUE "LegalCopyright", "Copyright (C) 2013-present MongoDB, Inc."
VALUE "LegalCopyright", "Copyright 2009-present MongoDB, Inc."
END
END
BLOCK "VarFileInfo"

View File

@ -3,7 +3,7 @@
* @brief BCON (BSON C Object Notation) Implementation
*/
/* Copyright 2009-2013 MongoDB, Inc.
/* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -5,7 +5,7 @@
#include <bson/bson-prelude.h>
/* Copyright 2009-2013 MongoDB, Inc.
/* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -187,6 +187,7 @@ enum bson_memory_order {
BSON_UNREACHABLE ("Invalid bson_memory_order value"); \
}) \
BSON_IF_GNU_LEGACY_ATOMICS ({ \
BSON_UNUSED (order); \
__sync_synchronize (); \
return *a; \
}) \
@ -213,7 +214,7 @@ enum bson_memory_order {
default: \
BSON_UNREACHABLE ("Invalid bson_memory_order value"); \
}) \
BSON_IF_GNU_LEGACY_ATOMICS (return __sync_val_compare_and_swap (a, *a, value);) \
BSON_IF_GNU_LEGACY_ATOMICS (BSON_UNUSED (ord); return __sync_val_compare_and_swap (a, *a, value);) \
} \
\
static BSON_INLINE Type bson_atomic_##NamePart##_compare_exchange_strong ( \

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2022 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,11 +36,11 @@
#ifdef BSON_OS_WIN32
#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600)
#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0601)
#undef _WIN32_WINNT
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#define _WIN32_WINNT 0x0601
#endif
#ifndef NOMINMAX
#define NOMINMAX

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018-present MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,6 +1,6 @@
/*
* Copyright 2015 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -269,7 +269,9 @@ bson_decimal128_to_string (const bson_decimal128_t *dec, /* IN */
}
/* Exponent */
*(str_out++) = 'E';
bson_snprintf (str_out, 6, "%+d", scientific_exponent);
// Truncation is OK.
int req = bson_snprintf (str_out, 6, "%+d", scientific_exponent);
BSON_ASSERT (req > 0);
} else {
/* Regular format with no decimal place */
if (exponent >= 0) {
@ -280,8 +282,11 @@ bson_decimal128_to_string (const bson_decimal128_t *dec, /* IN */
} else {
int32_t radix_position = significand_digits + exponent;
// Reserve space for null terminator.
const int available_bytes = BSON_DECIMAL128_STRING - 1;
if (radix_position > 0) { /* non-zero digits before radix */
for (int32_t i = 0; i < radix_position && (str_out - str) < BSON_DECIMAL128_STRING; i++) {
for (int32_t i = 0; i < radix_position && (str_out - str) < available_bytes; i++) {
*(str_out++) = *(significand_read++) + '0';
}
} else { /* leading zero before radix point */
@ -294,7 +299,7 @@ bson_decimal128_to_string (const bson_decimal128_t *dec, /* IN */
}
for (uint32_t i = 0; bson_cmp_greater_us (significand_digits - i, BSON_MAX (radix_position - 1, 0)) &&
(str_out - str) < BSON_DECIMAL128_STRING;
(str_out - str) < available_bytes;
i++) {
*(str_out++) = *(significand_read++) + '0';
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,11 +20,6 @@
#ifndef BSON_ENDIAN_H
#define BSON_ENDIAN_H
#if defined(__sun)
#include <sys/byteorder.h>
#endif
#include <bson/bson-config.h>
#include <bson/bson-macros.h>
#include <bson/bson-compat.h>
@ -36,12 +31,7 @@ BSON_BEGIN_DECLS
#define BSON_BIG_ENDIAN 4321
#define BSON_LITTLE_ENDIAN 1234
#if defined(__sun)
#define BSON_UINT16_SWAP_LE_BE(v) BSWAP_16 ((uint16_t) v)
#define BSON_UINT32_SWAP_LE_BE(v) BSWAP_32 ((uint32_t) v)
#define BSON_UINT64_SWAP_LE_BE(v) BSWAP_64 ((uint64_t) v)
#elif defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__) && (__clang_major__ >= 3) && \
#if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__) && (__clang_major__ >= 3) && \
(__clang_minor__ >= 1)
#if __has_builtin(__builtin_bswap16)
#define BSON_UINT16_SWAP_LE_BE(v) __builtin_bswap16 (v)

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -62,6 +62,7 @@ bson_iter_init (bson_iter_t *iter, /* OUT */
iter->d4 = 0;
iter->next_off = 4;
iter->err_off = 0;
iter->value = (bson_value_t){0};
return true;
}
@ -640,7 +641,7 @@ fill_data_fields:
/* subtype 2 has a redundant length header in the data */
memcpy (&binary_len, (iter->raw + iter->d3), sizeof (binary_len));
binary_len = BSON_UINT32_FROM_LE (binary_len);
if (binary_len + 4 != l) {
if (binary_len != l - 4) {
iter->err_off = iter->d3;
goto mark_invalid;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2020 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@
#include <bson/bson-keys.h>
#include <bson/bson-string.h>
#include <bson/bson-cmp.h>
static const char *gUint32Strs[] = {
@ -141,5 +142,9 @@ bson_uint32_to_string (uint32_t value, /* IN */
*strptr = str;
return bson_snprintf (str, size, "%u", value);
int ret = bson_snprintf (str, size, "%u", value);
// Truncation is OK.
BSON_ASSERT (ret > 0);
BSON_ASSERT (bson_in_range_size_t_signed (ret));
return (size_t) ret;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -232,6 +232,10 @@
} \
} while (0)
// `BSON_OPTIONAL_PARAM` is a documentation-only macro to document X may be NULL.
// Useful in combination with `BSON_ASSERT_PARAM` to document and assert pointer parameters.
#define BSON_OPTIONAL_PARAM(param) (void) 0
/* obsolete macros, preserved for compatibility */
#define BSON_STATIC_ASSERT(s) BSON_STATIC_ASSERT_ (s, __LINE__)
#define BSON_STATIC_ASSERT_JOIN(a, b) BSON_STATIC_ASSERT_JOIN2 (a, b)

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018-present MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -292,7 +292,7 @@ bson_string_append_printf (bson_string_t *string, const char *format, ...)
* Truncate the string @string to @len bytes.
*
* The underlying memory will be released via realloc() down to
* the minimum required size specified by @len.
* the minimum required size (at power-of-two boundary) specified by @len.
*
* Returns:
* None.
@ -307,19 +307,17 @@ void
bson_string_truncate (bson_string_t *string, /* IN */
uint32_t len) /* IN */
{
uint32_t alloc;
BSON_ASSERT (string);
BSON_ASSERT (len < INT_MAX);
alloc = len + 1;
if (alloc < 16) {
alloc = 16;
BSON_ASSERT_PARAM (string);
if (len == string->len) {
return;
}
if (!bson_is_power_of_two (alloc)) {
alloc = (uint32_t) bson_next_power_of_two ((size_t) alloc);
uint32_t needed = len;
BSON_ASSERT (needed < UINT32_MAX);
needed += 1u; // Add one for trailing NULL byte.
uint32_t alloc = bson_next_power_of_two_u32 (needed);
if (alloc == 0) {
// Overflowed: saturate at UINT32_MAX.
alloc = UINT32_MAX;
}
string->str = bson_realloc (string->str, alloc);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -278,6 +278,15 @@ bson_utf8_escape_for_json (const char *utf8, /* IN */
end = utf8 + utf8_len;
while (utf8 < end) {
uint8_t mask;
uint8_t length_of_char;
// Check if expected char length goes past end
_bson_utf8_get_sequence (utf8, &length_of_char, &mask);
if (utf8 > end - length_of_char) {
goto invalid_utf8;
}
c = bson_utf8_get_char (utf8);
switch (c) {
@ -313,18 +322,25 @@ bson_utf8_escape_for_json (const char *utf8, /* IN */
if (c) {
utf8 = bson_utf8_next_char (utf8);
} else {
if (length_provided && !*utf8) {
/* we escaped nil as '\u0000', now advance past it */
utf8++;
if (length_provided) {
// Check if current character is null character,
// if so skip past it as we've already added '\\u0000' above
if (*utf8 == '\0' || (*utf8 == '\xc0' && *(utf8 + 1) == '\x80')) {
utf8 += (*utf8 == '\0') ? 1 : 2;
} else {
goto invalid_utf8;
}
} else {
/* invalid UTF-8 */
bson_string_free (str, true);
return NULL;
goto invalid_utf8;
}
}
}
return bson_string_free (str, false);
invalid_utf8:
bson_string_free (str, true);
return NULL;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@
#include <bson/bson-string.h>
#include <bson/bson-value.h>
#include <bson/bson-oid.h>
#include <bson/bson-cmp.h>
void
@ -35,8 +36,11 @@ bson_value_copy (const bson_value_t *src, /* IN */
dst->value.v_double = src->value.v_double;
break;
case BSON_TYPE_UTF8:
BSON_ASSERT (bson_in_range_size_t_unsigned (src->value.v_utf8.len));
size_t utf8_len_sz = (size_t) src->value.v_utf8.len;
BSON_ASSERT (utf8_len_sz <= SIZE_MAX - 1);
dst->value.v_utf8.len = src->value.v_utf8.len;
dst->value.v_utf8.str = bson_malloc (src->value.v_utf8.len + 1);
dst->value.v_utf8.str = bson_malloc (utf8_len_sz + 1);
memcpy (dst->value.v_utf8.str, src->value.v_utf8.str, dst->value.v_utf8.len);
dst->value.v_utf8.str[dst->value.v_utf8.len] = '\0';
break;
@ -68,28 +72,40 @@ bson_value_copy (const bson_value_t *src, /* IN */
dst->value.v_regex.options = bson_strdup (src->value.v_regex.options);
break;
case BSON_TYPE_DBPOINTER:
BSON_ASSERT (bson_in_range_size_t_unsigned (src->value.v_dbpointer.collection_len));
size_t dbpointer_len_sz = (size_t) src->value.v_dbpointer.collection_len;
BSON_ASSERT (dbpointer_len_sz <= SIZE_MAX - 1);
dst->value.v_dbpointer.collection_len = src->value.v_dbpointer.collection_len;
dst->value.v_dbpointer.collection = bson_malloc (src->value.v_dbpointer.collection_len + 1);
dst->value.v_dbpointer.collection = bson_malloc (dbpointer_len_sz + 1);
memcpy (
dst->value.v_dbpointer.collection, src->value.v_dbpointer.collection, dst->value.v_dbpointer.collection_len);
dst->value.v_dbpointer.collection[dst->value.v_dbpointer.collection_len] = '\0';
bson_oid_copy (&src->value.v_dbpointer.oid, &dst->value.v_dbpointer.oid);
break;
case BSON_TYPE_CODE:
BSON_ASSERT (bson_in_range_size_t_unsigned (src->value.v_code.code_len));
size_t code_len_sz = (size_t) src->value.v_code.code_len;
BSON_ASSERT (code_len_sz <= SIZE_MAX - 1);
dst->value.v_code.code_len = src->value.v_code.code_len;
dst->value.v_code.code = bson_malloc (src->value.v_code.code_len + 1);
dst->value.v_code.code = bson_malloc (code_len_sz + 1);
memcpy (dst->value.v_code.code, src->value.v_code.code, dst->value.v_code.code_len);
dst->value.v_code.code[dst->value.v_code.code_len] = '\0';
break;
case BSON_TYPE_SYMBOL:
BSON_ASSERT (bson_in_range_size_t_unsigned (src->value.v_symbol.len));
size_t symbol_len_sz = (size_t) src->value.v_symbol.len;
BSON_ASSERT (symbol_len_sz <= SIZE_MAX - 1);
dst->value.v_symbol.len = src->value.v_symbol.len;
dst->value.v_symbol.symbol = bson_malloc (src->value.v_symbol.len + 1);
dst->value.v_symbol.symbol = bson_malloc (symbol_len_sz + 1);
memcpy (dst->value.v_symbol.symbol, src->value.v_symbol.symbol, dst->value.v_symbol.len);
dst->value.v_symbol.symbol[dst->value.v_symbol.len] = '\0';
break;
case BSON_TYPE_CODEWSCOPE:
BSON_ASSERT (bson_in_range_size_t_unsigned (src->value.v_codewscope.code_len));
size_t codewscope_len_sz = (size_t) src->value.v_codewscope.code_len;
BSON_ASSERT (codewscope_len_sz <= SIZE_MAX - 1);
dst->value.v_codewscope.code_len = src->value.v_codewscope.code_len;
dst->value.v_codewscope.code = bson_malloc (src->value.v_codewscope.code_len + 1);
dst->value.v_codewscope.code = bson_malloc (codewscope_len_sz + 1);
memcpy (dst->value.v_codewscope.code, src->value.v_codewscope.code, dst->value.v_codewscope.code_len);
dst->value.v_codewscope.code[dst->value.v_codewscope.code_len] = '\0';
dst->value.v_codewscope.scope_len = src->value.v_codewscope.scope_len;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -3299,29 +3299,35 @@ _bson_validate_internal (const bson_t *bson, bson_validate_state_t *state)
bool
bson_validate (const bson_t *bson, bson_validate_flags_t flags, size_t *offset)
{
bson_validate_state_t state;
state.flags = flags;
_bson_validate_internal (bson, &state);
if (state.err_offset > 0 && offset) {
*offset = (size_t) state.err_offset;
}
return state.err_offset < 0;
return bson_validate_with_error_and_offset (bson, flags, offset, NULL);
}
bool
bson_validate_with_error (const bson_t *bson, bson_validate_flags_t flags, bson_error_t *error)
{
return bson_validate_with_error_and_offset (bson, flags, NULL, error);
}
bool
bson_validate_with_error_and_offset (const bson_t *bson,
bson_validate_flags_t flags,
size_t *offset,
bson_error_t *error)
{
bson_validate_state_t state;
state.flags = flags;
_bson_validate_internal (bson, &state);
if (state.err_offset > 0 && error) {
memcpy (error, &state.error, sizeof *error);
if (state.err_offset > 0) {
if (offset) {
*offset = (size_t) state.err_offset;
}
if (error) {
memcpy (error, &state.error, sizeof *error);
}
}
return state.err_offset < 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -454,6 +454,25 @@ BSON_EXPORT (bool)
bson_validate_with_error (const bson_t *bson, bson_validate_flags_t flags, bson_error_t *error);
/**
* bson_validate_with_error_and_offset:
* @bson: A bson_t.
* @offset: A location for the error offset.
* @error: A location for the error info.
*
* Validates a BSON document by walking through the document and inspecting
* the fields for valid content.
*
* Returns: true if @bson is valid; otherwise false, @offset is set
* and @error is filled out.
*/
BSON_EXPORT (bool)
bson_validate_with_error_and_offset (const bson_t *bson,
bson_validate_flags_t flags,
size_t *offset,
bson_error_t *error);
/**
* bson_as_json_with_opts:
* @bson: A bson_t.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018-present MongoDB, Inc.
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,4 +15,4 @@
*/
/* Including bson.h is superseded. Use bson/bson.h instead. */
#include "bson/bson.h"
#include "bson/bson.h"

View File

@ -18,7 +18,7 @@ if grep -q Microsoft /proc/version; then
fi
NAME=libbson
VERSION=1.27.6
VERSION=1.28.1
if grep -q Microsoft /proc/version; then
SRC_ROOT=$(wslpath -u $(powershell.exe -Command "Get-ChildItem Env:TEMP | Get-Content | Write-Host"))