all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Fwd: Crash when buffer is edited while save-buffer asks for coding system
@ 2008-01-10  0:45 Glenn Morris
  2008-01-10  1:31 ` Kenichi Handa
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2008-01-10  0:45 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 788 bytes --]


Does anyone have any ideas about this? It causes a reproducible crash
(see very nice recipe below) with the current EMACS_22_BASE on
Gnu/Linux, so it would be good to fix.

It happens because when Fwrite_region calls
Vselect_safe_coding_system_function, it opens a window for the user to
modify the buffer mid-save. The abort in buf_charpos_to_bytepos in
marker.c due to changed buffer size is what causes the actual crash.

One easy solution is to for Fwrite_region to make the buffer read-only
while Vselect_safe_coding_system_function is called. That will protect
against accidental editing of the buffer at least, but of course a
determined user could still make the buffer writable again.

Ideally, I think one would want errors during write-region to abort
the write, not Emacs.



[-- Attachment #2: Type: message/rfc822, Size: 5880 bytes --]

From: Michael Schierl <schierlm@gmx.de>
To: bug-gnu-emacs@gnu.org
Subject: Crash when buffer is edited while save-buffer asks for coding system
Date: Tue, 25 Dec 2007 01:34:00 +0100
Message-ID: <47704FF8.9030202@gmx.de>

Please describe exactly what actions triggered the bug
and the precise symptoms of the bug:


Manual way:
- emacs -Q
- Create a new text file
- C-x RET f windows-1252 RET
- insert "Hi"
- M-x ucs-insert RET 2122 RET (inserts a trademark symbol)
- C-x C-s
- C-x RET f latin-1 RET C-x C-s
- Emacs will ask for a coding system, since latin-1 does not contain the
  trademark symbol.
- C-x C-o until point is in your file with the trademark
- C-a C-d to delete the first character
- C-x C-o until point is back at minibuffer
- RET
- "Would you like to attach a debugger?" I guess you will select Yes
  here :)

Automatic way:

(progn
  (with-current-buffer (find-file-noselect (make-temp-file
                                            "charsetbug"))
    (set-buffer-file-coding-system 'windows-1252)
    (insert "Hi")
    (ucs-insert 8482) ;; trademark sign
    (save-buffer 0)
    (setq buf (current-buffer))
    (pop-to-buffer buf))
  (set-buffer buf)
  (set-buffer-file-coding-system 'latin-1)
  (defun abcd () (interactive)
    (let ((wnd (selected-window)))
    (select-window (get-buffer-window buf))
    (goto-char (point-min))
    (delete-char 1)
    (select-window wnd)
    (execute-kbd-macro "\r")))
  (global-set-key "\C-cq" 'abcd)
  (execute-kbd-macro "\C-x\C-s\C-cq"))

Merry Christmas! :)



In GNU Emacs 22.1.1 (i386-mingw-nt5.1.2600)
 of 2007-06-02 on RELEASE
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (3.4) --cflags -Ic:/gnuwin32/include'

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: DEU
  locale-coding-system: cp1252
  default-enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  encoded-kbd-mode: t
  tooltip-mode: t
  tool-bar-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  unify-8859-on-encoding-mode: t
  utf-translate-cjk-mode: t
  auto-compression-mode: t
  line-number-mode: t

Recent input:
M-x r e p o r t - e m a c s - b u g <return>

Recent messages:
("D:\\Progs\\emacs\\bin\\emacs.exe" "-q")
Loading encoded-kb...done
For information about the GNU Project and its goals, type C-h C-p. [2 times]
Loading emacsbug...
Loading regexp-opt...done
Loading emacsbug...done

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Fwd: Crash when buffer is edited while save-buffer asks for coding system
  2008-01-10  0:45 Fwd: Crash when buffer is edited while save-buffer asks for coding system Glenn Morris
@ 2008-01-10  1:31 ` Kenichi Handa
  2008-01-10  1:54   ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: Kenichi Handa @ 2008-01-10  1:31 UTC (permalink / raw)
  To: Glenn Morris; +Cc: emacs-devel

In article <gny7ayfqzo.fsf@fencepost.gnu.org>, Glenn Morris <rgm@gnu.org> writes:

> Does anyone have any ideas about this? It causes a reproducible crash
> (see very nice recipe below) with the current EMACS_22_BASE on
> Gnu/Linux, so it would be good to fix.

