# GHSA-98QM-WVGF-W4CF: MongoDB Python Driver: Out-of-bounds read in BSON decoding via a malformed Regex element

- Database: GitHub
- Severity: high (stated by ghsa, no CVSS score)
- Published: 2026-10-27
- Modified: 2026-10-27

## Tracked as

- [CVE-2026-106435](https://cve.now/CVE-2026-106435.md): Application denial of service via out-of-bounds read in BSON Regex decoding in MongoDB Python Driver

## Affected versions

- pymongo (PyPI): from 3.9.0, fixed in 4.18.3

## Description

### Impact
The C extension's BSON decoder scans a Regex element's pattern and flags strings with strlen before checking the document's remaining length, so a crafted truncated Regex element can read past the end of the caller's buffer. bson.decode and bson.decode_all accept mmap and array buffers, which carry no NUL sentinel; the read can cross into unmapped memory and kill the process with an uncatchable SIGSEGV. Any application decoding untrusted BSON from such buffers is affected — impact is availability only, since the out-of-bounds bytes are never returned as content. NUL-terminated buffers (bytes, bytearray) raise `InvalidBSON` at worst; the driver's own transport and pure-Python installs are not affected. All releases through 4.18.2 are affected when the C extension is loaded.

### Patches
Fixed in PyMongo 4.18.3. Malformed Regex elements now raise InvalidBSON on every accepted buffer type; valid documents decode unchanged.

###  Workarounds
Decode untrusted BSON only from NUL-terminated buffers — bytes or bytearray — and copy mmap input first, e.g. bytes(mm[:size]).

## References

- https://github.com/mongodb/mongo-python-driver/security/advisories/GHSA-98qm-wvgf-w4cf
- https://nvd.nist.gov/vuln/detail/CVE-2026-106435
- https://github.com/mongodb/mongo-python-driver/pull/3109
- https://github.com/mongodb/mongo-python-driver/commit/bb8d4e195275e75bd94ebeffb53cc747d357fcf4
- https://github.com/mongodb/mongo-python-driver
- https://github.com/mongodb/mongo-python-driver/releases/tag/4.18.3
- https://jira.mongodb.org/browse/PYTHON-6110

Page: https://cve.now/GHSA-98QM-WVGF-W4CF

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
