From b8f3fcf2b8ef95e2b75958da819731aedb1a1238 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 13 Jul 2025 00:07:46 -0700 Subject: [PATCH] insert-file-contents unexpected end shrinkage * src/fileio.c (Finsert_file_contents): If the file unexpectedly shrinks while reading its tail backwards, give up searching for the match end. (cherry picked from commit f4adb56c9adc9b4f4715c656f1f8cfa7305479e5) --- src/fileio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/fileio.c b/src/fileio.c index 221cb175dd8..bd8528af235 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4523,12 +4523,17 @@ by calling `format-decode', which see. */) report_file_error ("Read error", orig_filename); else if (nread == 0) { + /* The file unexpectedly shrank. */ file_size_hint = curpos - trial + total_read; + giveup_match_end = true; break; } total_read += nread; } + if (giveup_match_end) + break; + /* Scan this bufferful from the end, comparing with the Emacs buffer. */ bufpos = total_read; -- 2.39.5