unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#7496: 23.2; copy recursive keymap cause crash
@ 2010-11-27  1:08 ARISAWA Akihiro
  2010-11-27  3:01 ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: ARISAWA Akihiro @ 2010-11-27  1:08 UTC (permalink / raw)
  To: 7496

In GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.12.12)
 of 2010-05-15 on nagi, modified by Debian
configured using `configure  '--build' 'i486-linux-gnu' '--build' 'i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.2/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.2/leim' '--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars' 'build_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS=''

Hi,

When I call `copy-keymap' with a keymap which contains recursive binding,
the emacs crashed.
I can reproduce it by following sexp.

(let ((map (make-sparse-keymap)))
  (define-key map " " map)
  (copy-keymap map))

Regards,
ARISAWA





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

* bug#7496: 23.2; copy recursive keymap cause crash
  2010-11-27  1:08 bug#7496: 23.2; copy recursive keymap cause crash ARISAWA Akihiro
@ 2010-11-27  3:01 ` Stefan Monnier
  2010-11-27  5:10   ` ARISAWA Akihiro
  2019-10-13  1:15   ` Lars Ingebrigtsen
  0 siblings, 2 replies; 12+ messages in thread
From: Stefan Monnier @ 2010-11-27  3:01 UTC (permalink / raw)
  To: ARISAWA Akihiro; +Cc: 7496

> When I call `copy-keymap' with a keymap which contains recursive binding,
> the emacs crashed.
> I can reproduce it by following sexp.

> (let ((map (make-sparse-keymap)))
>   (define-key map " " map)
>   (copy-keymap map))

I'm not surprised.  There are many ways to address it:
- try and make sure we better handle the "using up all memory" case
  rather than crashing.  This is very difficult.  We already try to do
  it, but clearly it's not working that well.
- try and detect such cycles and either signal an error or reproduce the
  same cycle in the copy.  We have added such things in several other
  cases, so we should probably do that.
- don't use cyclic keymaps and especially don't copy them.
- don't use copy-keymap, instead: inherit.


        Stefan





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

* bug#7496: 23.2; copy recursive keymap cause crash
  2010-11-27  3:01 ` Stefan Monnier
@ 2010-11-27  5:10   ` ARISAWA Akihiro
  2019-10-13  1:15   ` Lars Ingebrigtsen
  1 sibling, 0 replies; 12+ messages in thread
From: ARISAWA Akihiro @ 2010-11-27  5:10 UTC (permalink / raw)
  To: 7496

Stefan Monnier writes:

>> When I call `copy-keymap' with a keymap which contains recursive binding,
>> the emacs crashed.
> - don't use cyclic keymaps and especially don't copy them.
> - don't use copy-keymap, instead: inherit.

OK.
I use cycle binding in global-map, and the evernote-mode.el calls
(copy-keymap global-map).
http://code.google.com/p/emacs-evernote-mode/

So, I will suggest to the author that evernote-mode.el uses
set-keymap-parent instead of copy-keymap.

Regards,
ARISAWA





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

* bug#7496: 23.2; copy recursive keymap cause crash
  2010-11-27  3:01 ` Stefan Monnier
  2010-11-27  5:10   ` ARISAWA Akihiro
@ 2019-10-13  1:15   ` Lars Ingebrigtsen
  2019-10-13  6:58     ` Eli Zaretskii
  1 sibling, 1 reply; 12+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-13  1:15 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: ARISAWA Akihiro, 7496

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> When I call `copy-keymap' with a keymap which contains recursive binding,
>> the emacs crashed.
>> I can reproduce it by following sexp.
>
>> (let ((map (make-sparse-keymap)))
>>   (define-key map " " map)
>>   (copy-keymap map))
>
> I'm not surprised.  There are many ways to address it:
> - try and make sure we better handle the "using up all memory" case
>   rather than crashing.  This is very difficult.  We already try to do
>   it, but clearly it's not working that well.
> - try and detect such cycles and either signal an error or reproduce the
>   same cycle in the copy.  We have added such things in several other
>   cases, so we should probably do that.

While this is a pretty obscure, Emacs shouldn't crash on stuff like
this.  I first considered whether just to check for EQ in Fcopy_keymap,
but it's possible to have nested keymaps that are mutually recursive,
so that won't work.

So I just added a recursion counter and refuse to copy when we've
reached level 100.

It does not protect against the case where the keymap is a char table
where one of the entries is the same keymap, but I don't know whether
that's a thing.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#7496: 23.2; copy recursive keymap cause crash
  2019-10-13  1:15   ` Lars Ingebrigtsen
