From: Ruben Ortlam Date: Tue, 13 Jan 2026 14:57:07 +0000 (+0100) Subject: llama-mmap: fix direct-io loading fallback EOF exception (#18801) X-Git-Tag: upstream/0.0.8067~342 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=960e5e3b46f211b3c4446ce8380e88404274dbce;p=pkg%2Fggml%2Fsources%2Fllama.cpp llama-mmap: fix direct-io loading fallback EOF exception (#18801) --- diff --git a/src/llama-mmap.cpp b/src/llama-mmap.cpp index 2da857b3a..0c43495b1 100644 --- a/src/llama-mmap.cpp +++ b/src/llama-mmap.cpp @@ -244,11 +244,14 @@ struct llama_file::impl { } errno = 0; if (fd == -1) { - std::size_t ret = std::fread(ptr, len, 1, fp); + const size_t curr_off = tell(); + const size_t to_read = std::min(len, size - curr_off); + + std::size_t ret = std::fread(ptr, to_read, 1, fp); if (ferror(fp)) { throw std::runtime_error(format("read error: %s", strerror(errno))); } - if (ret != 1) { + if (to_read > 0 && ret != 1) { throw std::runtime_error("unexpectedly reached end of file"); } } else {