From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66375: 30.0.50; (error "Maximum buffer size exceeded") from (insert-file-contents "/dev/null") Date: Sat, 07 Oct 2023 14:43:45 +0800 Message-ID: <87sf6naq5a.fsf@yahoo.com> References: <87cyxru14o.fsf@gnu.org> <83o7hb0yfk.fsf@gnu.org> Reply-To: Po Lu Mime-Version: 1.0 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="28095"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: sds@gnu.org, 66375@debbugs.gnu.org, Paul Eggert To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 07 08:45:03 2023 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 1qp13f-00077P-GN for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 07 Oct 2023 08:45:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qp13M-0000aK-Bz; Sat, 07 Oct 2023 02:44:44 -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 1qp13L-0000Zy-9A for bug-gnu-emacs@gnu.org; Sat, 07 Oct 2023 02:44:43 -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 1qp13L-0006uh-0l for bug-gnu-emacs@gnu.org; Sat, 07 Oct 2023 02:44:43 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qp13d-0001sy-UL for bug-gnu-emacs@gnu.org; Sat, 07 Oct 2023 02:45:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 07 Oct 2023 06:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66375 X-GNU-PR-Package: emacs Original-Received: via spool by 66375-submit@debbugs.gnu.org id=B66375.16966610657189 (code B ref 66375); Sat, 07 Oct 2023 06:45:01 +0000 Original-Received: (at 66375) by debbugs.gnu.org; 7 Oct 2023 06:44:25 +0000 Original-Received: from localhost ([127.0.0.1]:53234 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qp132-0001rt-Di for submit@debbugs.gnu.org; Sat, 07 Oct 2023 02:44:24 -0400 Original-Received: from sonic315-22.consmr.mail.ne1.yahoo.com ([66.163.190.148]:43652) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qp130-0001rf-7e for 66375@debbugs.gnu.org; Sat, 07 Oct 2023 02:44:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1696661037; bh=jjN7MTAKrV/8xqWy89CMhk9xjeYF6VruqPR1qgdDBXI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=Wkl55gxCfo0gDy+O5LwKkD8Yi3FKu1J2GmZDtKC6kr9nO/Z3Kbi3WKWL5AuxeezbL5J8uOlAjCIkQzUZ6QqRLdUjz2D5Pbj0gcJbTN0y9TuQmhRFVSYxyJ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oKlYzaj8GCp7BDhwVTlRit4DPxP8ky29w vysWadbOIBShFkdd1phlOh.eGYV7YD8h4tMyagL_kE5SF6yRGC3x1BPCU8IS8ylYUO1pwsdPXxso Krm1S194K0x.MzVqePQOmND3lFUZINSKl6sdWfsCMPkwCgfX85EAXslVjvGtv1UOGQMfJUGSLxHr RonqwAQuKznOsbNd00uUtMKNpu5wsoqCZzfhpJbfz0yCDflimeHTycfhx6KsxyaBAQbR5oVr7CIO aRxxCoLZ1wRzfN1zxwvfMcc7l.1nuABp5g2TyK35hcyaMvmZmT2VEpeT7Cuyh2Wwet8yfqPQONzO mDiwfU2.vqr_eBp5__Uu6_bA7cHlOJNPYVUiYJjL1gyQ690j7tCDYGXkVtBbQ_Fhpa2HW0vseqGi .2xjprWobOG14KBlLYBXw9IqlpkLM3NfPrU2IhsqV9DUjyCM3z71zAb2UEOkfOMx4a7ca5Zi8ODJ oyOYRbqqGVGcMu9gbvTLe3oRL7Hb273eLwIATZl0T3 X-Sonic-MF: X-Sonic-ID: 55956d56-bff9-4168-93e3-0b5a82ff76d5 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Sat, 7 Oct 2023 06:43:57 +0000 Original-Received: by hermes--production-sg3-64dc67fbb6-rpgvx (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 4b951fc2b60acbfde04b9e43268167b2; Sat, 07 Oct 2023 06:43:51 +0000 (UTC) In-Reply-To: <83o7hb0yfk.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 07 Oct 2023 08:54:55 +0300") X-Mailer: WebService/1.1.21797 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo 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:271976 Archived-At: Eli Zaretskii writes: >> From: Sam Steingold >> Date: Fri, 06 Oct 2023 13:11:35 -0400 >>=20 >>=20 >> emacs -Q >>=20 >> (insert-file-contents "/dev/null") >> =3D=3D> >> Debugger entered--Lisp error: (error "Maximum buffer size exceeded") >> insert-file-contents("/dev/null") > > This is a "feature". From the doc string: > > When inserting data from a special file (e.g., /dev/urandom), you > can=E2=80=99t specify VISIT or BEG, and END should be specified to avoid > inserting unlimited data into the buffer from some special files > which otherwise could supply infinite amounts of data. > > Maybe we could make a special exception for the null-device, whose > name we generally know on each supported system. > > Technically, the problem is that the null device is seekable, so this: > > if (seekable || !NILP (end)) > total =3D end_offset - beg_offset; > > computes 'total' to be a very large value, and then this: > > /* Ensure the gap is at least one byte larger than needed for the > estimated file size, so that in the usual case we read to EOF > without reallocating. */ > if (GAP_SIZE <=3D total) > make_gap (total - GAP_SIZE + 1); > > attempts to make a gap very large, which errors out. And that is > before we try to read even a single byte from the file. > > Po Lu and Paul, any ideas? I think treating /dev/null specially is suitable, but there is a different shortcoming in the approach presently taken by insert-file-contents: if (!regular) end_offset =3D TYPE_MAXIMUM (off_t); else { end_offset =3D st.st_size; I think that the code computing total is presently beset by a presumption that special files are uniformly non-seekable and loses if that assumption proves untrue. Perhaps it should disregard end_offset if isn't expressly provided by the caller and the file is special, which if true implies that end_offset is TYPE_MAXIMUM (off_t); much as in the following untested patch: diff --git a/src/fileio.c b/src/fileio.c index 8919e08e1fd..e09616fb337 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4746,7 +4746,7 @@ DEFUN ("insert-file-contents", Finsert_file_contents,= Sinsert_file_contents, goto handled; } =20 - if (seekable || !NILP (end)) + if (((regular || !NILP (end)) && seekable) || !NILP (end)) total =3D end_offset - beg_offset; else /* For a special file, all we can do is guess. */