# JLSEC-2026-1389: Heap buffer overflow when `read_command` on a collection fails in Mongoc.jl

- Severity: not scored yet
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Published: 2026-11-19T22:47:03.447Z
- Modified: 2026-11-19T23:00:35.538Z

## Description

### Description

`Mongoc.read_command(collection, command)` called the wrong libmongoc function. Its binding for
`mongoc_collection_read_command_with_opts` called `mongoc_collection_command_simple`, which takes one
argument fewer, so libmongoc read every argument after `read_prefs` one place early. libmongoc wrote
its `bson_error_t` into the reply document, wrote the reply into the caller's `options` document (or
discarded it when no options were given), and never filled in the error that Mongoc.jl reads, so
the exception thrown for a failure carried no error code or message.

The reply document is a 128-byte `bson_t` that `bson_new` allocates on the C heap. A `bson_error_t`
is 512 bytes. When the command fails, libmongoc writes to the last byte of the error, 384 bytes past
the end of the allocation. A message longer than about 120 bytes also writes its text past the end.
The message comes from the MongoDB server or from libmongoc, and server messages can echo parts of
the command: the error for an unknown query operator includes the operator's name.

Calls that succeeded returned an empty document instead of the reply. A call with `options`
overwrote the caller's options document with the reply.

Only `read_command(collection, ...)` is affected. A comparison of all of the package's `ccall`s with
the libmongoc headers found no other wrong function or argument count.

### Impact

Each failing `read_command(collection, ...)` call corrupts the C heap of the Julia process. This can
crash the process or corrupt unrelated memory. A malicious or compromised MongoDB server controls the
text written past the allocation. When an application builds the command from user input, that user
can influence the text too. No exploit beyond heap corruption was demonstrated.

### Patches

Fixed in Mongoc.jl 0.10.2, which calls `mongoc_collection_read_command_with_opts`. Upgrade to 0.10.2
or later.

### Workarounds

`Mongoc.read_command(collection.database, command; options)` runs the same command through the
database binding, which calls the correct function.

### Credits

The binding error was found and fixed by hhaensel in Mongoc.jl pull request #162. The out-of-bounds
write was found while that fix was reviewed.

(As written by Julia Security Advisories.)

## Affected

- Mongoc (Julia): from 0.4.0 before 0.10.2

## References

- <https://github.com/JuliaDatabases/Mongoc.jl/commit/793615d2af2e0e103d2e92e8a3bd725cdf7de2c0> (web)
- <https://github.com/JuliaDatabases/Mongoc.jl/pull/162> (web)
- <https://github.com/JuliaDatabases/Mongoc.jl/releases/tag/v0.10.2> (web)

## Sources

- Julia Security Advisories: [JLSEC-2026-1389](https://osv.dev/vulnerability/JLSEC-2026-1389), CC-BY-4.0, modified 2026-11-19

---

Page: https://cve.day/JLSEC-2026-1389 · Whole record: https://cve.day/JLSEC-2026-1389.json · Rebuilt by cve.day 2026-11-25T22:56:25.964Z
