PYTHON-4305 Fix bson size check by ShaneHarvey · Pull Request #1564 · mongodb/mongo-python-driver

@ShaneHarvey

@ShaneHarvey

ShaneHarvey

/* 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) {

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) {

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.

blink1073

Choose a reason for hiding this comment

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

LGTM!

blink1073 pushed a commit that referenced this pull request

Mar 27, 2024
(cherry picked from commit 372b5d6)

@carnil