From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#71012: 30.0.50; tree-sitter crash Date: Wed, 29 May 2024 15:28:20 +0300 Message-ID: <86zfs8ssyj.fsf@gnu.org> References: <87ttiwpng0.fsf@gmail.com> <86wmnsfodz.fsf@gnu.org> <6F195712-81CE-4C75-8983-D1D909646CAC@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12828"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 71012@debbugs.gnu.org, eller.helmut@gmail.com To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 29 14:29:22 2024 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 1sCIQk-00032W-86 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 May 2024 14:29:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCIQK-0003cU-JD; Wed, 29 May 2024 08:28:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCIQG-0003bi-RQ for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 08:28:53 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCIQG-0004Gz-H1 for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 08:28:52 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sCIQQ-0005iR-5o for bug-gnu-emacs@gnu.org; Wed, 29 May 2024 08:29:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 May 2024 12:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71012 X-GNU-PR-Package: emacs Original-Received: via spool by 71012-submit@debbugs.gnu.org id=B71012.171698574021962 (code B ref 71012); Wed, 29 May 2024 12:29:02 +0000 Original-Received: (at 71012) by debbugs.gnu.org; 29 May 2024 12:29:00 +0000 Original-Received: from localhost ([127.0.0.1]:59909 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCIQB-0005hm-RB for submit@debbugs.gnu.org; Wed, 29 May 2024 08:29:00 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38632) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sCIQ3-0005hE-KH for 71012@debbugs.gnu.org; Wed, 29 May 2024 08:28:47 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCIPn-0004Bx-ES; Wed, 29 May 2024 08:28:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=NPngea3dDuOEpY3oFKfSKP3ds6lCdXuI/Zc2XAq/tLI=; b=Xh18jKfcfm3fWcjr8Fi0 y7oUYnvh79CD5CSq4TuN0xb4O0TKcxDpyP3yarKuZD0crP4MGaK9KVPFv1rq/+QgWnoEy8MqlPX6u s7QnDbEiOrgAfR5Kd7MEZMKWW3LUOaJo/2+LSHZSkzJ1XLuw0TmDqG8MOsS2gCr+lHW+Jbn52C148 JZXkmR+nCa+BOQC/44HvC7fB/BR2VQvBftezYw2WIdvF/5CCA46NtazzR1I5oLFFZRImmemfAKWdW Si0q+cborXPLF/fw9nrB7r3uffgdsS+DjmTuZKEwuMoe11cOspxUZOb137/7RLZPMV11UZpJd3vb4 ISiMpI7E9otW8A==; In-Reply-To: (message from Yuan Fu on Tue, 28 May 2024 22:15:05 -0700) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:286150 Archived-At: > From: Yuan Fu > Date: Tue, 28 May 2024 22:15:05 -0700 > Cc: Helmut Eller , > 71012@debbugs.gnu.org > > From what I can gather, the crash seems to be because the temp buffer is garbage collected—the inserted lisp.h is a large file, so the temp buffer is probably immediately collected, before Emacs tries to print the node in the next line. I replaced the insert-file-content with some smaller file and it didn’t crash. It is unthinkable that a buffer is GC'ed while it is being used. > But that theory has critical flaws: a) Emacs certainly doesn't collect the temp buffer before the with-temp-buffer form returns; b) I can’t crash Emacs in my non-debug build by inserting (garbage-collect) in front of the message line in the example; c) debug build Emacs still crashes even if I enlarge gc-cons-threshold. > > Eli, is there anything different regarding temp buffers in debug builds? No. But note that there are _two_ temporary buffers involved here: one is created in ts-bug.el, and it remains intact and valid; the other is the temporary buffer created by treesit-parse-string. That one is killed by the time treesit-parse-string returns, so treesit-node-start attempts to access positions of a killed buffer! So I think this is a bug in treesit-parse-string: it cannot use with-temp-buffer; instead, it should make the buffer into which it inserts the string part of the parser, so that the buffer is killed and GC'ed only when the parser is no longer referenced. Otherwise the syntax tree returned by treesit-parse-string is unsafe to use.