Subject: bug#61514: 30.0.50; sadistically long xml line hangs emacs

From: Stefan Monnier <[email-masked]>
Date: Sun, 19 Feb 2023 18:38:52 -0500

> Opening the file (a.xml) produced by the script above from a dired
> buffer in Emacs 30.0.50 shows the following in the message window:
>
>     RNG NXML error: (error "Stack overflow in regexp matcher")

That's "good": much better than a freeze.

It points to the use of a regexp pattern somewhere which doesn't fall
into the small subset which our regexp engine handles efficiently, in
which case we get typically one stack element pushed per character, so
if the text is long enough we inevitably bump into the limit of our
regexp-stack depth.

We should look at the regex and try to rewrite it in a way that fits
better within the limits of our regexp matcher.

> After this, Emacs appears to hang and nothing else is displayed.

That's a second and separate bug (tho probably triggered by the first).
These tend to be nastier to diagnose.
It may also come from a poor regexp (except one where the problem is
not just the backtracking depth but the resulting algorithmic
complexity which can be up to exponential :-( ), but not necessarily.

> Bottom line: Emacs 30 is handling files with long lines worse than Emacs 28.

:-)

As you may have seen by now, this just triggers defensive reactions.

        Stefan