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:43:33 -0700 Message-ID: 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="38664"; 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:46:07 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 1sDSnu-0009t9-Sw for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 01 Jun 2024 19:46:07 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sDSnl-0006uR-BO; Sat, 01 Jun 2024 13:45:57 -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 1sDSnf-0006u0-Ue for bug-gnu-emacs@gnu.org; Sat, 01 Jun 2024 13:45:51 -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 1sDSnf-0003Jd-4k for bug-gnu-emacs@gnu.org; Sat, 01 Jun 2024 13:45:51 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sDSnq-0003zK-AW for bug-gnu-emacs@gnu.org; Sat, 01 Jun 2024 13:46: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:46: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.171726390615246 (code B ref 71012); Sat, 01 Jun 2024 17:46:02 +0000 Original-Received: (at 71012) by debbugs.gnu.org; 1 Jun 2024 17:45:06 +0000 Original-Received: from localhost ([127.0.0.1]:57338 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sDSmv-0003xn-Is for submit@debbugs.gnu.org; Sat, 01 Jun 2024 13:45:05 -0400 Original-Received: from mail-pl1-f169.google.com ([209.85.214.169]:42446) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sDSmt-0003wz-Ba for 71012@debbugs.gnu.org; Sat, 01 Jun 2024 13:45:04 -0400 Original-Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f4a5344ec7so22929385ad.1 for <71012@debbugs.gnu.org>; Sat, 01 Jun 2024 10:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717263826; x=1717868626; 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=50CGOYjcQ3yfkMFf/wrLgeUBU21apmMW2DWSQOUBupQ=; b=ISvzxUABufPUqtdyaUGMgjCT3Oybc0G06S8A9HP40lurNfJmotJc1Cpc4D2fo+5NjV RIK2yYycKEtaF3dE/8PTc3QMHckVYvqTVQN8dVWTyHUpKU1571ci+MjVS/5TDqeMU5U3 J+2W/txmOj34yXxBZDVzHDKUZ8yU74RSMgUHpkwiazuYwN/McKNmfXD6vGolOE3FaURn 7ptEoireGuPQmd+ipdPb3n6Y8AhL4/WQ+LxJd2FrOaJn4E0XUr4aIGDpwgESmgVD0EKF DL8dON0OarRuN+2rd8KcHx8q5ZJx7QRg9503etQwf+d4UscGK78C9Zdr1WwqdX0+l4V7 0V+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717263826; x=1717868626; 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=50CGOYjcQ3yfkMFf/wrLgeUBU21apmMW2DWSQOUBupQ=; b=R66Wc2teoNKzJicl5Z8uvmeOgSlBW2ONCpTJMgWDZVbbHC3kGMspVDKzNdot5frmSR 0jic9ZBTjiw3N8l7uCOUcx4ZN0xv+C+AJFiSfGAMpnWuvmrhnNIqVxK+mi4MeRFNFlY5 MHiK41vIoH6hVBtjgk7+h8dMm1gc95RjY5ZulNDeL3OzAmXeXniW4mQcVQVcJJIlGO3c dIeToygsuEG0y8C0gDEs48jQq5K1PhLWl4L24Lwc6omVoDHmowWsDi6eHU3biIbn2GHh egdkycB6xgn8hlPA3BGdWND0yGGsPtxQOBFISbaSmyRl5bTGD5PxNZdNxdRdfiNdWCm5 9vhA== X-Forwarded-Encrypted: i=1; AJvYcCWt3EUJ5CGSbkHmwRKlu5E36wYLX6p5f3Ngru5jVj5SHzOVQtQYTw4Rq0bkIKVb9g/JjEk7va0SI6isK+IT/GqIt/GYFbQ= X-Gm-Message-State: AOJu0YwlcmciUF2WAn9LLAvbZgvI7lpw+ZA6a9TbecYcSpHiwIxPzmPd A/12wMVuq6Upr4rl2EKOiljGOx0vNtzJ6Lp6GohyUUX0qEja56DYyurxxw== X-Google-Smtp-Source: AGHT+IEmygYnC4a872QtygqMa/3BcQJbKjj5NuKlPCzHKUuf2rzktfwhaXmBUW1ePpTE9baeehTbpw== X-Received: by 2002:a17:902:c401:b0:1f0:8cbf:c1b5 with SMTP id d9443c01a7336-1f6359c9c78mr84183425ad.16.1717263825614; Sat, 01 Jun 2024 10:43:45 -0700 (PDT) Original-Received: from smtpclient.apple ([2601:646:8f81:f810:8583:e600:bd04:ee0f]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f63232f1b0sm35376485ad.32.2024.06.01.10.43.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2024 10:43:44 -0700 (PDT) In-Reply-To: <6FC1345F-B7CE-4A95-84BA-E559D5A963E1@gmail.com> 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:286340 Archived-At: > 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 Pushed the fix to emacs-29. Yuan