@ 2019-10-13  6:58     ` Eli Zaretskii
  2019-10-13 17:56       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2019-10-13  6:58 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: ari, monnier, 7496

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Sun, 13 Oct 2019 03:15:17 +0200
> Cc: ARISAWA Akihiro <ari@mbf.ocn.ne.jp>, 7496@debbugs.gnu.org
> 
> >> (let ((map (make-sparse-keymap)))
> >>   (define-key map " " map)
> >>   (copy-keymap map))
> >
> > I'm not surprised.  There are many ways to address it:
> > - try and make sure we better handle the "using up all memory" case
> >   rather than crashing.  This is very difficult.  We already try to do
> >   it, but clearly it's not working that well.
> > - try and detect such cycles and either signal an error or reproduce the
> >   same cycle in the copy.  We have added such things in several other
> >   cases, so we should probably do that.
> 
> While this is a pretty obscure, Emacs shouldn't crash on stuff like
> this.  I first considered whether just to check for EQ in Fcopy_keymap,
> but it's possible to have nested keymaps that are mutually recursive,
> so that won't work.
> 
> So I just added a recursion counter and refuse to copy when we've
> reached level 100.

What happens in the current master without that limitation?  We have
since added stack overflow protection -- doesn't it kick in in this
case?





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

* bug#7496: 23.2; copy recursive keymap cause crash
  2019-10-13  6:58     ` Eli Zaretskii
@ 2019-10-13 17:56       ` Lars Ingebrigtsen
  2019-10-13 18:47         ` Eli Zaretskii
                           ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-13 17:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: ari, monnier, 7496

Eli Zaretskii <eliz@gnu.org> writes:

> What happens in the current master without that limitation?  We have
> since added stack overflow protection -- doesn't it kick in in this
> case?

No, Emacs just crashes hard.  I haven't examined why, though -- I didn't
know about the new stack overflow protection.

It's easy to reproduce, though: Just eval this form and Emacs will
segfault (if it's older than yesterday's):

(let ((map (make-sparse-keymap)))
  (define-key map " " map)
  (copy-keymap map))

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#7496: 23.2; copy recursive keymap cause crash
  2019-10-13 17:56       ` Lars Ingebrigtsen
@ 2019-10-13 18:47         ` Eli Zaretskii
  2019-10-13 20:24         ` Stefan Monnier
  2019-10-13 21:38         ` Drew Adams
  2 siblings, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2019-10-13 18:47 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: ari, monnier, 7496

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: monnier@iro.umontreal.ca,  ari@mbf.ocn.ne.jp,  7496@debbugs.gnu.org
> Date: Sun, 13 Oct 2019 19:56:47 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > What happens in the current master without that limitation?  We have
> > since added stack overflow protection -- doesn't it kick in in this
> > case?
> 
> No, Emacs just crashes hard.  I haven't examined why, though -- I didn't
> know about the new stack overflow protection.

Maybe because the stack overflow happens during GC.





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

* bug#7496: 23.2; copy recursive keymap cause crash
  2019-10-13 17:56       ` Lars Ingebrigtsen
  2019-10-13 18:47         ` Eli Zaretskii
@ 2019-10-13 20:24         ` Stefan Monnier
  2019-10-13 20:34           ` Lars Ingebrigtsen
  2019-10-13 21:38         ` Drew Adams
  2 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2019-10-13 20:24 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: ari, 7496

> (let ((map (make-sparse-keymap)))
>   (define-key map " " map)
>   (copy-keymap map))

BTW, copy-keymap should pretty much never be used.
And as a consequence its performance is largely irrelevant, so it could
be re-implemented in Elisp ;-)


        Stefan






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

* bug#7496: 23.2; copy recursive keymap cause crash
  2019-10-13 20:24         ` Stefan Monnier
