emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

24.2.92 fix [Re: Crash caused by insert-file-contents, both trunk (bzr 1


From: Dmitry Antipov
Subject: 24.2.92 fix [Re: Crash caused by insert-file-contents, both trunk (bzr 111532) and 24.2.92 affected]
Date: Mon, 21 Jan 2013 12:55:04 +0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

On 01/18/2013 11:34 PM, Eli Zaretskii wrote:

I'm not sure I see how the gap size fails to be updated.  There's a
call to make_gap just before read_non_regular is called.  Or did you
mean GAP_SIZE?  If the latter, then the comments there explain why
this is not done.

Argh. We fool itself with gap_size (src/fileio.c, 24.2.92):

  4098              /* Maybe make more room.  */
  4099              if (gap_size < trytry)
  4100                {
  4101                  make_gap (total - gap_size);
  4102                  gap_size = GAP_SIZE;           /* !!! here */
  4103                }

After that, local gap_size (e.g. amount of bytes which may be used to
read next chunk from the file) is GAP_SIZE - inserted, not GAP_SIZE.

But until GAP_SIZE and ZV are updated, the inserted text is not
really part of the buffer, right?  So what is the problem here?

Here is the original code (src/fileio.c, 24.2.92):

  4169    /* Make the text read part of the buffer.  */
  4170    GAP_SIZE -= inserted;
  4171    GPT      += inserted;
  4172    GPT_BYTE += inserted;
  4173    ZV       += inserted;
  4174    ZV_BYTE  += inserted;
  4175    Z        += inserted;
  4176    Z_BYTE   += inserted;
  4177                                                                    /* !!! 
`inserted' bytes becomes "really inserted" */
  4178    if (GAP_SIZE > 0)
  4179      /* Put an anchor to ensure multi-byte form ends at gap.  */
  4180      *GPT_ADDR = 0;
  4181
  4182    emacs_close (fd);
  4183
  4184    /* Discard the unwind protect for closing the file.  */
  4185    specpdl_ptr--;
  4186
  4187    if (how_much < 0)
  4188      error ("IO error reading %s: %s",                             /* 
error leaves `inserted' bytes not decoded !!! */
  4189             SDATA (orig_filename), emacs_strerror (errno));

Attached is the fix for 24.2.92, and I believe that this is important
for the next pretest. For trunk, I'll revert 111547 and do the similar fix.

Dmitry

Attachment: insert_file_contents.patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]