Subject: bug#64423: 29.0.92; save-interprogram-paste-before-kill doesn't prevent streaming large selections

From: [email-masked]
Date: Sun, 02 Jul 2023 14:13:04 +0000 (UTC)

1. emacs -Q under X, preferably X forwarded over ssh to make things slower.
2. (setq save-interprogram-paste-before-kill 2000) (or any other integer)
3. Copy some very large data in another X client, so the selection is
very large.
4. (kill-new "foo")
5. Observe Emacs hanging as it receives the entire large data from the
selection owner, and then after receiving it all, discards it because
it's more than 2000 bytes.

Solution: receive_incremental_selection in xselect.c should support a
cap on the size of the selection it receives and truncate (or discard,
returning nil?) the selection if it's larger than that.  And setting
save-interprogram-paste-before-kill to a numeric value should activate
this cap.

In GNU Emacs 29.0.92 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.16.0, Xaw3d scroll bars) of 2023-07-01 built on earth
Repository revision: b179926388ee76f7b3304535a7189f89bd7c7f8c
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12014000
System Description: NixOS 22.11 (Raccoon)

Configured using:
 'configure --with-x-toolkit=lucid --with-tree-sitter'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY
PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP X11 XAW3D XDBE XIM XPM LUCID ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Help

Minor modes in effect:
  TeX-PDF-mode: t
  pixel-scroll-precision-mode: t
  envrc-global-mode: t
  envrc-mode: t
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  shell-dirtrack-mode: t
  server-mode: t
  windmove-mode: t
  savehist-mode: t
  save-place-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  isearch-fold-quotes-mode: t
  context-menu-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/sbaugh/.emacs.d/elpa/transient-0.3.7/transient hides /home/sbaugh/src/emacs/emacs-29/lisp/transient

