From: Anri Lombard Date: Wed, 31 Dec 2025 15:29:03 +0000 (+0200) Subject: quantize: prevent input/output file collision (#18451) X-Git-Tag: upstream/0.0.7599~4 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=33ded988ba9a5514036d64334f803334047a15d8;p=pkg%2Fggml%2Fsources%2Fllama.cpp quantize: prevent input/output file collision (#18451) Check if input and output files are the same before quantizing to prevent file corruption when mmap reads from a file being written to. Fixes #12753 --- diff --git a/tools/quantize/quantize.cpp b/tools/quantize/quantize.cpp index 470dc3d9..881f4b3d 100644 --- a/tools/quantize/quantize.cpp +++ b/tools/quantize/quantize.cpp @@ -12,6 +12,7 @@ #include #include #include +#include struct quant_option { std::string name; @@ -643,6 +644,11 @@ int main(int argc, char ** argv) { return 1; } + if (std::error_code ec; std::filesystem::equivalent(fname_inp, fname_out, ec)) { + fprintf(stderr, "%s: error: input and output files are the same: '%s'\n", __func__, fname_inp.c_str()); + return 1; + } + print_build_info(); fprintf(stderr, "%s: quantizing '%s' to '%s' as %s", __func__, fname_inp.c_str(), fname_out.c_str(), ftype_str.c_str());