You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CDRIVER-5915: Fix for allocation of bson_t larger than half max size (#1891)
addresses CDRIVER-5915, fixing three closely related problems:
* rounding allocation size to the next power of two could cause BSON_MAX_SIZE to be exceeded
* bson_reserve_buffer allocated more space than requested, equal to the previous document length
* test_bson_reserve_buffer_errors had a flawed "too big" case which was masked by the other two issues
additionally:
* adds a test for allocating bson_t of exactly max size (on 64-bit systems only)
* fix for potential integer overflow in bson_reserve_buffer() with overlong size
* comments and assertions related to bson_t max size assumptions
* ``size``: The length in bytes of the new buffer.
18
+
* ``total_size``: The length in bytes of the new buffer.
19
19
20
20
Description
21
21
-----------
22
22
23
-
Grow the internal buffer of ``bson`` to ``size`` and set the document length to ``size``. Useful for eliminating copies when reading BSON bytes from a stream.
23
+
Grow the internal buffer of ``bson`` to ``total_size`` and set the document length to ``total_size``. Useful for eliminating copies when reading BSON bytes from a stream.
24
24
25
-
First, initialize ``bson`` with :symbol:`bson_init` or :symbol:`bson_new`, then call this function. After it returns, the length of ``bson`` is set to ``size`` but its contents are uninitialized memory: you must fill the contents with a BSON document of the correct length before any other operations.
25
+
First, initialize ``bson`` with :symbol:`bson_init` or :symbol:`bson_new`, then call this function. After it returns, the length of ``bson`` is set to ``total_size`` but its contents are uninitialized memory: you must fill the contents with a BSON document of the correct length before any other operations.
26
26
27
27
The document must be freed with :symbol:`bson_destroy`.
28
28
29
+
Note that, in this usage, the BSON header and footer bytes will not be verified or used by Libbson.
30
+
The ``bson_t`` document length and buffer size limit are both set to ``total_size`` regardless of the value encoded in the document header.
31
+
29
32
Returns
30
33
-------
31
34
32
-
A pointer to the internal buffer, which is at least ``size`` bytes, or NULL if the space could not be allocated.
35
+
A pointer to the internal buffer, which is at least ``total_size`` bytes, or NULL if the space could not be allocated.
0 commit comments