Features:
(completion nndoc gnus-dup mm-archive debbugs-gnu debbugs-compat debbugs
soap-client rng-xsd rng-dt rng-util xsd-regexp debbugs-browse octave
semantic/symref/grep semantic/symref semantic/util-modes semantic/util
semantic semantic/tag semantic/lex semantic/fw mode-local cedet
org-archive org-attach org-agenda org-capture display-line-numbers
ibuffer ibuffer-loaddefs tabify em-tramp em-rebind em-smart em-unix
em-term term ehelp em-script em-prompt em-ls em-hist em-pred em-glob
em-extpipe em-cmpl em-dirs esh-var em-basic em-banner em-alias esh-mode
eshell esh-cmd esh-ext esh-opt esh-proc esh-io esh-arg esh-module
esh-groups esh-util goto-addr man cus-theme eieio-custom xwidget
magit-bookmark bookmark wid-browse tree-widget icon conf-mode descr-text
cus-edit pcmpl-unix pcmpl-gnu shadow emacsbug misc dabbrev cl-print
emacs-news-mode tex-info tex texmathp texinfo texinfo-loaddefs
bug-reference org-element org-persist org-id org-refile avl-tree
oc-basic ol-eww eww xdg url-queue mm-url ol-rmail ol-mhe ol-irc ol-info
ol-gnus nnselect ol-docview doc-view image-mode exif ol-bibtex bibtex
ol-bbdb ol-w3m ol-doi org-link-doi org org-macro org-pcomplete org-list
org-footnote org-faces org-entities noutline outline ob-python python ob
ob-tangle org-src ob-ref ob-lob ob-table ob-exp ob-comint ob-emacs-lisp
ob-core ob-eval org-cycle org-table ol org-fold org-fold-core org-keys
oc org-loaddefs cal-menu calendar cal-loaddefs org-version org-compat
org-macs etags fileloop generator find-dired pulse color js cc-mode
cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars
cc-defs grep vc-hg vc-bzr vc-src vc-sccs vc-svn vc-cvs vc-rcs log-view
vc nix-mode nix-repl nix-shell nix-store nix-log nix-instantiate
nix-shebang nix-format nix rust-ts-mode c-ts-common sh-script smie
treesit executable dired-aux dired-x tramp-archive tramp-gvfs tramp
tramp-loaddefs trampver tramp-integration files-x tramp-compat cus-start
cus-load pixel-scroll cua-base misearch multi-isearch vc-git
vc-dispatcher sort smiley gnus-cite mail-extr textsec uni-scripts
idna-mapping ucs-normalize uni-confusable textsec-check qp gnus-async
gnus-bcklg gnus-ml disp-table nndraft nnmh nnfolder gnus-agent gnus-srvr
gnus-score score-mode nnvirtual gnus-msg gnus-art mm-uu mml2015 mm-view
mml-smime smime dig nntp gnus-cache gnus-sum shr pixel-fill kinsoku
url-file svg dom gnus-group gnus-undo gnus-start gnus-dbus dbus xml
gnus-cloud nnimap nnmail mail-source utf7 nnoo gnus-spec gnus-int
gnus-range gnus-win gnus nnheader range wid-edit timezone parse-time
iso8601 mule-util jka-compr eglot external-completion array jsonrpc ert
pp ewoc debug backtrace find-func xref flymake-proc flymake warnings
icons compile project network-stream url-http url-gw nsm url-cache
url-auth face-remap ffap shortdoc desktop frameset help-fns radix-tree
lui-autopaste circe advice lui-irc-colors irc gnutls lcs lui-logging
lui-format lui tracking shorten thingatpt flyspell ispell circe-compat
agda2 envrc inheritenv page-ext magit-extras magit-submodule
magit-obsolete magit-blame magit-stash magit-reflog magit-bisect
magit-push magit-pull magit-fetch magit-clone magit-remote magit-commit
magit-sequence magit-notes magit-worktree magit-tag magit-merge
magit-branch magit-reset magit-files magit-refs magit-status magit
magit-repos magit-apply magit-wip magit-log which-func imenu magit-diff
smerge-mode diff diff-mode easy-mmode git-commit rx log-edit message
sendmail yank-media puny dired dired-loaddefs rfc822 mml mml-sec epa
derived epg rfc6068 epg-config gnus-util text-property-search time-date
mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045 mm-util
ietf-drums mail-prsvr mailabbrev mail-utils gmm-utils mailheader
pcvs-util add-log magit-core magit-autorevert autorevert filenotify
magit-margin magit-transient magit-process with-editor shell pcomplete
comint ansi-osc ring server ansi-color magit-mode transient cl-extra
edmacro kmacro help-mode format-spec magit-git magit-section magit-utils
crm dash windmove modus-vivendi-theme modus-themes pcase savehist
saveplace finder-inf auctex-autoloads tex-site circe-autoloads
csv-mode-autoloads cyberpunk-theme-autoloads debbugs-autoloads
eat-autoloads envrc-autoloads ggtags-autoloads
graphviz-dot-mode-autoloads htmlize-autoloads inheritenv-autoloads
magit-autoloads git-commit-autoloads mentor-autoloads async-autoloads
nix-mode-autoloads magit-section-autoloads dash-autoloads
notmuch-autoloads rust-mode-autoloads transient-autoloads
url-scgi-autoloads vundo-autoloads info with-editor-autoloads
xml-rpc-autoloads package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie generate-lisp-file
url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs password-cache json subr-x map byte-opt gv
bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc iso-transl tooltip
cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify
dynamic-setting system-font-setting font-render-setting cairo x-toolkit
x multi-tty make-network-process emacs)

Memory information:
((conses 16 1334240 144878)
 (symbols 48 62872 2)
 (strings 32 278128 12807)
 (string-bytes 1 11041307)
 (vectors 16 132517)
 (vector-slots 8 2850991 257159)
 (floats 8 749 666)
 (intervals 56 83547 2259)
 (buffers 984 140))