Skip to content

Commit 7707196

Browse files
authored
Merge commit from fork
* add length validation to the header * fix accessing out of bound index with .at()
1 parent 7e3471c commit 7707196

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mlx/io/load.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ array load(std::shared_ptr<io::Reader> in_stream, StreamOrDevice s) {
265265
std::vector<char> buffer(header_len + 1);
266266
in_stream->read(&buffer[0], header_len);
267267
buffer[header_len] = 0;
268-
std::string header(&buffer[0]);
268+
std::string header(buffer.data(), header_len);
269269

270270
// Read data type from header
271271
std::string dtype_str = header.substr(11, 3);
272272
bool read_is_big_endian = dtype_str[0] == '>';
273273
Dtype dtype = dtype_from_array_protocol(dtype_str);
274274

275275
// Read contiguity order
276-
bool col_contiguous = header[34] == 'T';
276+
bool col_contiguous = header.at(34) == 'T';
277277

278278
// Read array shape from header
279279
Shape shape;

0 commit comments

Comments
 (0)