From 7e3471c98711ee09bcefe56590c4c4e0815e76e5 Mon Sep 17 00:00:00 2001 From: wickedcoder <96148289+wickgit@users.noreply.github.com> Date: Thu, 23 Oct 2025 01:31:03 +0300 Subject: [PATCH] Merge commit from fork * add tensor->weights_data validation * add null pointer check for tensor --- mlx/io/gguf.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mlx/io/gguf.cpp b/mlx/io/gguf.cpp index ed6ea11dd..00ce95a58 100644 --- a/mlx/io/gguf.cpp +++ b/mlx/io/gguf.cpp @@ -57,9 +57,15 @@ Shape get_shape(const gguf_tensor& tensor) { } std::tuple extract_tensor_data(gguf_tensor* tensor) { + if (tensor == nullptr) { + throw std::invalid_argument("[extract_tensor_data] Input tensor pointer is null."); + } std::optional equivalent_dtype = gguf_type_to_dtype(tensor->type); // If there's an equivalent type, we can simply copy. if (equivalent_dtype.has_value()) { + if (tensor->weights_data == nullptr) { + throw std::runtime_error("[load_gguf] NULL tensor data pointer"); + } allocator::Buffer buffer = allocator::malloc(tensor->bsize); memcpy( buffer.raw_ptr(),