From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#71012: 30.0.50; tree-sitter crash Date: Sat, 1 Jun 2024 10:15:20 -0700 Message-ID: <6FC1345F-B7CE-4A95-84BA-E559D5A963E1@gmail.com> References: <87ttiwpng0.fsf@gmail.com> <86wmnsfodz.fsf@gnu.org> <6F195712-81CE-4C75-8983-D1D909646CAC@gmail.com> <86zfs8ssyj.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18420"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 71012@debbugs.gnu.org, Helmut Eller To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 01 19:17:13 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 1sDSLw-0004bW-Qc for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 01 Jun 2024 19:17:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sDSLe-0001We-DG; Sat, 01 Jun 2024 13:16:54 -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 1sDSLb-0001Tu-FT for bug-gnu-emacs@gnu.org; Sat, 01 Jun 2024 13:16:52 -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 1sDSLa-0007FJ-Oi for bug-gnu-emacs@gnu.org; Sat, 01 Jun 2024 13:16:51 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sDSLm-0003GI-Fw for bug-gnu-emacs@gnu.org; Sat, 01 Jun 2024 13:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 01 Jun 2024 17:17: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.171726221212519 (code B ref 71012); Sat, 01 Jun 2024 17:17:02 +0000 Original-Received: (at 71012) by debbugs.gnu.org; 1 Jun 2024 17:16:52 +0000 Original-Received: from localhost ([127.0.0.1]:57325 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sDSLc-0003Fq-0V for submit@debbugs.gnu.org; Sat, 01 Jun 2024 13:16:52 -0400 Original-Received: from mail-pf1-f179.google.com ([209.85.210.179]:42293) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sDSLZ-0003Fd-I1 for 71012@debbugs.gnu.org; Sat, 01 Jun 2024 13:16:51 -0400 Original-Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-70260814b2dso132336b3a.1 for <71012@debbugs.gnu.org>; Sat, 01 Jun 2024 10:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717262132; x=1717866932; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rolcEmHMnP+WAQI14Tnt8qzPar/XKjANIrvyAH34314=; b=JDWXVJCXqI+HKuzCgpxJT+Eg28o5igko2fF6P1rTyhdDWU8I/gOz4b62xUedATwzM7 hUQlYR8PC47+1WBY4XKHFh6WUpt2q4ZFNYe6uBmoWkTW9yI1d5VlMVkILki/+AQXmKdX pQaUNA3bZwurHwLUXHbGk7CmVGDrahdkJWQb3wPBi0G4+EtJUclere1CVMKUY7ddILGe psknIT/Ua7oPvMvUsVwLxa6wRj1evs+gBBHA22WpOSILQsdH14D2EgUO5mPol3IxDeVC yTeNQh6AB+HkUJXlUyTyrTmHvXNE/DOA/6V3932OMAwUqysZsS5BPxsUSrQS0GA1dnc8 WwDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717262132; x=1717866932; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rolcEmHMnP+WAQI14Tnt8qzPar/XKjANIrvyAH34314=; b=HV0zn0jwbg7XF9OMjehJrpU29N3RjuixQa1rTpa9qcv7A2m7apeiuLz48vtHOfPnWL x07MbF+Re64xdIcwdVPU2VneDhNm5ahDK4k1PhrAp9+D9UlDnQdBNRayR5G9ZBmd477S Gp+oxe6sg1Tph4jo1pxPAUIDwzzmz6UFlRmBuV6K1OXVelGfXLxtKPy51TEhDe6vaqpC OzFD+ncEFmCgvej7An0jx7mB9vVlf/9o422LbWVeGgvxA5PmoacKH4+VsgyZHm6v/3BV 74Ckh15bMO07DNea1koV4rnqq5/ZsBkKbxSUKWo6xpuAUekppGrMh3fqyZuHjYw+SYAK mESw== X-Forwarded-Encrypted: i=1; AJvYcCUeebEXCZCdKWI+j/Zwvd/1XhabFlDhtbLqujyAKQWJV2GJyJwm3bRxGKLIrWtcx95t9Y8YXut5q4Jb47SedYcbAeJWtrw= X-Gm-Message-State: AOJu0YymAzMbEv/8qFjE3/HqpRKIVaTAcIXWbjjVNZdw9gvzwy3g07Cr N2JCGagqBlN8wCgKEPlTT9l1aJGQYzb2WT669cGBey0mezpzAEtd X-Google-Smtp-Source: AGHT+IGOStR9wCT64Xv2n/Ifawfn6qBz7tzq4hI2WOJBCsoU0bUEhTe8ZESxyIe28Su9+3fK/OrgOw== X-Received: by 2002:a05:6a20:5601:b0:1ac:dead:68 with SMTP id adf61e73a8af0-1b26f253aaamr5755537637.24.1717262131750; Sat, 01 Jun 2024 10:15:31 -0700 (PDT) Original-Received: from smtpclient.apple ([2601:646:8f81:f810:8583:e600:bd04:ee0f]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7025a955dd1sm1001922b3a.64.2024.06.01.10.15.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2024 10:15:31 -0700 (PDT) In-Reply-To: <86zfs8ssyj.fsf@gnu.org> X-Mailer: Apple Mail (2.3774.600.62) 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:286337 Archived-At: > On May 29, 2024, at 5:28=E2=80=AFAM, Eli Zaretskii = wrote: >=20 >> From: Yuan Fu >> Date: Tue, 28 May 2024 22:15:05 -0700 >> Cc: Helmut Eller , >> 71012@debbugs.gnu.org >>=20 >> =46rom what I can gather, the crash seems to be because the temp = buffer is garbage collected=E2=80=94the 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=E2=80=99t crash. >=20 > It is unthinkable that a buffer is GC'ed while it is being used. >=20 >> 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=E2=80=99t 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. >>=20 >> Eli, is there anything different regarding temp buffers in debug = builds? >=20 > No. >=20 > 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! >=20 > 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. I see, you=E2=80=99re absolutely right, thanks for the analysis! On top = of that I need to make sure all the treesit function checks for buffer = liveness before accessing the buffer. I was under the impression that a = killed buffer would keep its content around until it=E2=80=99s = collected. Turns out that wasn=E2=80=99t the case. Yuan=