Subject: bug#42931: 27.1; json-pretty-print-buffer on ~2MB line causes core dump

From: Paul Eggert <[email-masked]>
Date: Mon, 24 Aug 2020 16:46:01 -0700

The patch I installed into Emacs master for Bug#43016 also fixes Bug#42931's 
test case, at least for me. However, Bug#42931 prompted me to change the way 
that the Gnulib diffseq module recurses so that the stack size is O(log N) 
rather than O(N). I installed this change into Gnulib, here:

https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=7aadb23803a8fb71d07e6e87ffb1ca510d86f8ef

and propagated this into Emacs master, here:

https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=d494f9e81a6d11dcf6c22333cd950989b2051dff

I doubt whether this patch needs to be backported into the emacs-27 branch.

In theory even O(log N) might not be good enough if Emacs has a tiny stack and a 
huge buffer, but I doubt whether this is of practical concern.

I'll cc this to Bruno Haible to give him a heads-up, since he created the 
diffseq module. Bruno, the bug report is here:

https://bugs.gnu.org/42931