From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#18577: Regexp I-search: [(error Stack overflow in regexp matcher)] Date: Fri, 22 Oct 2021 19:47:53 -0700 Message-ID: References: <20140928085554.GA3157@acm.acm> <87mw9kt3m7.fsf@igel.home> <20140928123717.GC3157@acm.acm> <87d2afud0p.fsf@igel.home> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8819"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Alan Mackenzie , Andreas Schwab , 18577@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 23 04:49:09 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1me75p-00023Q-Iz for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 23 Oct 2021 04:49:09 +0200 Original-Received: from localhost ([::1]:51752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1me75n-00032g-Io for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 Oct 2021 22:49:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1me75i-00032X-04 for bug-gnu-emacs@gnu.org; Fri, 22 Oct 2021 22:49:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50766) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1me75h-0004n3-N4 for bug-gnu-emacs@gnu.org; Fri, 22 Oct 2021 22:49:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1me75h-0007aL-Lp for bug-gnu-emacs@gnu.org; Fri, 22 Oct 2021 22:49:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Oct 2021 02:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18577 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: notabug Original-Received: via spool by 18577-submit@debbugs.gnu.org id=B18577.163495728329076 (code B ref 18577); Sat, 23 Oct 2021 02:49:01 +0000 Original-Received: (at 18577) by debbugs.gnu.org; 23 Oct 2021 02:48:03 +0000 Original-Received: from localhost ([127.0.0.1]:34077 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1me74k-0007Yj-Tw for submit@debbugs.gnu.org; Fri, 22 Oct 2021 22:48:03 -0400 Original-Received: from mail-pf1-f175.google.com ([209.85.210.175]:41736) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1me74h-0007XZ-PC for 18577@debbugs.gnu.org; Fri, 22 Oct 2021 22:48:00 -0400 Original-Received: by mail-pf1-f175.google.com with SMTP id y7so5258068pfg.8 for <18577@debbugs.gnu.org>; Fri, 22 Oct 2021 19:47:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:in-reply-to:references:user-agent :mime-version:date:message-id:subject:to:cc; bh=5EIEfSLHNOphYEht1zd5RWJlR/3TLqUOzZOU80XnM1M=; b=6F1jzbTzkItjn7qzckuGFVMelunAnPO6FhXZx5CtSE8h4XAwOvYjCHOy5j4MCdQMQw 05n8Rj1ltzLeobOxZBDbXEuAs6do6hA2sd5cUxb4G/YY+7fIUs0XucgKfl2zg1egqHCn 3B2yj8ryRbeUqiDPTe95x1V/v4NEy6QMToDSQgmSSehQzS3cgTy7N7dDiwLWAV6E17E6 wL63vrWEiLuUauK0EsuZfVASnQ2MyUKjfFkLBVC2jzKcgR/juRhbJoI/GB11u62iJmCn nJN3icCh5VkIWgehp2gByfnh+r1aYKy572x1lHzDjkBIc2RwP46VvnKgs5F91m9mDohh nHjA== X-Gm-Message-State: AOAM531Cl69rm0TLAyt9JtCSEyGEWrzr+5eFHjAJ4FE+XeHWSGydDWQa jaudVNOK9nPYMiS4b1wygpB/VoJaPYcbK6+P148MSDMe8SU= X-Google-Smtp-Source: ABdhPJzs6NGUMb1/uPBS9ybN7IPA0w/LkiatkoANTaL3HcWPELoZo/56xXSt/WASKT2wlBPuczP9R9U3pRiYW4A0r5Y= X-Received: by 2002:a63:9d06:: with SMTP id i6mr2655752pgd.42.1634957274230; Fri, 22 Oct 2021 19:47:54 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Fri, 22 Oct 2021 19:47:53 -0700 In-Reply-To: (Stefan Monnier's message of "Sun, 28 Sep 2014 13:35:30 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:217934 Archived-At: Stefan Monnier writes: >>> Is this a defect in my regexp or in the regexp engine? >> It is fundamental to the way regexp matching works. > > To clarify: it is fundamental to the way *our* regexp engine works. > > As long as the regexp doesn't use backrefs, it can be matched > efficiently, without backtracking. Of course using \(..\) (as opposed > to using \(?:..\)) can also make the problem harder since the various > different (but largely equivalent) ways to match might need to be > distinguishable via match-data. > > But even tho your regexp doesn't use backrefs, and even if you replace > all \(..\) with \(?:..\), your regexp will still cause problems because > our regexp engine does not try to optimize these kinds of cases. > > So you have to do it by hand. > >>> If the former, how could I rewrite the regexp so that it would not hit >>> these problems? > > Maybe something like: > > /\*\(\)*\*+/ > > where is something like > > [^'*]\|\*+\([^/'*]\|'\)\|' > > where is something like > > \([^'*]\|\*+[^/'*]\)*' > > Tho this will still push a backtrack point for every character. > Maybe better would be something like > > /\*[^'*]*\(\)*\*+/ > > where is something like > > \(\*+[^/'*]\|\**'\)[^'*]* > > where is still something like > > \([^'*]\|\*+[^/'*]\)*' > > so that we should only push a backtrace point when we see a * or a ' in > the comment. Should we do anything about this, like document it in etc/PROBLEMS, or should this bug just be closed?