Subject: bug#27779: #27779; C stack overflow from `read' on deeply nested lisp object.

From: Keith David Bershatsky <[email-masked]>
Date: Thu, 02 May 2019 00:05:52 -0700

I performed the following tests on OSX 10.6.8 (Snow Leopard):

SOURCE:  git clone -b emacs-26 git://git.sv.gnu.org/emacs.git

CONFIGURE:  CFLAGS='-Wall -O0 -g3' ./configure \
            --with-ns \
            --enable-checking='yes,glyphs' \
            --enable-check-lisp-object-type \
            --without-compress-install \
            --without-makeinfo \
            --with-gnutls=no \
            --with-mailutils \
            --without-makeinfo

LISP:

(require 'cl-lib)

(defun make-deep-object (depth)
    (let ((obj 1))
      (while (> (cl-decf depth) 0)
        (setq obj (vector (list obj))))
      obj))

;;; STACK OVERFLOW:  problem with `read'
;;; The bug was introduced on December 8, 2016 with
;;; commit:  f0a1e9ec3fba3d5bea5bd62f525dba3fb005d1b1
(let* ((print-circle t)
       (max-lisp-eval-depth most-positive-fixnum)
       (max-specpdl-size most-positive-fixnum)
       (deep-object (make-deep-object 6000))
       (string (prin1-to-string deep-object))
       (result (read string)))
  (when result
    (message "Bug #27779:  Success! (%d)" (length string))))

RESULT _WITH_ TERMINAL (ulimit -S -s unlimited):  "Bug #27779:  Success! (23997)"

RESULT _WITHOUT_ TERMINAL (ulimit -S -s unlimited):  "Re-entering top level after C stack overflow"

I use a custom fork of undo-tree with a previous version of the CL Lisp libraries and have not done any testing to see how Emacs 26.2 would fair with my custom fork, or with the stock version of undo-tree.  I have a list of known issues affecting my fork, including, but not limited to:  Emacs Bug #27571 and a need for the old CL Lisp libraries ....  I have not done any testing to see whether #27571 still exists.

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

> Date: [05-01-2019 19:30:17] <01 May 2019 22:30:17 -0400>
> From: Noam Postavsky <[email-masked]>
> To: Vasilij Schneidermann <[email-masked]>
> Cc: Keith David Bershatsky <[email-masked]>, Noam Postavsky <[email-masked]>,
> Paul Eggert <[email-masked]>, [email-masked]
> Subject: Re: bug#27779: #27779; C stack overflow from `read' on deeply nested lisp object.
> 
> Vasilij Schneidermann <[email-masked]> writes:
> 
> > I've run into this issue today when loading up undo-tree on Emacs 26.1.
> 
> I'm wondering if Paul's patch at https://debbugs.gnu.org/31995#21 (which
> is in Emacs 26.2) effectively fixes this for practical use of undo-tree
> history?  That is, we know stack overflow is still possible for a
> sufficiently deep nested object, but that patch should make it possible
> for Emacs to read much deeper objects without overflowing.