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: Wed, 5 Jun 2024 22:31:04 -0700 Message-ID: <792DB4FC-EB1E-4094-A4CF-14500DDA82C1@gmail.com> References: <87ttiwpng0.fsf@gmail.com> <86wmnsfodz.fsf@gnu.org> <6F195712-81CE-4C75-8983-D1D909646CAC@gmail.com> <86zfs8ssyj.fsf@gnu.org> <6FC1345F-B7CE-4A95-84BA-E559D5A963E1@gmail.com> 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="25100"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 71012-done@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 Thu Jun 06 07:33:04 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 1sF5kG-0006IH-Ba for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 06 Jun 2024 07:33:04 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sF5k2-0002ok-1B; Thu, 06 Jun 2024 01:32:50 -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 1sF5k0-0002o9-KR for bug-gnu-emacs@gnu.org; Thu, 06 Jun 2024 01:32:48 -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 1sF5k0-0008GI-8E for bug-gnu-emacs@gnu.org; Thu, 06 Jun 2024 01:32:48 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sF5kE-0007Sb-LG for bug-gnu-emacs@gnu.org; Thu, 06 Jun 2024 01:33:02 -0400 Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Thu, 06 Jun 2024 05:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 71012 X-GNU-PR-Package: emacs Mail-Followup-To: 71012@debbugs.gnu.org, casouri@gmail.com, eller.helmut@gmail.com Original-Received: via spool by 71012-done@debbugs.gnu.org id=D71012.171765195828627 (code D ref 71012); Thu, 06 Jun 2024 05:33:02 +0000 Original-Received: (at 71012-done) by debbugs.gnu.org; 6 Jun 2024 05:32:38 +0000 Original-Received: from localhost ([127.0.0.1]:39340 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sF5jp-0007Rf-Tt for submit@debbugs.gnu.org; Thu, 06 Jun 2024 01:32:38 -0400 Original-Received: from mail-pg1-f171.google.com ([209.85.215.171]:59665) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sF5jo-0007RO-Oi for 71012-done@debbugs.gnu.org; Thu, 06 Jun 2024 01:32:37 -0400 Original-Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-6c9d747be82so456534a12.3 for <71012-done@debbugs.gnu.org>; Wed, 05 Jun 2024 22:32:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717651876; x=1718256676; 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=Aqsd1CAKzELC33JPInqAgdOCX2SBPajPMSX1A10fsKo=; b=H/kn+QpB+Q3MMeK1qI8m69n+tw5rc/Pe6lnEOkGpFdBAXeIX94WLwbM5BG8dQAql2J HMjhwmSM/Ap2/GsTRu9nOCDXWYNjtQYIEhMc2BzcwY2ES4EerTMhKAY7hMzcIpu8gJA0 E9yWgmdLZtJPt12CheloUvwYAw5b/MUMANmxDqV9I3Kor3qGYiGFnuTZOOo3/NvVY5u0 8u0sCxM258T1emNrE6bv8id7MWKTBlRn22R/qqwj8FWWRob9krm2ODpeKuvU7QqsnCpa 36jtQOvgnT4wr78jXpVJLxlp2LbffUEGILlobenZqEiTnIGA5XOR6aAK80Qt4hKGDlWD n8ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717651876; x=1718256676; 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=Aqsd1CAKzELC33JPInqAgdOCX2SBPajPMSX1A10fsKo=; b=ppcgKSP29VCiKU03Z/CkyST7LaKqUykr7mummijcQMk+JmuQQqrK86KAvTddvPDNyX /PC/nzYaP8ooT9V54YUlIEVsAz4uTDfe6CMDVC54L1XfCvgocNCHNA4bFwXYpR01XmZQ cZegjjo2bpArRZGrBvhMrGyAzMYheQAns7y9fZw/8+kD53+qp+bku7ZdpuEt7ufWadxd ixYza9RQ4MslO6n7PONG7BxCc2sQICvbezlk+20x3SiJchG51jh/M0HAorUVQIUiD48m rWEF9c/uOTN8Vwe3PLJtmIEWNGS5c1ldk6psLAo6WM/kO6AkET6LnR8mkoZjcaRm3Jbr KuuA== X-Forwarded-Encrypted: i=1; AJvYcCUWHpOuW/wF3GQBMkDxn9ng5vhPegJz+Q/qL/WKca20iU/2amwn2axlHEniJ3AL7e4XJDL9lK58+gYcgJMWurqeRNOOnm2fcEy12A== X-Gm-Message-State: AOJu0Yxufz8nlk+gZrmomL3ryc8NWz5M+SNRfCT0sQpuGGUVvrVgeBFf wJdoN3l5/5HnKii4IJ2dlbqxnNy2jsK7SDWOodun38eY22cJlnm9nnJYdw== X-Google-Smtp-Source: AGHT+IEiCfpDK7GGsvWhCYI1mMBLHvRus2y4Xb2XEECuqftbHdAL3J7WkG+L4HnNMx+LBjaukK9qxA== X-Received: by 2002:a05:6a20:3caa:b0:1b1:d400:1967 with SMTP id adf61e73a8af0-1b2b715fd1emr5612650637.53.1717651876311; Wed, 05 Jun 2024 22:31:16 -0700 (PDT) Original-Received: from smtpclient.apple ([2601:646:8f81:f810:6d47:6e61:bc5f:51a3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd7e30a9sm4970965ad.198.2024.06.05.22.31.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2024 22:31:15 -0700 (PDT) In-Reply-To: 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:286650 Archived-At: > On Jun 1, 2024, at 10:43=E2=80=AFAM, Yuan Fu = wrote: >=20 >=20 >=20 >> On Jun 1, 2024, at 10:15=E2=80=AFAM, Yuan Fu = wrote: >>=20 >>=20 >>=20 >>> 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. >>=20 >> 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. >>=20 >> Yuan >=20 > Pushed the fix to emacs-29. >=20 > Yuan >=20 The fix works for me so I=E2=80=99m closing this report. Feel free to = followup if new problems occur :-) Yuan