]> git.eshelyaron.com Git - emacs.git/commitdiff
insert-file-contents unexpected end shrinkage
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 13 Jul 2025 07:07:46 +0000 (00:07 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 24 Jul 2025 08:49:01 +0000 (10:49 +0200)
* 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

index 221cb175dd8cfaf143c7368be5f9c835c2b77a76..bd8528af235c694c0291859f423f49803c3dc053 100644 (file)
@@ -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;