Compare commits

...

3 Commits

Author SHA1 Message Date
Awni Hannun
5bcf3a6794 format 2025-10-22 16:08:47 -07:00
wickedcoder
7707196297 Merge commit from fork
* add length validation to the header

* fix accessing out of bound index with .at()
2025-10-22 15:31:25 -07:00
wickedcoder
7e3471c987 Merge commit from fork
* add tensor->weights_data validation

* add null pointer check for tensor
2025-10-22 15:31:03 -07:00
2 changed files with 9 additions and 2 deletions

View File

@@ -57,9 +57,16 @@ Shape get_shape(const gguf_tensor& tensor) {
}
std::tuple<allocator::Buffer, Dtype> extract_tensor_data(gguf_tensor* tensor) {
if (tensor == nullptr) {
throw std::invalid_argument(
"[extract_tensor_data] Input tensor pointer is null.");
}
std::optional<Dtype> 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(),

View File

@@ -265,7 +265,7 @@ array load(std::shared_ptr<io::Reader> in_stream, StreamOrDevice s) {
std::vector<char> buffer(header_len + 1);
in_stream->read(&buffer[0], header_len);
buffer[header_len] = 0;
std::string header(&buffer[0]);
std::string header(buffer.data(), header_len);
// Read data type from header
std::string dtype_str = header.substr(11, 3);
@@ -273,7 +273,7 @@ array load(std::shared_ptr<io::Reader> in_stream, StreamOrDevice s) {
Dtype dtype = dtype_from_array_protocol(dtype_str);
// Read contiguity order
bool col_contiguous = header[34] == 'T';
bool col_contiguous = header.at(34) == 'T';
// Read array shape from header
Shape shape;