Subject: 29.0.60; Crash in get_narrowed_begv

From: Po Lu <[email-masked]>
Date: Wed, 22 Feb 2023 20:20:02 +0800

I just got the following crash:

#0  0x00007f43164b0e7c in __pthread_kill_implementation () at /lib64/libc.so.6
#1  0x00007f4316460aa6 in raise () at /lib64/libc.so.6
#2  0x000000000041dd7d in terminate_due_to_signal (sig=sig@entry=8, backtrace_limit=backtrace_limit@entry=40) at emacs.c:464
#3  0x000000000041e244 in handle_fatal_signal (sig=sig@entry=8) at sysdep.c:1783
#4  0x000000000055f118 in deliver_thread_signal (sig=8, handler=0x41e239 <handle_fatal_signal>) at sysdep.c:1775
#5  0x000000000055f1f9 in deliver_fatal_thread_signal (sig=<optimized out>) at sysdep.c:1795
#6  0x00007f4316460b50 in <signal handler called> () at /lib64/libc.so.6
#7  0x0000000000453617 in get_narrowed_begv (w=<optimized out>, pos=13523) at xdisp.c:3519
#8  0x0000000000456ee5 in reseat (it=0x7ffc4e7ed560, pos=..., force_p=<optimized out>) at xdisp.c:7468
#9  0x00000000004574fb in init_iterator (it=<optimized out>, w=<optimized out>, charpos=<optimized out>, bytepos=<optimized out>, row=<optimized out>, base_face_id=<optimized out>) at xdisp.c:3488
#10 0x000000000045cac2 in start_display (it=it@entry=0x7ffc4e7ed560, w=w@entry=0xef69700, pos=...) at xdisp.c:3595
#11 0x000000000046bc16 in try_window (window=window@entry=0xef69705, pos=..., flags=flags@entry=1) at xdisp.c:20561
#12 0x000000000048abb8 in redisplay_window (window=<optimized out>, just_this_one_p=<optimized out>) at xdisp.c:19953
#13 0x000000000048d65b in redisplay_window_0 (window=window@entry=0xef69705) at xdisp.c:17439
#14 0x00000000005cac14 in internal_condition_case_1 (bfun=bfun@entry=0x48d630 <redisplay_window_0>, arg=arg@entry=0xef69705, handlers=<optimized out>, hfun=hfun@entry=0x444e20 <redisplay_window_error>) at eval.c:1498
#15 0x0000000000442254 in redisplay_windows (window=0xef69705) at xdisp.c:17409
#16 0x0000000000442275 in redisplay_windows (window=0x5649ac75) at xdisp.c:17403
#17 0x00000000004755db in redisplay_internal () at xdisp.c:16863
#18 0x000000000054ef03 in read_char (commandflag=1, map=0x20219f93, prev_event=0x0, used_mouse_menu=0x7ffc4e7f2bcb, end_time=0x0) at keyboard.c:2627
#19 0x0000000000551bc5 in read_key_sequence (keybuf=<optimized out>, prompt=0x0, dont_downcase_last=<optimized out>, can_return_switch_frame=true, fix_current_buffer=true, prevent_redisplay=false) at keyboard.c:10074
#20 0x0000000000553a67 in command_loop_1 () at keyboard.c:1376
#21 0x00000000005cab87 in internal_condition_case (bfun=bfun@entry=0x5538c0 <command_loop_1>, handlers=handlers@entry=0x90, hfun=hfun@entry=0x547210 <cmd_error>) at eval.c:1474
#22 0x000000000053fc4a in command_loop_2 (handlers=handlers@entry=0x90) at keyboard.c:1125
#23 0x00000000005caae1 in internal_catch (tag=tag@entry=0xff30, func=func@entry=0x53fc30 <command_loop_2>, arg=arg@entry=0x90) at eval.c:1197
#24 0x000000000053fbef in command_loop () at keyboard.c:1103
#25 0x0000000000546dc1 in recursive_edit_1 () at keyboard.c:712
#26 0x000000000054713e in Frecursive_edit () at keyboard.c:795
#27 0x00000000004264c2 in main (argc=<optimized out>, argv=<optimized out>) at emacs.c:2529

The cause is an arithmetic trap in get_narrowed_begv:

  return max ((pos / len - 1) * len, BEGV);

where len is 0.  The window was previously being resized, and has a
pixel width of 24.

In GNU Emacs 29.0.60 (build 1, x86_64-pc-linux-gnu) of 2022-12-24 built
 on trinity
Repository revision: 0e39ad6fa56d50b4710157f0b6f396e492da0dfb
Repository branch: HEAD
Windowing system distributor 'The X.Org Foundation', version 11.0.12101099
System Description: Fedora Linux 37 (Workstation Edition)

Configured using:
 'configure --with-native-compilation --with-x-toolkit=no
 --without-cairo --without-tree-sitter'

Configured features:
ACL DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON LCMS2
LIBSELINUX LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY
OLDXMENU PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF WEBP X11
XDBE XFT XIM XINPUT2 XPM ZLIB

Important settings:
  value of $LANG: en_GB.utf8
  value of $XMODIFIERS: @im=none
  locale-coding-system: utf-8-unix

Major mode: Messages

Minor modes in effect:
  electric-pair-mode: t
  desktop-save-mode: t
  global-telega-mnz-mode: t
  telega-root-auto-fill-mode: t
  telega-active-locations-mode: t
  telega-patrons-mode: t
  display-time-mode: t
  shell-dirtrack-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  lost-selection-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t