CTranslate2 Model Loader Heap Overflows
- Date
- Affected
- OpenNMT / CTranslate2
- Class
- Heap buffer overflow (OOB read + OOB write)
- Severity
- High
- CVSS
- 8.5 CVE-2026-102566 · v4.0CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
- 7.8 CVE-2026-102566 · v3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
- 6.9 CVE-2026-102567 · v4.0CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:P/VC:L/VI:N/VA:H/SC:N/SI:N/SA:N
- 6.1 CVE-2026-102567 · v3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:H
- Identifiers
- CVE-2026-102566, CVE-2026-102567
Two heap overflows in CTranslate2's model loader, both reachable by loading a crafted model file. A string field with no null terminator causes an out-of-bounds read. An unchecked tensor length causes an out-of-bounds write. Fixed in CTranslate2 4.8.1 (PR #2068).
Overview
CTranslate2 is OpenNMT’s C++ inference engine for Transformer models. Its model loader has two heap overflows, and loading a crafted model file triggers both:
- CVE-2026-102567: an out-of-bounds read when a string field has no null terminator.
- CVE-2026-102566: an out-of-bounds write when a tensor’s declared length is larger than its buffer.
The bugs affect versions earlier than 4.8.1. To fix them, upgrade to 4.8.1.
Both bugs come from one pattern. Model::load (src/models/model.cc) reads length fields from the file and uses them without checking them against the buffers they fill.
Out-of-bounds read in string deserialization
consume<std::string> reads each string field in a model file, such as the spec name and each variable name:
std::string consume(std::istream& in) {
const auto str_length = consume<uint16_t>(in);
const auto c_str = consume<char>(in, str_length);
std::string str(c_str);
delete [] c_str;
return str;
}
The function works in three steps:
- It reads a 16-bit length prefix,
str_length. - It allocates
str_lengthbytes and fills them from the file. Nothing guarantees that those bytes contain a null terminator. - It builds the string with
std::string(c_str). That constructor ignoresstr_lengthand callsstrlento find the end.
If the buffer has no null byte, strlen reads past the end of the allocation until it finds one elsewhere on the heap. The returned string can include heap memory that followed the buffer.
Out-of-bounds write in variable loading
For each variable, StorageView allocates a buffer sized from the shape and dtype in the file. The loader then reads num_bytes bytes into that buffer, and num_bytes also comes from the file:
StorageView variable(std::move(shape), dtype);
consume<char>(model_file, num_bytes, static_cast<char*>(variable.buffer()));
The loader never compares num_bytes with the buffer size. A file that declares a small shape and a large num_bytes writes past the end of the allocation. The file controls both the length and the contents of that write.
Fix
CTranslate2 4.8.1 includes the fix from PR #2068. The fix makes two changes:
- It passes
str_lengthto the string constructor, so the string no longer depends on a null terminator. - It rejects any variable whose payload size doesn’t match its buffer.
std::string str(c_str, str_length);
// ...
if (num_bytes != variable.size_in_bytes())
throw std::runtime_error("Variable '" + name + "' has an invalid payload size");
