all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#6149: 24.0.50; shell buffer overflow when input longer than 4096 bytes
@ 2010-05-10  4:14 jidanni
  2010-06-01  1:50 ` Stefan Monnier
  2018-09-28 20:13 ` bug#6149: 24.0.50; shell buffer overflow when input longer than 4096 bytes Charles A. Roelli
  0 siblings, 2 replies; 16+ messages in thread
From: jidanni @ 2010-05-10  4:14 UTC (permalink / raw)
  To: 6149

[-- Attachment #1: Type: text/plain, Size: 575 bytes --]

This is a serious bug in M-x shell. It is not a bash or dash bug. It is
not a readline bug. It does not happen in xterm. It does not happen when
using pipes or backticks to get the input. It only happens in M-x
shell... when one gives lines longer than ~4096 characters.

Actually it is not buffer overflow, but buffer truncation, with NO
WARNING to the user. One day the wrong file will get removed via this
mess.

In GNU Emacs 24.0.50.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0)
 of 2010-05-01 on elegiac, modified by Debian
 (emacs-snapshot package, version 1:20100501-1)


[-- Attachment #2: buffer truncation --]
[-- Type: application/octet-stream, Size: 1717 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread
* bug#24531: process-send-string seems to truncate lines over 4096 characters
@ 2016-09-24 23:38 talwrii talwrii
  2016-09-26  8:36 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 16+ messages in thread
From: talwrii talwrii @ 2016-09-24 23:38 UTC (permalink / raw)
  To: 24531


[-- Attachment #1.1: Type: text/plain, Size: 1689 bytes --]

=== Repro ===

i. Download attached el file
ii. Read it to ensure I am not hacking your computer
iii. In the same directory run

emacs -Q --eval '(progn (load-file "line-repro.el") (message (format "%S"
(repro))))' -nw --batch

As the last line of output I get

(3005 4100 6006)

I wouild expect this 4100 to be 5005

The third value indicates it is the line that gets truncated rather than
the string

=== Version details ===

In GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of
2016-04-08 on binet, modified by Debian Windowing system distributor `The
X.Org Foundation', version 11.0.11804000 System Description: Debian
GNU/Linux testing (stretch) Configured using: `configure --build
x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
--libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info
--mandir=/usr/share/man --with-pop=yes
--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.5/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.5/site-lisp:/usr/share/emacs/site-lisp
--build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
--libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info
--mandir=/usr/share/man --with-pop=yes
--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.5/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.5/site-lisp:/usr/share/emacs/site-lisp
--with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g
-O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall'
'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro' Important
settings: value of $LANG: en_GB.UTF-8 locale-coding-system: utf-8-unix

[-- Attachment #1.2: Type: text/html, Size: 1994 bytes --]

[-- Attachment #2: line-repro.el --]
[-- Type: text/x-emacs-lisp, Size: 1741 bytes --]


(defun s-repeat (num s)
  ;; extracted from s.el
  "Make a string of S repeated NUM times."
  (let (ss)
    (while (> num 0)
      (setq ss (cons s ss))
      (setq num (1- num)))
    (apply 'concat ss)))

(defun s-concat (&rest strings)
  ;; extracted from s.el
  "Join all the string arguments into one string."
  (apply 'concat strings))

(setq tee-program "
import fcntl
import os
import select
import sys

fd = sys.stdin.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)

filename, = sys.argv[1:]

with open(filename, 'w') as stream:
    while True:
        select.select([sys.stdin], [], [sys.stdin], 0.2)
        data = sys.stdin.read()
        if data == '':
            break
        else:
            stream.write(data)
            stream.flush()
")

(defun repro ()
  (list
     (length (write-to-file (s-repeat 3000 "a")))
     (length (write-to-file (s-repeat 5000 "a")))
     (length (write-to-file (s-concat (s-repeat 3000 "a") "\n" (s-repeat 3000 "a"))))
     ))

(defun write-to-file (input)
  (let (p)

    (if (not (file-exists-p "/tmp/bettertee.py"))
        (write-region tee-program nil "/tmp/bettertee.py"))

    (setq p (start-process "bocp" "*bocp*"
                           "python" "/tmp/bettertee.py" "/tmp/line-repro-bug"))
    (process-send-string p input)
    (process-send-string p "\nnext")
    (process-send-eof p)

    (message (format "Waiting for process to die"))
    (while (process-live-p p)
      (sit-for 0.1))
    (message "Process is dead")
    (get-string-from-file "/tmp/line-repro-bug")
    ))

(defun get-string-from-file (filePath)
  "Return filePath's file content."
  (with-temp-buffer
    (insert-file-contents filePath) (buffer-string)))


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-07-27 14:51 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-10  4:14 bug#6149: 24.0.50; shell buffer overflow when input longer than 4096 bytes jidanni
2010-06-01  1:50 ` Stefan Monnier
2023-07-20 20:15   ` bug#6149: bug#24531: process-send-string seems to truncate lines over 4096 characters Spencer Baugh
2023-07-20 21:21     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-21  5:39       ` Eli Zaretskii
2023-07-21 13:58         ` Spencer Baugh
2023-07-21 14:18           ` Eli Zaretskii
2023-07-27  1:48           ` bug#6149: " Dmitry Gutov
2023-07-27  5:41             ` Eli Zaretskii
2023-07-27 13:59               ` Spencer Baugh
2023-07-27 14:51                 ` Paul Eggert
2023-07-21 15:09         ` bug#24531: " Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2018-09-28 20:13 ` bug#6149: 24.0.50; shell buffer overflow when input longer than 4096 bytes Charles A. Roelli
  -- strict thread matches above, loose matches on Subject: below --
2016-09-24 23:38 bug#24531: process-send-string seems to truncate lines over 4096 characters talwrii talwrii
2016-09-26  8:36 ` Thien-Thi Nguyen
2016-09-26 10:23   ` Andreas Schwab

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.