Skip to content

PYTHON-6163 Pure-Python decode_all silently accepts 1-byte invalid BSON - #3117

Merged
blink1073 merged 2 commits into
mongodb:mainfrom
blink1073:PYTHON-6163
Oct 13, 2026
Merged

blink1073 merged 2 commits into
mongodb:mainfrom
blink1073:PYTHON-6163

Conversation

@blink1073

Copy link
Copy Markdown
Member

PYTHON-6163

Changes in this PR

The pure-Python decoder silently accepted buffers ending in a partial document, while the C extension raises InvalidBSON. The Python version now applies the same checks and messages.

Test Plan

  • Added a regression test covering 1 to 4 byte buffers, a trailing partial after a valid document, and empty input, across bytes, bytearray, and memoryview.
  • BSON suite passes with and without the C extension (100 tests each); the new test fails without the fix in pure-Python mode.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)? Not yet; add an entry under unreleased bug fixes before merge.
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s). PYTHON-4232

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Align the error message with the C implementation and add the required changelog entry.

2 open findings
What changed in this PR

Updates pure-Python decode_all to reject truncated BSON consistently with the C extension.

Changes:

  • Adds BSON size and boundary validation.
  • Adds regression tests for partial buffers and supported buffer types.
File Summary
bson/​__init__.py Adds pure-Python BSON size validation.
test/​test_bson.py Adds truncated-document regression coverage.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread bson/__init__.py Outdated
Comment thread test/test_bson.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The validation, regression tests, and changelog updates fully address the reported issue.

0 open findings

2 resolved since last review

🧠 Review effort: Lite

@blink1073
blink1073 marked this pull request as ready for review October 13, 2026 16:32
@blink1073
blink1073 requested a review from a team as a code owner October 13, 2026 16:33
@blink1073
blink1073 requested a review from aclark4life October 13, 2026 16:33
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bson/__init__.py 16.66% 3 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@aclark4life aclark4life left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@blink1073
blink1073 merged commit e0b11bf into mongodb:main Oct 13, 2026
81 of 93 checks passed
@blink1073
blink1073 deleted the PYTHON-6163 branch October 13, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants