Subject: bug#31829: 27.0.50;

From: Eli Zaretskii <[email-masked]>
Date: Thu, 14 Jun 2018 21:10:59 +0300

> From: Richard Stallman <[email-masked]>
> Date: Thu, 14 Jun 2018 12:41:47 -0400
> 
> 
> Run emacs -Q, visit foo.txt (see below), type
> C-SPC M-> C-p C-f C-f C-f C-x r d C-x C-s, and it gets
> an error trying to save.  In another Emacs job (same version),
> it got a seg fault, but I can't reproduce that now.

I get an assertion violation if I set debug-on-error non-nil, I guess
your Emacs is configured without "--enable-checking"?

Here's the backtrace (I get this also on the emacs-26 branch):

  lisp.h:3318: Emacs fatal error: assertion failed: 0 <= idx && idx < (1 << CHARTAB_SIZE_BITS_0)

  Thread 1 hit Breakpoint 1, terminate_due_to_signal (sig=22,
      backtrace_limit=2147483647) at emacs.c:364
  364       signal (sig, SIG_DFL);
  (gdb) bt
  #0  terminate_due_to_signal (sig=22, backtrace_limit=2147483647)
      at emacs.c:364
  #1  0x011f5624 in die (
      msg=0x169e0b4 <DEFAULT_REHASH_SIZE+540> "0 <= idx && idx < (1 << CHARTAB_SIZE_BITS_0)", file=0x169daa8 <Qzlib+8> "lisp.h", line=3318) at alloc.c:7410
  #2  0x011460ef in set_char_table_contents (table=XIL(0xa000000001c98020),
      idx=178, val=XIL(0xa00000000790d3f8)) at lisp.h:3318
  #3  0x01116dcc in char_table_set (table=XIL(0xa000000001c98020), c=11672154,
      val=XIL(0xebd0)) at chartab.c:436
  #4  0x010fb986 in Ffind_coding_systems_region_internal (start=make_number(1),
      end=make_number(50106), exclude=XIL(0)) at coding.c:9086
  #5  0x012270d0 in funcall_subr (
      subr=0x1384e40 <Sfind_coding_systems_region_internal>, numargs=2,
      args=0x82c0f0) at eval.c:2849
  #6  0x01226ab0 in Ffuncall (nargs=3, args=0x82c0e8) at eval.c:2769
  #7  0x0128d477 in exec_byte_code (bytestr=XIL(0x80000000014386c8),
      vector=XIL(0xa0000000014386d8), maxdepth=make_number(6),
      args_template=make_number(514), nargs=2, args=0x82c5a8) at bytecode.c:629
  #8  0x01227bae in funcall_lambda (fun=XIL(0xa000000001438698), nargs=2,
      arg_vector=0x40000000) at eval.c:2970
  #9  0x01226b0a in Ffuncall (nargs=3, args=0x82c590) at eval.c:2771
  #10 0x0128d477 in exec_byte_code (bytestr=XIL(0x8000000001439170),
      vector=XIL(0xa000000001439180), maxdepth=make_number(20),
      args_template=make_number(1282), nargs=5, args=0x82cd60) at bytecode.c:629
  #11 0x01227bae in funcall_lambda (fun=XIL(0xa000000001439140), nargs=5,
      arg_vector=0x40000000) at eval.c:2970
  #12 0x01226b0a in Ffuncall (nargs=6, args=0x82cd30) at eval.c:2771
  #13 0x01226218 in call5 (fn=XIL(0xc99a8), arg1=make_number(1),
      arg2=make_number(50106), arg3=XIL(0x119508), arg4=XIL(0),
      arg5=XIL(0x8000000000fd4360)) at eval.c:2654
  #14 0x011b8f73 in choose_write_coding_system (start=make_number(1),
      end=make_number(50106), filename=XIL(0x8000000000fd4360), append=XIL(0),
      visit=XIL(0xebd0), lockname=XIL(0x8000000000fd4390), coding=0x82d170)
      at fileio.c:4681
  #15 0x011b9a2a in write_region (start=make_number(1), end=make_number(50106),
      filename=XIL(0x8000000000fd4360), append=XIL(0), visit=XIL(0xebd0),
      lockname=XIL(0x8000000000fd4390), mustbenew=XIL(0), desc=-1)
      at fileio.c:4875
  #16 0x011b9251 in Fwrite_region (start=XIL(0), end=XIL(0),
      filename=XIL(0x8000000000fd4360), append=XIL(0), visit=XIL(0xebd0),
      lockname=XIL(0x8000000000fd4390), mustbenew=XIL(0)) at fileio.c:4755
  #17 0x012272a8 in funcall_subr (subr=0x1387580 <Swrite_region>, numargs=6,
      args=0x82d858) at eval.c:2864
  #18 0x01226ab0 in Ffuncall (nargs=7, args=0x82d850) at eval.c:2769
  #19 0x0128d477 in exec_byte_code (bytestr=XIL(0x80000000013cdae8),
      vector=XIL(0xa0000000013cdaf8), maxdepth=make_number(14),
      args_template=make_number(0), nargs=0, args=0x82de20) at bytecode.c:629
  #20 0x01227bae in funcall_lambda (fun=XIL(0xa0000000013cdac0), nargs=0,
      arg_vector=0x40000000) at eval.c:2970
  #21 0x01226b0a in Ffuncall (nargs=1, args=0x82de18) at eval.c:2771
  #22 0x0128d477 in exec_byte_code (bytestr=XIL(0x80000000013cda80),
      vector=XIL(0xa0000000013cda90), maxdepth=make_number(3),
      args_template=make_number(0), nargs=0, args=0x82e2b0) at bytecode.c:629
  #23 0x01227bae in funcall_lambda (fun=XIL(0xa0000000013cda58), nargs=0,
      arg_vector=0x40000000) at eval.c:2970
  #24 0x01226b0a in Ffuncall (nargs=1, args=0x82e2a8) at eval.c:2771
  #25 0x0128d477 in exec_byte_code (bytestr=XIL(0x80000000013cd7b8),
      vector=XIL(0xa0000000013cd7c8), maxdepth=make_number(9),
      args_template=make_number(256), nargs=1, args=0x82e898) at bytecode.c:629
  #26 0x01227bae in funcall_lambda (fun=XIL(0xa0000000013cd780), nargs=1,
      arg_vector=0x40000000) at eval.c:2970
  #27 0x01226b0a in Ffuncall (nargs=2, args=0x82e888) at eval.c:2771
  #28 0x0128d477 in exec_byte_code (bytestr=XIL(0x80000000013cd518),
      vector=XIL(0xa0000000013cd528), maxdepth=make_number(5),
      args_template=make_number(256), nargs=1, args=0x82eeb8) at bytecode.c:629
  #29 0x01227bae in funcall_lambda (fun=XIL(0xa0000000013cd4e0), nargs=1,
      arg_vector=0x40000000) at eval.c:2970
  #30 0x01226b0a in Ffuncall (nargs=2, args=0x82eea8) at eval.c:2771
  #31 0x0121867d in Ffuncall_interactively (nargs=2, args=0x82eea8)
      at callint.c:252
  #32 0x01226f78 in funcall_subr (subr=0x16855c0 <Sfuncall_interactively>,
      numargs=2, args=0x82eea8) at eval.c:2824
  #33 0x01226ab0 in Ffuncall (nargs=3, args=0x82eea0) at eval.c:2769
  #34 0x0121b808 in Fcall_interactively (function=XIL(0x144810),
      record_flag=XIL(0), keys=XIL(0xa000000006f1b838)) at callint.c:854
  #35 0x012270d0 in funcall_subr (subr=0x16855e0 <Scall_interactively>,
      numargs=3, args=0x82f230) at eval.c:2849
  #36 0x01226ab0 in Ffuncall (nargs=4, args=0x82f228) at eval.c:2769
  #37 0x0128d477 in exec_byte_code (bytestr=XIL(0x80000000014224e0),
      vector=XIL(0xa0000000014224f0), maxdepth=make_number(13),
      args_template=make_number(1025), nargs=1, args=0x82f750) at bytecode.c:629
  #38 0x01227bae in funcall_lambda (fun=XIL(0xa0000000014224b0), nargs=1,
      arg_vector=0x40000000) at eval.c:2970
  #39 0x01226b0a in Ffuncall (nargs=2, args=0x82f740) at eval.c:2771
  #40 0x01225ffc in call1 (fn=XIL(0x4398), arg1=XIL(0x144810)) at eval.c:2620
  #41 0x01150625 in command_loop_1 () at keyboard.c:1482
  #42 0x01221455 in internal_condition_case (bfun=0x114fba3 <command_loop_1>,
      handlers=XIL(0x5b70), hfun=0x114ee23 <cmd_error>) at eval.c:1332
  #43 0x0114f637 in command_loop_2 (ignore=XIL(0)) at keyboard.c:1110
  #44 0x01220587 in internal_catch (tag=XIL(0xf570),
      func=0x114f5fb <command_loop_2>, arg=XIL(0)) at eval.c:1097
  #45 0x0114f5b6 in command_loop () at keyboard.c:1089
  #46 0x0114e84b in recursive_edit_1 () at keyboard.c:695
  #47 0x0114eaed in Frecursive_edit () at keyboard.c:766
  #48 0x0114c1f4 in main (argc=2, argv=0xa428d8) at emacs.c:1713

  Lisp Backtrace:
  "find-coding-systems-region-internal" (0x82c0f0)
  "find-coding-systems-region" (0x82c598)
  "select-safe-coding-system" (0x82cd38)
  "write-region" (0x82d858)
  "basic-save-buffer-2" (0x82de20)
  "basic-save-buffer-1" (0x82e2b0)
  "basic-save-buffer" (0x82e890)
  "save-buffer" (0x82eeb0)
  "funcall-interactively" (0x82eea8)
  "call-interactively" (0x82f230)
  "command-execute" (0x82f748)
  (gdb)