@ 2019-10-13 20:34           ` Lars Ingebrigtsen
  2019-10-13 21:26             ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-13 20:34 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: ari, 7496

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> BTW, copy-keymap should pretty much never be used.
> And as a consequence its performance is largely irrelevant, so it could
> be re-implemented in Elisp ;-)

Yes, I wondered whether I should just do that -- almost everything it
does is available from Lisp land, I think -- except map_char_table,
which I didn't investigate closely.

(copy-keymap is used 76 times in the Emacs tree.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#7496: 23.2; copy recursive keymap cause crash
  2019-10-13 20:34           ` Lars Ingebrigtsen
@ 2019-10-13 21:26             ` Stefan Monnier
  0 siblings, 0 replies; 12+ messages in thread
From: Stefan Monnier @ 2019-10-13 21:26 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: ari, 7496

> (copy-keymap is used 76 times in the Emacs tree.)

Yes, I know.  I've had it in my TODO to get this number down, but never
got around to it.


        Stefan






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

* bug#7496: 23.2; copy recursive keymap cause crash
  2019-10-13 17:56       ` Lars Ingebrigtsen
  2019-10-13 18:47         ` Eli Zaretskii
  2019-10-13 20:24         ` Stefan Monnier
@ 2019-10-13 21:38         ` Drew Adams
  2019-10-14  6:09           ` Eli Zaretskii
  2 siblings, 1 reply; 12+ messages in thread
From: Drew Adams @ 2019-10-13 21:38 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Eli Zaretskii; +Cc: ari, monnier, 7496

> It's easy to reproduce, though: Just eval this form and Emacs will
> segfault (if it's older than yesterday's):
> 
> (let ((map (make-sparse-keymap)))
>   (define-key map " " map)
>   (copy-keymap map))

FWIW, on MS Windows, Emacs 26.3, emacs -Q hangs if I
do that, after showing this message in the echo area:

  Re-entering top level after C stack overflow.

Have to kill the process with the Task Manager.





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

* bug#7496: 23.2; copy recursive keymap cause crash
  2019-10-13 21:38         ` Drew Adams
@ 2019-10-14  6:09           ` Eli Zaretskii
  0 siblings, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2019-10-14  6:09 UTC (permalink / raw)
  To: Drew Adams; +Cc: larsi, ari, monnier, 7496

> Date: Sun, 13 Oct 2019 21:38:06 +0000 (UTC)
> From: Drew Adams <drew.adams@oracle.com>
> Cc: ari@mbf.ocn.ne.jp, monnier@iro.umontreal.ca, 7496@debbugs.gnu.org
> 
> > It's easy to reproduce, though: Just eval this form and Emacs will
> > segfault (if it's older than yesterday's):
> > 
> > (let ((map (make-sparse-keymap)))
> >   (define-key map " " map)
> >   (copy-keymap map))
> 
> FWIW, on MS Windows, Emacs 26.3, emacs -Q hangs if I
> do that, after showing this message in the echo area:
> 
>   Re-entering top level after C stack overflow.
> 
> Have to kill the process with the Task Manager.

Thanks for testing.  So the stack overflow protection does kick in.





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

end of thread, other threads:[~2019-10-14  6:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-27  1:08 bug#7496: 23.2; copy recursive keymap cause crash ARISAWA Akihiro
2010-11-27  3:01 ` Stefan Monnier
2010-11-27  5:10   ` ARISAWA Akihiro
2019-10-13  1:15   ` Lars Ingebrigtsen
2019-10-13  6:58     ` Eli Zaretskii
2019-10-13 17:56       ` Lars Ingebrigtsen
2019-10-13 18:47         ` Eli Zaretskii
2019-10-13 20:24         ` Stefan Monnier
2019-10-13 20:34           ` Lars Ingebrigtsen
2019-10-13 21:26             ` Stefan Monnier
2019-10-13 21:38         ` Drew Adams
2019-10-14  6:09           ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).