GNU bug report logs - #10701
24.0.93; Crash while decoding input with DOS EOLs

Previous Next

Package: emacs;

Reported by: Eli Zaretskii <eliz <at> gnu.org>

Date: Thu, 2 Feb 2012 18:19:02 UTC

Severity: important

Found in version 24.0.93

Fixed in version 24.0.94

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 10701 in the body.
You can then email your comments to 10701 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#10701; Package emacs. (Thu, 02 Feb 2012 18:19:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eli Zaretskii <eliz <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 02 Feb 2012 18:19:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: bug-gnu-emacs <at> gnu.org
Cc: Kenichi Handa <handa <at> m17n.org>
Subject: 24.0.93; Crash while decoding input with DOS EOLs
Date: Thu, 02 Feb 2012 20:15:39 +0200
This bug report will be sent to the Bug-GNU-Emacs mailing list
and the GNU bug tracker at debbugs.gnu.org.  Please check that
the From: line contains a valid email address.  After a delay of up
to one day, you should receive an acknowledgement at that address.

Please write in English if possible, as the Emacs maintainers
usually do not have translators for other languages.

Please describe exactly what actions triggered the bug, and
the precise symptoms of the bug.  If you can, give a recipe
starting from `emacs -Q':

I see this both with today's trunk and in the 24.0.93 pretest, both on
GNU/Linux and on MS-Windows.

To reproduce:

 emacs -Q
 C-x b foo RET
 M-: (set-buffer-multibyte nil) RET
 C-x RET c undecided-dos RET C-u M-! gunzip -c emacs-24.0.93.tar.gz RET

(It must be the tarball of Emacs 24.0.93, because the bug is
data-dependent.  It doesn't have to be .tar.gz, as long as you use the
correct decompressor: bunzip2 for .tar.bz2. xz for .tar.xz, etc.  You
can even do this with an uncompressed tarball and cat.  The important
part is that Emacs gets the byte stream of that tarball, and it gets
it from a subprocess.)

This crashes somewhere in the middle of reading the output from the
subprocess.  The immediate reason for the crash can be seen from this
fragment of the backtrace:

  #0  w32_abort () at w32fns.c:7196
  #1  0x012eea83 in temp_set_point_both (buffer=0x10137600, charpos=45817604,
      bytepos=45817605) at intervals.c:1870
  #2  0x01135816 in Fcall_process (nargs=6, args=0x82f644) at callproc.c:846

As you see temp_set_point_both gets character position and byte
position that are different, which cannot happen in a unibyte buffer
(as can be seen above, the recipe makes the buffer `foo' a unibyte
one).  There's an assertion inside temp_set_point_both that aborts due
to this.

The call to temp_set_point_both is in call-process:

		  TEMP_SET_PT_BOTH (PT + process_coding.produced_char,
				    PT_BYTE + process_coding.produced);
		  carryover = process_coding.carryover_bytes;
		  if (carryover > 0)
		    memcpy (buf, process_coding.carryover,
			    process_coding.carryover_bytes);

The crash happens at the point in the input byte stream where the last
byte in the chunk we read from the pipe is \r.  Since the stream is
decoded with raw-text-dos coding-system, this last \r is left as a
"carryover", for the possibility that there will be a \n at the
beginning of the next chunk.  However, process_coding.produced does
not account for this single byte that was not processed, and gets the
value one more than it should.

As far as I could see, the problematic code that sets
process_coding.produced to incorrect value is in decode_coding, around
line 7176:

      else
	{
	  /* Record unprocessed bytes in coding->carryover.  We are
	     sure that the number of data is less than the size of
	     coding->carryover.  */
	  unsigned char *p = coding->carryover;

	  if (nbytes > sizeof coding->carryover)
	    nbytes = sizeof coding->carryover;
	  coding->carryover_bytes = nbytes;
	  while (nbytes-- > 0)
	    *p++ = *src++;
	}
      coding->consumed = coding->src_bytes; <<<<<<<<<<<<<<<<<<<

This last assignment then causes produce_chars to set
coding->produced to an incorrect value:

      /* Source characters are at coding->source.  */
      const unsigned char *src = coding->source;
      const unsigned char *src_end = src + coding->consumed; <<<<<<<<<<<<
      ...
	  produced_chars = coding->consumed_char;
	  while (src < src_end)
	    *dst++ = *src++;
	}
    }

  produced = dst - (coding->destination + coding->produced);  <<<<<<<<<<<
  if (BUFFERP (coding->dst_object) && produced_chars > 0)
    insert_from_gap (produced_chars, produced);
  coding->produced += produced; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  coding->produced_char += produced_chars;

