]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
llama-mmap: fix direct-io loading fallback EOF exception (#18801)
authorRuben Ortlam <redacted>
Tue, 13 Jan 2026 14:57:07 +0000 (15:57 +0100)
committerGitHub <redacted>
Tue, 13 Jan 2026 14:57:07 +0000 (15:57 +0100)
src/llama-mmap.cpp

index 2da857b3aaec22b90782fd1d61afd922af1a45b8..0c43495b11db3d4e7fadd79efc3d0f93c66b89a7 100644 (file)
@@ -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 {