Skip to content

CDRIVER-5915: Fix for allocation of bson_t larger than half max size #1891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
4 commits merged into from
Mar 3, 2025

Conversation

ghost
Copy link

@ghost ghost commented Feb 27, 2025

This PR 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

This fixes allocation for bson_t that are exactly max size, and adds a test which exercises this case on 64-bit systems.

@ghost ghost force-pushed the CDRIVER-5915 branch from b852a8e to 072b44d Compare February 27, 2025 19:51
@ghost ghost requested review from kevinAlbs and eramongodb February 27, 2025 19:52
The new name doesn't misleadingly imply that the result is always a power of two.
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Changes LGTM. Left a question and possible suggestion for a parameter rename.

* Rename parameters to disambiguate total vs additional size
* Document and test expectations around range of sums when computing new sizes
* Add additional size check to bson_reserve_buffer() to uphold _bson_grow() expectations on 32-bit
* Add warning to bson_reserve_buffer() documentation about lack of document validation in the suggested usage.
@ghost ghost requested a review from eramongodb March 1, 2025 00:30
@ghost
Copy link
Author

ghost commented Mar 1, 2025

Ok, that last commit rolls up I think a reasonable set of changes which clarify the size limits without sprawling too much.

From the commit description:

  • Rename parameters to disambiguate total vs additional size
  • Document and test expectations around the range of summed values when computing new sizes
  • Add additional size check to bson_reserve_buffer() to uphold _bson_grow() expectations on 32-bit
  • Add warning to bson_reserve_buffer() documentation about lack of document validation in the suggested usage.

@ghost ghost requested a review from kevinAlbs March 1, 2025 00:33
@ghost ghost merged commit 57bffac into mongodb:master Mar 3, 2025
40 of 42 checks passed
@ghost ghost deleted the CDRIVER-5915 branch March 3, 2025 16:37
kevinAlbs pushed a commit that referenced this pull request Mar 4, 2025
…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
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants