From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.bugs Subject: bug#52461: spontaneous crash with portable dumper Date: Tue, 14 Dec 2021 17:04:48 +0900 Organization: Faculty of Science, Chiba University Message-ID: References: <83czm0my1u.fsf@gnu.org> <83zgp4la58.fsf@gnu.org> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26459"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Cc: 52461@debbugs.gnu.org, Pip Cet To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 14 09:20:22 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mx32s-0006i0-FS for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 Dec 2021 09:20:22 +0100 Original-Received: from localhost ([::1]:41622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mx32r-0004P6-4p for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 Dec 2021 03:20:21 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:36242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mx2o2-00009T-7z for bug-gnu-emacs@gnu.org; Tue, 14 Dec 2021 03:05:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45973) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mx2o1-0000eX-Vt for bug-gnu-emacs@gnu.org; Tue, 14 Dec 2021 03:05:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mx2o1-0000m4-Ov for bug-gnu-emacs@gnu.org; Tue, 14 Dec 2021 03:05:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: YAMAMOTO Mitsuharu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 14 Dec 2021 08:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52461 X-GNU-PR-Package: emacs Original-Received: via spool by 52461-submit@debbugs.gnu.org id=B52461.16394690932954 (code B ref 52461); Tue, 14 Dec 2021 08:05:01 +0000 Original-Received: (at 52461) by debbugs.gnu.org; 14 Dec 2021 08:04:53 +0000 Original-Received: from localhost ([127.0.0.1]:57519 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mx2nt-0000lZ-Bz for submit@debbugs.gnu.org; Tue, 14 Dec 2021 03:04:53 -0500 Original-Received: from mathmail.math.s.chiba-u.ac.jp ([133.82.132.2]:64864) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mx2nq-0000lP-L5 for 52461@debbugs.gnu.org; Tue, 14 Dec 2021 03:04:51 -0500 Original-Received: from mathent.math.s.chiba-u.ac.jp (mathent [192.168.32.5]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id 5B8B6F08E1; Tue, 14 Dec 2021 17:04:48 +0900 (JST) (envelope-from mituharu@math.s.chiba-u.ac.jp) In-Reply-To: <83zgp4la58.fsf@gnu.org> <83czm0my1u.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:222356 Archived-At: On Mon, 13 Dec 2021 22:31:09 +0900, Eli Zaretskii wrote: > > FWIW, on my system, charset_table_used is 179, so maybe the mac port > defines some additional charsets? Yes. On Tue, 14 Dec 2021 01:52:51 +0900, Eli Zaretskii wrote: > > > From: Pip Cet > > Date: Mon, 13 Dec 2021 14:43:55 +0000 > > Cc: YAMAMOTO Mitsuharu , 52461@debbugs.gnu.org > > > > What we can try is debugging the crashing temacs binary, setting a > > breakpoint to the point where define-charset-internal calls xpalloc > > (in a very strange manner), at about line 1126 in charset.c, and zero > > the memory after the call by executing > > memset (new_table, 0, new_size * sizeof (new_table[0])) > > in the debugger (I don't use lldb so I'm not sure precisely how to do > > that), then continuing to the memcpy. > > > > If that fixes things, we should make the obvious change, I think. > > Sounds like a plan, thanks. I directly inserted the memset line just after the xpalloc call in charset.c, and dumped 10 times. No crash occured. I also tried the change below, and it seems to work, too. YAMAMOTO Mitsuharu mituharu@math.s.chiba-u.ac.jp diff --git a/src/charset.c b/src/charset.c index 7cd0fa78f0..670fd48a2d 100644 --- a/src/charset.c +++ b/src/charset.c @@ -63,7 +63,7 @@ Copyright (C) 2003, 2004 /* Table of struct charset. */ struct charset *charset_table; int charset_table_size; -static int charset_table_used; +int charset_table_used; /* Special charsets corresponding to symbols. */ int charset_ascii; diff --git a/src/charset.h b/src/charset.h index 97122d82a6..8c538234d8 100644 --- a/src/charset.h +++ b/src/charset.h @@ -249,6 +249,7 @@ #define EMACS_CHARSET_H /* Table of struct charset. */ extern struct charset *charset_table; extern int charset_table_size; +extern int charset_table_used; #define CHARSET_FROM_ID(id) (charset_table + (id)) diff --git a/src/pdumper.c b/src/pdumper.c index 98c760162e..2782648e7a 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -3174,7 +3174,7 @@ dump_charset (struct dump_context *ctx, int cs_i) DUMP_FIELD_COPY (&out, cs, hash_index); DUMP_FIELD_COPY (&out, cs, dimension); memcpy (out.code_space, &cs->code_space, sizeof (cs->code_space)); - if (cs->code_space_mask) + if (cs_i < charset_table_used && cs->code_space_mask) dump_field_fixup_later (ctx, &out, cs, &cs->code_space_mask); DUMP_FIELD_COPY (&out, cs, code_linear_p); DUMP_FIELD_COPY (&out, cs, iso_chars_96); @@ -3195,7 +3195,7 @@ dump_charset (struct dump_context *ctx, int cs_i) memcpy (out.fast_map, &cs->fast_map, sizeof (cs->fast_map)); DUMP_FIELD_COPY (&out, cs, code_offset); dump_off offset = dump_object_finish (ctx, &out, sizeof (out)); - if (cs->code_space_mask) + if (cs_i < charset_table_used && cs->code_space_mask) dump_remember_cold_op (ctx, COLD_OP_CHARSET, Fcons (dump_off_to_lisp (cs_i), dump_off_to_lisp (offset)));