From: Paul Eggert Date: Sun, 13 Jul 2025 07:07:46 +0000 (-0700) Subject: insert-file-contents unexpected end shrinkage X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b8f3fcf2b8ef95e2b75958da819731aedb1a1238;p=emacs.git 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) --- 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;