From a83c461dba8c95d02f5ae7028f57e8eeac9b09f1 Mon Sep 17 00:00:00 2001 From: liubo Date: Wed, 8 Nov 2023 14:55:35 +0800 Subject: [PATCH] Add missing error message to InvalidBSON error Signed-off-by: liubo --- ...missing-error-message-to-InvalidBSON.patch | 46 +++++++++++++++++++ python-pymongo.spec | 6 ++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 0001-PYTHON-2631-Add-missing-error-message-to-InvalidBSON.patch diff --git a/0001-PYTHON-2631-Add-missing-error-message-to-InvalidBSON.patch b/0001-PYTHON-2631-Add-missing-error-message-to-InvalidBSON.patch new file mode 100644 index 0000000..2f6de67 --- /dev/null +++ b/0001-PYTHON-2631-Add-missing-error-message-to-InvalidBSON.patch @@ -0,0 +1,46 @@ +From 9e01a6bf1d081c62ac2173f666234de159397e0c Mon Sep 17 00:00:00 2001 +From: Shane Harvey +Date: Fri, 2 Apr 2021 10:17:04 -0700 +Subject: [PATCH] PYTHON-2631 Add missing error message to InvalidBSON error + (#589) + +(cherry picked from commit cc029a1e6208863eaab453777363d3935b927f32) +--- + bson/_cbsonmodule.c | 2 +- + test/test_bson.py | 7 +++++++ + 2 files changed, 8 insertions(+), 1 deletion(-) + +diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c +index 34f3ab6f..1522bb0a 100644 +--- a/bson/_cbsonmodule.c ++++ b/bson/_cbsonmodule.c +@@ -2621,7 +2621,7 @@ static int _element_to_dict(PyObject* self, const char* string, + if (name_length > BSON_MAX_SIZE || position + name_length >= max) { + PyObject* InvalidBSON = _error("InvalidBSON"); + if (InvalidBSON) { +- PyErr_SetNone(InvalidBSON); ++ PyErr_SetString(InvalidBSON, "field name too large"); + Py_DECREF(InvalidBSON); + } + return -1; +diff --git a/test/test_bson.py b/test/test_bson.py +index ad726f71..f75da3d2 100644 +--- a/test/test_bson.py ++++ b/test/test_bson.py +@@ -373,6 +373,13 @@ class TestBSON(unittest.TestCase): + with self.assertRaises(InvalidBSON, msg=msg): + list(decode_file_iter(scratch)) + ++ def test_invalid_field_name(self): ++ # Decode a truncated field ++ with self.assertRaises(InvalidBSON) as ctx: ++ decode(b'\x0b\x00\x00\x00\x02field\x00') ++ # Assert that the InvalidBSON error message is not empty. ++ self.assertTrue(str(ctx.exception)) ++ + def test_data_timestamp(self): + self.assertEqual({"test": Timestamp(4, 20)}, + decode(b"\x13\x00\x00\x00\x11\x74\x65\x73\x74\x00\x14" +-- +2.42.0.windows.2 + diff --git a/python-pymongo.spec b/python-pymongo.spec index 30c72e4..c2c7991 100644 --- a/python-pymongo.spec +++ b/python-pymongo.spec @@ -1,11 +1,12 @@ Name: python-pymongo Version: 3.11.3 -Release: 1 +Release: 2 License: Apache License 2.0 Summary: PyMongo - the Python driver for MongoDB URL: https://github.com/mongodb/mongo-python-driver Source0: https://files.pythonhosted.org/packages/72/82/e7196f2f69318dd206db26db68fcfa0ff821d88fbca6d0f0c7b678ba0353/pymongo-3.11.3.tar.gz Patch01: 0001-Use-ssl.match_hostname-from-the-Python-stdlib.patch +Patch02: 0001-PYTHON-2631-Add-missing-error-message-to-InvalidBSON.patch BuildRequires: python3-devel python3-setuptools BuildRequires: python3-sphinx gcc @@ -85,6 +86,9 @@ python3 setup.py test %{_pkgdocdir} %changelog +* Wed Nov 8 2023 liubo - 3.11.3-2 +- Add missing error message to InvalidBSON error + * Fri Aug 06 2021 OpenStack_SIG - 3.11.3-1 - Update version to 3.11.3 -- Gitee