Avoid slowdowns in xmltok-scan-attributes
authorGregory Heytings <gregory@heytings.org>
Sat, 18 Mar 2023 10:49:29 +0000 (10:49 +0000)
committerGregory Heytings <gregory@heytings.org>
Sat, 18 Mar 2023 10:51:32 +0000 (11:51 +0100)
* lisp/nxml/xmltok.el (xmltok-scan-attributes): Limit the search
to 10000 characters, to avoid slowdowns due to the quadratic
complexity of the regexp.  Suggested by Stefan Monnier.

lisp/nxml/xmltok.el

index c36d225c7c9bed995f395c0c9d95721250a38781..fb852e5ea5e4ca31fcbb5400124a80fc3495c183 100644 (file)
@@ -734,8 +734,13 @@ and VALUE-END, otherwise a STRING giving the value."
        (atts-needing-normalization nil))
     (while (cond ((or (looking-at (xmltok-attribute regexp))
                      ;; use non-greedy group
-                     (when (looking-at (concat "[^<>\n]+?"
-                                               (xmltok-attribute regexp)))
+                     ;; Limit the search to 10000 characters, to
+                     ;; avoid slowdowns due to the quadratic
+                     ;; complexity of the regexp.  See bug#61514.
+                     (when (with-restriction
+                             (point) (+ (point) 10000)
+                             (looking-at (concat "[^<>\n]+?"
+                                                 (xmltok-attribute regexp))))
                        (unless recovering
                          (xmltok-add-error "Malformed attribute"
                                            (point)