Skip to content
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

PYTHON-4305 Fix bson size check #1564

Merged
merged 1 commit into from
Mar 27, 2024
Merged

Conversation

ShaneHarvey
Copy link
Member

@@ -2311,7 +2312,8 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,
memcpy(&code_size, buffer + *position, 4);
code_size = BSON_UINT32_FROM_LE(code_size);
/* code_w_scope length + code length + code + scope length */
if (!code_size || max < code_size || max < 4 + 4 + code_size + 4) {
len = 4 + 4 + code_size + 4;
if (!code_size || max < code_size || max < len || len < code_size) {
Copy link
Member Author

Choose a reason for hiding this comment

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

len < code_size catches when len overflows.

/* code length + code + scope length + scope */
if ((4 + code_size + 4 + scope_size) != c_w_s_size) {
len = 4 + 4 + code_size + scope_size;
if (scope_size < BSON_MIN_SIZE || len != c_w_s_size || len < scope_size) {
Copy link
Member Author

Choose a reason for hiding this comment

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

len < scope_size catches when len overflows.

Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

LGTM!

@blink1073 blink1073 merged commit 372b5d6 into mongodb:master Mar 27, 2024
71 of 75 checks passed
blink1073 pushed a commit that referenced this pull request Mar 27, 2024
@ShaneHarvey ShaneHarvey deleted the PYTHON-4305 branch March 28, 2024 00:47
@carnil
Copy link

carnil commented Jun 10, 2024

This is related to CVE-2024-5629

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.

3 participants