From ed7a58640f3c5a967ab2a6e762a9ca1234a6e317 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Thu, 20 Jun 2024 11:40:05 -0700 Subject: [PATCH] PYTHON-4323 Add regression test for out-of-bounds read when decoding invalid bson (#1695) --- test/test_bson.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/test_bson.py b/test/test_bson.py index 89c0983ca5..fec84090d2 100644 --- a/test/test_bson.py +++ b/test/test_bson.py @@ -23,6 +23,7 @@ import os import pickle import re +import struct import sys import tempfile import uuid @@ -489,6 +490,33 @@ def test_basic_encode(self): b"\x00", ) + def test_bad_code(self): + # Assert that decoding invalid Code with scope does not include a field name. + def generate_payload(length: int) -> bytes: + string_size = length - 0x1E + + return bytes.fromhex( + struct.pack("