Skip to content

Commit 7e3471c

Browse files
authored
Merge commit from fork
* add tensor->weights_data validation * add null pointer check for tensor
1 parent 9f0ba3d commit 7e3471c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

mlx/io/gguf.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@ Shape get_shape(const gguf_tensor& tensor) {
5757
}
5858

5959
std::tuple<allocator::Buffer, Dtype> extract_tensor_data(gguf_tensor* tensor) {
60+
if (tensor == nullptr) {
61+
throw std::invalid_argument("[extract_tensor_data] Input tensor pointer is null.");
62+
}
6063
std::optional<Dtype> equivalent_dtype = gguf_type_to_dtype(tensor->type);
6164
// If there's an equivalent type, we can simply copy.
6265
if (equivalent_dtype.has_value()) {
66+
if (tensor->weights_data == nullptr) {
67+
throw std::runtime_error("[load_gguf] NULL tensor data pointer");
68+
}
6369
allocator::Buffer buffer = allocator::malloc(tensor->bsize);
6470
memcpy(
6571
buffer.raw_ptr(),

0 commit comments

Comments
 (0)