Note that in find-coding-systems-region we have an invalid character
code, larger than 0x3fffff:

  (gdb) up
  #1  0x011f5624 in die (
      msg=0x169e0b4 <DEFAULT_REHASH_SIZE+540> "0 <= idx && idx < (1 << CHARTAB_SIZE_BITS_0)", file=0x169daa8 <Qzlib+8> "lisp.h", line=3318) at alloc.c:7410
  7410      terminate_due_to_signal (SIGABRT, INT_MAX);
  (gdb)
  #2  0x011460ef in set_char_table_contents (table=XIL(0xa000000001c98020),
      idx=178, val=XIL(0xa00000000790d3f8)) at lisp.h:3318
  3318      eassert (0 <= idx && idx < (1 << CHARTAB_SIZE_BITS_0));
  (gdb)
  #3  0x01116dcc in char_table_set (table=XIL(0xa000000001c98020), c=11672154,
      val=XIL(0xebd0)) at chartab.c:436
  436               set_char_table_contents (table, i, sub);
  (gdb)
  #4  0x010fb986 in Ffind_coding_systems_region_internal (start=make_number(1),
      end=make_number(50106), exclude=XIL(0)) at coding.c:9086
  9086              char_table_set (work_table, c, Qt);
  (gdb) p/x c
  $1 = 0xb21a5a  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<