From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#29918: 26.0.90; serial-term error in process filter Date: Wed, 17 Jul 2019 07:36:34 -0400 Message-ID: <87a7dczyd9.fsf@gmail.com> References: <87y3liwr80.fsf@runbox.com> <87d0icy03x.fsf@mouse.gnus.org> <87sgr7ottd.fsf@runbox.com> <87ims19bbo.fsf@mouse.gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="166992"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2.90 (gnu/linux) Cc: 29918@debbugs.gnu.org, Gemini Lasswell To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 17 13:37:09 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hniFA-000hHG-DR for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Jul 2019 13:37:08 +0200 Original-Received: from localhost ([::1]:56176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hniF9-0007gC-Dv for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Jul 2019 07:37:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46569) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hniF6-0007g2-0d for bug-gnu-emacs@gnu.org; Wed, 17 Jul 2019 07:37:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hniF4-0002Uc-Ry for bug-gnu-emacs@gnu.org; Wed, 17 Jul 2019 07:37:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42809) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hniF4-0002UP-N0 for bug-gnu-emacs@gnu.org; Wed, 17 Jul 2019 07:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hniF4-0006li-HH for bug-gnu-emacs@gnu.org; Wed, 17 Jul 2019 07:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 17 Jul 2019 11:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29918 X-GNU-PR-Package: emacs Original-Received: via spool by 29918-submit@debbugs.gnu.org id=B29918.156336340425994 (code B ref 29918); Wed, 17 Jul 2019 11:37:02 +0000 Original-Received: (at 29918) by debbugs.gnu.org; 17 Jul 2019 11:36:44 +0000 Original-Received: from localhost ([127.0.0.1]:51630 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hniEm-0006lB-B3 for submit@debbugs.gnu.org; Wed, 17 Jul 2019 07:36:44 -0400 Original-Received: from mail-io1-f45.google.com ([209.85.166.45]:41276) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hniEk-0006kz-SB for 29918@debbugs.gnu.org; Wed, 17 Jul 2019 07:36:43 -0400 Original-Received: by mail-io1-f45.google.com with SMTP id j5so40971558ioj.8 for <29918@debbugs.gnu.org>; Wed, 17 Jul 2019 04:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=RvnhlT7U9dtnH8QG66qiTuZYW9MLdqBe+ajhIIJ9gJg=; b=b5r7MVHdtgtSPSxKO/N7h6I41qOjG37cVw/Z8nHnlOoCtbRUNiZBokQ2sJV3cu49ye NUgwJ7M5UkynU0Ez57ZcekxXJhWPtIYam75iDX4604SeNVhV8m2iKISrEMh2VmSrxod7 dzpsy3CNNb+l8bxp0PNZzippcFU5QheLrHwh0WEDU6wJ+uHgnq0TVCTiWQGB5Dco6wEq 9mziL0xh0J0LM4qflOMmIkz18QBDiqshy85bAPX94JFu8HA0pZ46QbcPkl+ai9lNm1WJ Pg57Vs7bnHme2YkCc8MBpO99LxFMIlUU87W4EY+X7A6QO0h/mYt/clVF9XBzxY+imS3O DZ8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=RvnhlT7U9dtnH8QG66qiTuZYW9MLdqBe+ajhIIJ9gJg=; b=WLS/iWT64FVLQG7JmvSrI/dNSRSYA3cjrrfY8b9tKnf3VSuf6vJ5Ub556NSEM3hvr0 Gb+a2RrQibkW4chpiRSoVPXC+KkBLFsXIWF/6VeGoX22Lj6ChVMPtW7yVyBYQWWFpxdj 3KNktQCRlsSelpm7i/ZkH2XCBQrcMJbdbrxnkOvzqMb61k14brZmDLcDJpt3uhueXMs/ HdtLjnr0L2LHXq0kFvZwoaKIuan+tpfKsTfH8bsZqdQmyEBxZbro/J8kqiAAwoYIe2Sh N/AA5Ozy1PFLsuccEHHknPY48lVF05YaePn6dmHXqu8H8wA+uAPhIkeKn+3Y5fW8Arr1 gqIQ== X-Gm-Message-State: APjAAAXI6FtGrh3RBmpNHPbXfrk852w5V7eQP6UBCGkrFn3/NMmwVvN4 fE9yZ25LiFmkiqjM1UlHhXIdwIkK X-Google-Smtp-Source: APXvYqwaAh9+XxoGWraRkvAiq60SIdBMJD0LF06x0NxBDkNBPIB9vMtJ/vwcfDMphLEHuX01zm9D+Q== X-Received: by 2002:a02:c65a:: with SMTP id k26mr41061000jan.18.1563363396682; Wed, 17 Jul 2019 04:36:36 -0700 (PDT) Original-Received: from minid (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.gmail.com with ESMTPSA id p3sm20153846iog.70.2019.07.17.04.36.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Jul 2019 04:36:35 -0700 (PDT) In-Reply-To: <87ims19bbo.fsf@mouse.gnus.org> (Lars Ingebrigtsen's message of "Wed, 17 Jul 2019 12:58:51 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:163237 Archived-At: --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > Gemini Lasswell writes: > >> Lars Ingebrigtsen writes: >> >>> Does setting (setq debug-on-error t) give you a backtrace for these >>> errors? >> >> No, but I just made one happen by removing the internal_condition_case_1 >> wrapper on the read_process_output_call in read_and_dispose_of_process_output. >> Then after I got the first backtrace showing that the error was in >> term-emulate-terminal I eval-defun'd it to make a more useful backtrace: >> >> Debugger entered--Lisp error: (args-out-of-range "\376\374\376\364\376\364\376\364\376\364\376\364\376\364\376\364\376\364\376\364\376\364\376\364\376" -1) >> aref("\376\374\376\364\376\364\376\364\376\364\376\364\376\364\376\364\376\364\376\364\376\364\376\364\376" -1) >> (char-charset (aref decoded-substring (- count 1 partial))) > > I'm guessing this bug was introduced by: > > commit 47019a521f774fbd13441e178a6a82c9989b9912 > Author: Noam Postavsky > Date: Thu Jan 18 08:22:47 2018 -0500 > > Switch term.el to lexical binding, and clean up code a bit It can't be that patch, because it's only in master, not emacs-26. I think it's rather [1: 134e86b360] (also mine). [1: 134e86b360]: 2017-01-03 08:58:40 -0500 Handle multibyte chars spanning chunks in term.el https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=134e86b360cab0d0a5cb634b71a4b06ec26c5f1f If I understand the backtrace correctly, then the problem is that I didn't think of the case where the whole string fails to decode. I think the patch below should fix it; there is a possibility it prevents correct decoding in case the terminal receives a utf-8 character in single byte chunks (though I'm not sure if it's even valid for a program to emit single bytes like that). --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Handle-completely-undecoded-input-in-term-Bug-29918.patch Content-Description: patch >From 3e2663f8366ea82f52f47019b63fca243e3f88d9 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 17 Jul 2019 07:20:20 -0400 Subject: [PATCH] Handle completely undecoded input in term (Bug#29918) * lisp/term.el (term-emulate-terminal): Avoid errors if the whole decoded string is eight-bit characters. --- lisp/term.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lisp/term.el b/lisp/term.el index cbef68dc0a..9785ce3024 100644 --- a/lisp/term.el +++ b/lisp/term.el @@ -2900,11 +2900,12 @@ term-emulate-terminal ;; next time. (when (= funny str-length) (let ((partial 0)) - (while (eq (char-charset (aref decoded-substring - (- count 1 partial))) - 'eight-bit) + (while (and (< partial count) + (eq (char-charset (aref decoded-substring + (- count 1 partial))) + 'eight-bit)) (cl-incf partial)) - (when (> partial 0) + (when (> count partial 0) (setq term-terminal-undecoded-bytes (substring decoded-substring (- partial))) (setq decoded-substring -- 2.11.0 --=-=-=--