Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes and improvements

* Fix memory-safety issues in the model loader (#2068) by [@jordimas](https://github.com/jordimas), reported by Chegne Eu Joe (Project Umbra)
* Upgrade Thrust submodule from 1.12.0 to CCCL 2.7.0 (#2062) by [@jordimas](https://github.com/jordimas)

## [v4.8.0](https://github.com/OpenNMT/CTranslate2/releases/tag/v4.8.0) (2026-06-06)
Expand Down
6 changes: 5 additions & 1 deletion src/models/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ namespace ctranslate2 {
template<>
std::string consume(std::istream& in) {
const auto str_length = consume<uint16_t>(in);
if (str_length == 0)
throw std::runtime_error("Invalid string length in " + binary_file);
const auto c_str = consume<char>(in, str_length);
std::string str(c_str);
std::string str(c_str, str_length - 1);
delete [] c_str;
return str;
}
Expand Down Expand Up @@ -654,6 +656,8 @@ namespace ctranslate2 {
}

StorageView variable(std::move(shape), dtype);
if (num_bytes != variable.size() * variable.item_size())
throw std::runtime_error("Variable '" + name + "' has an invalid payload size");
consume<char>(model_file, num_bytes, static_cast<char*>(variable.buffer()));
if (tensor_parallel) {
int outer_dim = 0;
Expand Down
Loading