I don't understand the logic of "carryover" in decode_coding well
enough to decide how to fix it.

If Emacs crashed, and you have the Emacs process in the gdb debugger,
please include the output from the following gdb commands:
    `bt full' and `xbacktrace'.
For information about debugging Emacs, please read the file
d:/gnu/bzr/emacs/trunk/etc/DEBUG.


In GNU Emacs 24.0.93.1 (i386-mingw-nt5.1.2600)
 of 2012-02-02 on HOME-C4E4A596F7
Windowing system distributor `Microsoft Corp.', version 5.1.2600
Configured using:
 `configure --with-gcc (3.4) --no-opt'

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: ENU
  value of $XMODIFIERS: nil
  locale-coding-system: cp1255
  default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
M-x r e p o r t - e m <tab> <return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr message format-spec rfc822 mml easymenu
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mailabbrev mail-utils gmm-utils mailheader
emacsbug time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel
dos-w32 disp-table ls-lisp w32-win w32-vars tool-bar dnd fontset image
fringe lisp-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev minibuffer loaddefs button faces cus-face files text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process multi-tty emacs)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10701; Package emacs. (Fri, 03 Feb 2012 08:58:01 GMT) Full text and rfc822 format available.

Message #8 received at 10701 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 10701 <at> debbugs.gnu.org
Subject: Re: bug#10701: 24.0.93; Crash while decoding input with DOS EOLs
Date: Fri, 03 Feb 2012 09:56:38 +0100
(with-temp-buffer
  (let ((coding-system-for-read 'undecided-dos))
    (set-buffer-multibyte nil)
    (shell-command "yes 'a\r'" t)))

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10701; Package emacs. (Fri, 03 Feb 2012 15:44:02 GMT) Full text and rfc822 format available.

Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Leo <sdl.web <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#10701: 24.0.93; Crash while decoding input with DOS EOLs
Date: Fri, 03 Feb 2012 23:41:54 +0800
On 2012-02-03 16:56 +0800, Andreas Schwab wrote:
> (with-temp-buffer
>   (let ((coding-system-for-read 'undecided-dos))
>     (set-buffer-multibyte nil)
>     (shell-command "yes 'a\r'" t)))

Crash emacs 23.4 as well!

Leo





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10701; Package emacs. (Wed, 08 Feb 2012 08:36:02 GMT) Full text and rfc822 format available.

Message #14 received at 10701 <at> debbugs.gnu.org (full text, mbox):

From: Kenichi Handa <handa <at> m17n.org>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: 10701 <at> debbugs.gnu.org, eliz <at> gnu.org
Subject: Re: bug#10701: 24.0.93; Crash while decoding input with DOS EOLs
Date: Wed, 08 Feb 2012 17:33:39 +0900
In article <m2liokcn21.fsf <at> igel.home>, Andreas Schwab <schwab <at> linux-m68k.org> writes:

> (with-temp-buffer
>   (let ((coding-system-for-read 'undecided-dos))
>     (set-buffer-multibyte nil)
>     (shell-command "yes 'a\r'" t)))

I've just installed a fix to emacs-23 branch.

---
Kenichi Handa
handa <at> m17n.org




bug marked as fixed in version 24.0.94, send any further explanations to 10701 <at> debbugs.gnu.org and Eli Zaretskii <eliz <at> gnu.org> Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 09 Feb 2012 07:50:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10701; Package emacs. (Fri, 10 Feb 2012 11:07:01 GMT) Full text and rfc822 format available.

Message #19 received at 10701 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Kenichi Handa <handa <at> m17n.org>
Cc: 10701 <at> debbugs.gnu.org, schwab <at> linux-m68k.org
Subject: Re: bug#10701: 24.0.93; Crash while decoding input with DOS EOLs
Date: Fri, 10 Feb 2012 13:05:15 +0200
> From: Kenichi Handa <handa <at> m17n.org>
> Cc: eliz <at> gnu.org, 10701 <at> debbugs.gnu.org
> Date: Wed, 08 Feb 2012 17:33:39 +0900
> 
> In article <m2liokcn21.fsf <at> igel.home>, Andreas Schwab <schwab <at> linux-m68k.org> writes:
> 
> > (with-temp-buffer
> >   (let ((coding-system-for-read 'undecided-dos))
> >     (set-buffer-multibyte nil)
> >     (shell-command "yes 'a\r'" t)))
> 
> I've just installed a fix to emacs-23 branch.

Thanks, confirmed.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 09 Mar 2012 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 165 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.