Subject: bug#58232: 29.0.50; alloc.c:879: assertion failed: 0 < item_size && 0 < nitems_incr_min && 0 <= n0 && -1 <= nitems_max

From: Eli Zaretskii <[email-masked]>
Date: Sun, 02 Oct 2022 12:42:04 +0300

> From: Visuwesh <[email-masked]>
> Cc: [email-masked]
> Date: Sun, 02 Oct 2022 14:47:33 +0530
> 
> (gdb) frame 6
> #6  0x000055a416dad158 in load_pdump (argc=2, argv=0x7fffc2172b98) at emacs.c:935
> 935	  dump_file = xpalloc (NULL, &bufsize, needed - bufsize, -1, 1);
> (gdb) p needed
> $1 = 41
> (gdb) p bufsize
> $2 = 128
> (gdb) p exenamelen
> $3 = 35
> (gdb) p emacs_executable
> $4 = 0x55a41793af20 "/home/viz/lib/ports/emacs/src/emacs"
> (gdb) p suffix
> $5 = 0x55a41701a648 ".pdmp"

Ouch!  Please try the patch below.

diff --git a/src/emacs.c b/src/emacs.c
index 91bf0a9..00c381a 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -932,7 +932,7 @@ load_pdump (int argc, char **argv)
 	exenamelen = prefix_length;
     }
   ptrdiff_t needed = exenamelen + strlen (suffix) + 1;
-  dump_file = xpalloc (NULL, &bufsize, needed - bufsize, -1, 1);
+  dump_file = xpalloc (NULL, &bufsize, max (1, needed - bufsize), -1, 1);
   memcpy (dump_file, emacs_executable, exenamelen);
   strcpy (dump_file + exenamelen, suffix);
   result = pdumper_load (dump_file, emacs_executable);