Skip to content

Commit d1b35d0

Browse files
author
Micah Scott
committed
Revert "libbson bugfix, allow allocating max size documents"
This reverts commit 6f732fc. (Moved to CDRIVER-5915)
1 parent abbe3cc commit d1b35d0

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

src/libbson/src/bson/bson.c

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <bson/bson-json-private.h>
2222
#include <common-string-private.h>
2323
#include <common-json-private.h>
24-
#include <common-macros-private.h>
2524
#include <bson/bson-iso8601-private.h>
2625

2726
#include <string.h>
@@ -61,31 +60,6 @@ typedef struct {
6160
*/
6261
static const uint8_t gZero;
6362

64-
/*
65-
*--------------------------------------------------------------------------
66-
*
67-
* _bson_next_power_of_two_for_alloc --
68-
*
69-
* Given a potential allocation length no greater than BSON_MAX_SIZE,
70-
* round it up to the next power of two without exceeding BSON_MAX_SIZE.
71-
*
72-
* Returns:
73-
* A value >= the input size and <= BSON_MAX_SIZE.
74-
*
75-
* Side effects:
76-
* None.
77-
*
78-
*--------------------------------------------------------------------------
79-
*/
80-
81-
static BSON_INLINE size_t
82-
_bson_next_power_of_two_for_alloc (size_t size)
83-
{
84-
MONGOC_DEBUG_ASSERT (size <= BSON_MAX_SIZE);
85-
size_t power_of_two = bson_next_power_of_two (size);
86-
return BSON_MIN (power_of_two, BSON_MAX_SIZE);
87-
}
88-
8963
/*
9064
*--------------------------------------------------------------------------
9165
*
@@ -116,7 +90,7 @@ _bson_impl_inline_grow (bson_impl_inline_t *impl, /* IN */
11690
return true;
11791
}
11892

119-
req = _bson_next_power_of_two_for_alloc (impl->len + size);
93+
req = bson_next_power_of_two (impl->len + size);
12094

12195
if (req <= BSON_MAX_SIZE) {
12296
data = bson_malloc (req);
@@ -176,7 +150,7 @@ _bson_impl_alloc_grow (bson_impl_alloc_t *impl, /* IN */
176150
return true;
177151
}
178152

179-
req = _bson_next_power_of_two_for_alloc (req);
153+
req = bson_next_power_of_two (req);
180154

181155
if ((req <= BSON_MAX_SIZE) && impl->realloc) {
182156
*impl->buf = impl->realloc (*impl->buf, req, impl->realloc_func_ctx);
@@ -194,8 +168,7 @@ _bson_impl_alloc_grow (bson_impl_alloc_t *impl, /* IN */
194168
* _bson_grow --
195169
*
196170
* Grows the bson_t structure to be large enough to contain @size
197-
* bytes in addition to its current content. The caller is responsible
198-
* for ensuring the new summed size is <= BSON_MAX_SIZE.
171+
* bytes.
199172
*
200173
* Returns:
201174
* true if successful, false if the size would overflow.
@@ -210,9 +183,6 @@ static bool
210183
_bson_grow (bson_t *bson, /* IN */
211184
uint32_t size) /* IN */
212185
{
213-
// Already checked by caller in all build types
214-
MONGOC_DEBUG_ASSERT ((size_t) bson->len <= BSON_MAX_SIZE && (size_t) size <= BSON_MAX_SIZE - (size_t) bson->len);
215-
216186
if ((bson->flags & BSON_FLAG_INLINE)) {
217187
return _bson_impl_inline_grow ((bson_impl_inline_t *) bson, size);
218188
}
@@ -2127,7 +2097,7 @@ bson_copy_to (const bson_t *src, bson_t *dst)
21272097
}
21282098

21292099
data = _bson_data (src);
2130-
len = _bson_next_power_of_two_for_alloc ((size_t) src->len);
2100+
len = bson_next_power_of_two ((size_t) src->len);
21312101

21322102
adst = (bson_impl_alloc_t *) dst;
21332103
adst->flags = BSON_FLAG_STATIC;
@@ -2249,10 +2219,6 @@ bson_reserve_buffer (bson_t *bson, uint32_t size)
22492219
return NULL;
22502220
}
22512221

2252-
MONGOC_DEBUG_ASSERT ((size_t) bson->len <= BSON_MAX_SIZE);
2253-
if ((size_t) size > BSON_MAX_SIZE - (size_t) bson->len) {
2254-
return NULL;
2255-
}
22562222
if (!_bson_grow (bson, size)) {
22572223
return NULL;
22582224
}

0 commit comments

Comments
 (0)