Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bson/_cbsonmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,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;
Expand Down
7 changes: 7 additions & 0 deletions test/test_bson.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ def test_invalid_decodes(self):
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"
Expand Down