GNU bug report logs - #6149
24.0.50; shell buffer overflow when input longer than 4096 bytes

Previous Next

Package: emacs;

Reported by: jidanni <at> jidanni.org

Date: Mon, 10 May 2010 04:17:01 UTC

Severity: normal

Tags: confirmed

Merged with 12440, 24531

Found in versions 24.0.50, 24.2

Full log


View this message in rfc822 format

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Spencer Baugh <sbaugh <at> janestreet.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 6149 <at> debbugs.gnu.org, Dmitry Gutov <dmitry <at> gutov.dev>, monnier <at> iro.umontreal.ca, jidanni <at> jidanni.org
Subject: bug#6149: bug#24531: process-send-string seems to truncate lines over 4096 characters
Date: Thu, 27 Jul 2023 07:51:31 -0700
On 2023-07-27 06:59, Spencer Baugh wrote:
>> AFAIU, that is based on the errno value returned by a 'write' call
>> which attempts to write too many bytes (see the would_block function).
>> I guess writes to PTYs don't do that?
> Writes to PTYs do tell us when the data has been truncated.

Unfortunately not. Data bytes are silently truncated, at least on Ubuntu 
23.04. If I fire up Emacs and type:

   M-x shell RET cat >out RET C-u 4096 x RET C-d

the last RET causes Emacs to write 4097 bytes (4096 'x's followed by a 
newline) to the pty. This 'write' system call succeeds and returns 4097. 
However, the two 'read' calls that 'cat' executes see only 4095 'x's 
followed by '\n' ('read' returns 4096) followed by EOF ('read' returns 
0). An 'x' was lost, and Emacs has no way to see this directly.

This comes from the canonical mode of Linux's terminal driver, which 
silently discards non-newline bytes after the 4095th byte of an input 
line. See:

https://github.com/torvalds/linux/blob/v6.4/drivers/tty/n_tty.c#L1648

One possibility is that Emacs could monitor writes to a Linux pty, 
looking for too many non-newline bytes in a row, and warn the user if 
that number exceeds 4095. That might be the best it can do in this 
troublesome environment. (The warning would be irrelevant for ttys 
operating in non-canonical mode, which have a different set of problems.)




This bug report was last modified 1 year and 321 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.