PYTHON-5214 - Improve BSON decoding InvalidBSON error message (#2605)

This commit is contained in:
Noah Stapp 2025-10-29 14:30:18 -04:00 committed by GitHub
parent fd02550349
commit b607ef144c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1109,7 +1109,9 @@ def _decode_all(data: _ReadableBuffer, opts: CodecOptions[_DocumentType]) -> lis
while position < end:
obj_size = _UNPACK_INT_FROM(data, position)[0]
if data_len - position < obj_size:
raise InvalidBSON("invalid object size")
raise InvalidBSON(
f"invalid object size: expected {obj_size}, got {data_len - position}"
)
obj_end = position + obj_size - 1
if data[obj_end] != 0:
raise InvalidBSON("bad eoo")