VDB
Sign up
HIGH8.2

GHSA-98qm-wvgf-w4cf

MongoDB Python Driver: Out-of-bounds read in BSON decoding via a malformed Regex element

Quick fix

GHSA-98qm-wvgf-w4cf — pymongo: upgrade to the fixed version with the command below.

pip install --upgrade 'pymongo>=4.18.3'

Details

### 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]).

Are you affected?

Enter the version of the package you're using.

Affected packages

PyPI/pymongo
Introduced in: 3.9.0Fixed in: 4.18.3
Fixpip install --upgrade 'pymongo>=4.18.3'

References

Check it before you install it

One call answers whether to add this package: known advisories, CISA KEV, and whether the name is a hallucinated or freshly squatted one. No key needed to try it.

curl -s https://vdb.ai.kr/v1/ai/check-packages \
  -H 'Content-Type: application/json' \
  -d '{"packages":["pkg:pypi/pymongo"]}'