Skip to content

Commit 16b8e1f

Browse files
committed
avoid int32 overflow prior to bson_append_utf8 invocation
1 parent 2b5c35a commit 16b8e1f

File tree

1 file changed

+8
-7
lines changed
  • src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/builder

1 file changed

+8
-7
lines changed

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

+8-7
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)