Subject: bug#23397: 25.0.92; assertion failure auto-reverting a file being overwritten

From: Eli Zaretskii <[email-masked]>
Date: Mon, 02 May 2016 19:47:57 +0300

> From: Ken Raeburn <[email-masked]>
> Date: Thu, 28 Apr 2016 18:05:29 -0400
> 
> I'm running the emacs-25 branch as of revision a1f221b, but with commit
> d82f24b reverted (attempting to debug #23013), and built with
> MARKER_DEBUG enabled (as Eli pointed out, probably not relevant to
> #23013) along with assertions.
> 
> I was using "git" to update a source tree while about twenty files from
> it were loaded into Emacs buffers. Auto-revert was triggered; during the
> process, Finsert_file_contents was loading a Perl file when it invoked
> BYTE_TO_CHAR:
> 
> 	  /* Don't try to reuse the same piece of text twice.  */
> 	  overlap = (same_at_start - BEGV_BYTE
> 		     - (same_at_end
> 			+ (! NILP (end) ? end_offset : st.st_size) - ZV_BYTE));
> 	  if (overlap > 0)
> 	    same_at_end += overlap;
> 	  same_at_end_charpos = BYTE_TO_CHAR (same_at_end);
> 
> ...with same_at_end well out of range (Z_BYTE=12451, same_at_end=24673).
> The reverting appears to have happened while the file was in the process
> of being updated, as st.st_size is zero.

So you are saying that the file's contents was updated between the
time we called 'fstat' at the beginning of the function and the time
we used st.st_size in the above snippet?

If so, perhaps we should call 'fstat' again each time we want to use
st.st_size, and retry from the beginning if we find a mismatch?

> I haven't managed to reproduce this so far.

You could artificially modify the value of st.st_size in the debugger,
and then see what happens.

Thanks.