From f145c7db940f72cb9ad76b99793267f619e63217 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 7 May 2026 15:23:00 -0400 Subject: [PATCH 1/2] PYTHON-5756 - Fix BSON Binary type length bug (#2790) --- bson/_cbsonmodule.c | 2 +- test/test_bson.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c index 330a52a73..366129936 100644 --- a/bson/_cbsonmodule.c +++ b/bson/_cbsonmodule.c @@ -2281,7 +2281,7 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer, } memcpy(&length, buffer + *position, 4); length = BSON_UINT32_FROM_LE(length); - if (max < length) { + if (max - 5 < length) { // Account for 5-byte header. max >= 5 guaranteed above goto invalid; } diff --git a/test/test_bson.py b/test/test_bson.py index ffc02965f..ae1807e5f 100644 --- a/test/test_bson.py +++ b/test/test_bson.py @@ -1269,6 +1269,22 @@ class TestBSON(unittest.TestCase): encode(doc) self.assertEqual(cm.exception.document, doc) + def test_binary_length_accounts_for_header(self): + size = 20 + binary_length = 12 # 5 more than the actual 7 bytes + + payload = b"" + payload += struct.pack(" Date: Thu, 7 May 2026 15:23:07 -0400 Subject: [PATCH 2/2] PYTHON-5708 - Unskip large encryption tests on mongocryptd (#2793) --- test/asynchronous/test_encryption.py | 4 ---- test/test_encryption.py | 4 ---- 2 files changed, 8 deletions(-) diff --git a/test/asynchronous/test_encryption.py b/test/asynchronous/test_encryption.py index 1503f54c7..455b1940c 100644 --- a/test/asynchronous/test_encryption.py +++ b/test/asynchronous/test_encryption.py @@ -876,8 +876,6 @@ class TestViews(AsyncEncryptionIntegrationTest): class TestCorpus(AsyncEncryptionIntegrationTest): - # PYTHON-5708: Encryption tests sending large payloads fail on some mongocryptd versions. - @async_client_context.require_version_max(6, 99) @unittest.skipUnless(any(AWS_CREDS.values()), "AWS environment credentials are not set") async def asyncSetUp(self): await super().asyncSetUp() @@ -1054,8 +1052,6 @@ class TestBsonSizeBatches(AsyncEncryptionIntegrationTest): client_encrypted: AsyncMongoClient listener: OvertCommandListener - # PYTHON-5708: Encryption tests sending large payloads fail on some mongocryptd versions. - @async_client_context.require_version_max(6, 99) async def asyncSetUp(self): await super().asyncSetUp() db = async_client_context.client.db diff --git a/test/test_encryption.py b/test/test_encryption.py index 099336227..7df9e7ac3 100644 --- a/test/test_encryption.py +++ b/test/test_encryption.py @@ -872,8 +872,6 @@ class TestViews(EncryptionIntegrationTest): class TestCorpus(EncryptionIntegrationTest): - # PYTHON-5708: Encryption tests sending large payloads fail on some mongocryptd versions. - @client_context.require_version_max(6, 99) @unittest.skipUnless(any(AWS_CREDS.values()), "AWS environment credentials are not set") def setUp(self): super().setUp() @@ -1050,8 +1048,6 @@ class TestBsonSizeBatches(EncryptionIntegrationTest): client_encrypted: MongoClient listener: OvertCommandListener - # PYTHON-5708: Encryption tests sending large payloads fail on some mongocryptd versions. - @client_context.require_version_max(6, 99) def setUp(self): super().setUp() db = client_context.client.db