> It happens because when Fwrite_region calls
> Vselect_safe_coding_system_function, it opens a window for the user to
> modify the buffer mid-save. The abort in buf_charpos_to_bytepos in
> marker.c due to changed buffer size is what causes the actual crash.

> One easy solution is to for Fwrite_region to make the buffer read-only
> while Vselect_safe_coding_system_function is called. That will protect
> against accidental editing of the buffer at least, but of course a
> determined user could still make the buffer writable again.

> Ideally, I think one would want errors during write-region to abort
> the write, not Emacs.

I installed the following fix last year, but it was only to
the trunk.  Could someone who already has the working
directory of EMACS_22_BASE install it?

2007-12-27  Kenichi Handa  <handa@ni.aist.go.jp>

	* international/mule-cmds.el (select-safe-coding-system):
	When a buffer is modified, cancel the writing.

Index: mule-cmds.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/international/mule-cmds.el,v
retrieving revision 1.316
retrieving revision 1.317
diff -u -r1.316 -r1.317
--- mule-cmds.el	6 Dec 2007 00:46:17 -0000	1.316
+++ mule-cmds.el	27 Dec 2007 10:27:21 -0000	1.317
@@ -966,6 +966,7 @@
 
     (let ((codings (find-coding-systems-region from to))
 	  (coding-system nil)
+	  (tick (if (not (stringp from)) (buffer-modified-tick)))
 	  safe rejected unsafe)
       (if (eq (car codings) 'undecided)
 	  ;; Any coding system is ok.
@@ -1030,6 +1031,8 @@
 %s specified by file contents.  Really save (else edit coding cookies \
 and try again)? " coding-system auto-cs))
 	      (error "Save aborted"))))
+      (when (and tick (/= tick (buffer-modified-tick)))
+	(error "Cancelled because the buffer was modified"))
       coding-system)))
 
 (setq select-safe-coding-system-function 'select-safe-coding-system)


Diffs between 1.316 and 1.317 end here.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Fwd: Crash when buffer is edited while save-buffer asks for coding system
  2008-01-10  1:31 ` Kenichi Handa
@ 2008-01-10  1:54   ` Glenn Morris
  2008-01-10  2:09     ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2008-01-10  1:54 UTC (permalink / raw)
  To: Kenichi Handa; +Cc: emacs-devel

Kenichi Handa wrote:

> I installed the following fix last year, but it was only to the trunk.

That's what I get for not checking in the trunk. :)

> Could someone who already has the working directory of EMACS_22_BASE
> install it?

I can install it in a little while. Thanks for fixing it.

Though I guess someone could set select-safe-coding-system-function to
a less careful function and still crash Emacs.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Fwd: Crash when buffer is edited while save-buffer asks for coding system
  2008-01-10  1:54   ` Glenn Morris
@ 2008-01-10  2:09     ` Glenn Morris
  2008-01-10  2:22       ` Juanma Barranquero
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2008-01-10  2:09 UTC (permalink / raw)
  To: Kenichi Handa; +Cc: Juanma Barranquero, emacs-devel

Glenn Morris wrote:

> Kenichi Handa wrote:
[...]
>> Could someone who already has the working directory of EMACS_22_BASE
>> install it?
>
> I can install it in a little while.

But not as quickly as Juanma did. :)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Fwd: Crash when buffer is edited while save-buffer asks for coding system
  2008-01-10  2:09     ` Glenn Morris
@ 2008-01-10  2:22       ` Juanma Barranquero
  0 siblings, 0 replies; 5+ messages in thread
From: Juanma Barranquero @ 2008-01-10  2:22 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Kenichi Handa, emacs-devel

On Jan 10, 2008 3:09 AM, Glenn Morris <rgm@gnu.org> wrote:

> But not as quickly as Juanma did. :)

Sorry, I saw your message when I had already committed the change to
mule-cmds.el.

             Juanma

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-01-10  2:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-10  0:45 Fwd: Crash when buffer is edited while save-buffer asks for coding system Glenn Morris
2008-01-10  1:31 ` Kenichi Handa
2008-01-10  1:54   ` Glenn Morris
2008-01-10  2:09     ` Glenn Morris
2008-01-10  2:22       ` Juanma Barranquero

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.