Skip to content

Holding down C-S to search in a PDF causes Emacs crash from uncontrolled memory usage #334

@SuperCowProducts

Description

@SuperCowProducts

Describe the bug
I used the Bash Reference Manual and search for unset

Steps to Reproduce the behaviour
Steps to reproduce the behaviour:

  1. Go to the start of the PDF (M-<)
  2. Search for unset (C-S unset, holding down)
  3. Watch how memory usage just keeps on going up until forced crash

What is the expected behaviour?
CLI tool rga is very fast and doesn't crash on PDFs with thousands of pages: perhaps we should consider borrowing it for a new-and-improved search algorithm?

Desktop
Please complete the following information:

  • OS: Fedora Linux Asahi Remix 42
  • Emacs Version: GNU Emacs 30.2 (build 1, aarch64-redhat-linux-gnu, GTK+
    Version 3.24.49, cairo version 1.18.2) of 2025-08-17
  • Poppler Version: 25.02.0

Your pdf-tools install
Please complete the following information:

  • pdf-tools Version:
    Version: 1.1.0
     Commit: a9c9a12c3ecf2005fa641059368ac8284f507620
    Summary: Support library for PDF documents
   Requires: emacs-26.3, tablist-1.0, let-alist-1.0.4
    Website: https://github.com/vedang/pdf-tools/
   Keywords: files multimedia 
 Maintainer: Vedang Manerikar <vedang.manerikar@gmail.com>
     Author: Andreas Politz <mail@andreas-politz.de>
Other versions: 1.1.0 (nongnu).
  • pdf-tools customization / configuration that you use
(blink-cursor-mode -1)

(pdf-tools-install) ;;(pdf-loader-install) ; On demand loading, leads to faster startup time

;; annotation colours
(defun bms/pdf-annot-colour-gray ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "gray"))
 (highlight (color . "gray")) (squiggly (color . "gray"))
 (strike-out (color . "gray")) (underline (color . "gray"))))
  (message "%s" (propertize "Annotation colour set to gray." 'face '(:foreground "gray"))))
(defun bms/pdf-annot-colour-yellow ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "yellow"))
 (highlight (color . "yellow")) (squiggly (color . "yellow"))
 (strike-out (color . "yellow")) (underline (color . "yellow"))))
  (message "%s" (propertize "Annotation colour set to yellow." 'face '(:foreground "yellow"))))
(defun bms/pdf-annot-colour-pink ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "pink"))
 (highlight (color . "pink")) (squiggly (color . "pink"))
 (strike-out (color . "pink")) (underline (color . "pink"))))
  (message "%s" (propertize "Annotation colour set to pink." 'face '(:foreground "pink"))))
(defun bms/pdf-annot-colour-cyan ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "cyan"))
 (highlight (color . "cyan")) (squiggly (color . "cyan"))
 (strike-out (color . "cyan")) (underline (color . "cyan"))))
  (message "%s" (propertize "Annotation colour set to cyan." 'face '(:foreground "cyan"))))
(defun bms/pdf-annot-colour-blue ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "blue"))
 (highlight (color . "blue")) (squiggly (color . "blue"))
 (strike-out (color . "blue")) (underline (color . "blue"))))
  (message "%s" (propertize "Annotation colour set to blue." 'face '(:foreground "blue"))))
(defun bms/pdf-annot-colour-orange ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "orange"))
 (highlight (color . "orange")) (squiggly (color . "orange"))
 (strike-out (color . "orange")) (underline (color . "orange"))))
  (message "%s" (propertize "Annotation colour set to orange." 'face '(:foreground "orange"))))
(defun bms/pdf-annot-colour-gold ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "gold"))
 (highlight (color . "gold")) (squiggly (color . "gold"))
 (strike-out (color . "gold")) (underline (color . "gold"))))
  (message "%s" (propertize "Annotation colour set to gold." 'face '(:foreground "gold"))))
(defun bms/pdf-annot-colour-green ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "green"))
 (highlight (color . "green")) (squiggly (color . "green"))
 (strike-out (color . "green")) (underline (color . "green"))))
  (message "%s" (propertize "Annotation colour set to green." 'face '(:foreground "green"))))
(defun bms/pdf-annot-colour-red ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "red"))
 (highlight (color . "red")) (squiggly (color . "red"))
 (strike-out (color . "red")) (underline (color . "red"))))
  (message "%s" (propertize "Annotation colour set to red." 'face '(:foreground "red"))))
(defun bms/pdf-annot-colour-purple ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "purple"))
 (highlight (color . "purple")) (squiggly (color . "purple"))
 (strike-out (color . "purple")) (underline (color . "purple"))))
  (message "%s" (propertize "Annotation colour set to purple." 'face '(:foreground "purple"))))
(defun bms/pdf-annot-colour-silver ()
  (interactive)
  (setq pdf-annot-default-annotation-properties
        '((t (label . "Alessandro")) (text (icon . "Note") (color . "silver"))
 (highlight (color . "silver")) (squiggly (color . "silver"))
 (strike-out (color . "silver")) (underline (color . "silver"))))
  (message "%s" (propertize "Annotation colour set to silver." 'face '(:foreground "silver"))))

(defun bms/pdf-selection-style-glyph ()
  (interactive)
  (setq pdf-view-selection-style 'glyph)
  (message "%s" (propertize "Selection style set to glyph." 'face '(:foreground "gray"))))

(defun bms/pdf-selection-style-word ()
  (interactive)
  (setq pdf-view-selection-style 'word)
  (message "%s" (propertize "Selection style set to word." 'face '(:foreground "gray"))))

;; rebind keys for pdf-tools
(defun bms/pdf-tools-mode-config ()
  "Set pdf-tools keybindings."
  (local-set-key (kbd "a") #'bms/pdf-annot-colour-gray)
  (local-set-key (kbd "e") #'bms/pdf-annot-colour-yellow)
  (local-set-key (kbd "k") #'bms/pdf-annot-colour-pink)
  (local-set-key (kbd "y") #'bms/pdf-annot-colour-cyan)
  (local-set-key (kbd "b") #'bms/pdf-annot-colour-blue)
  (local-set-key (kbd "o") #'bms/pdf-annot-colour-orange)
  (local-set-key (kbd "g") #'bms/pdf-annot-colour-gold)
  (local-set-key (kbd "n") #'bms/pdf-annot-colour-green)
  (local-set-key (kbd "d") #'bms/pdf-annot-colour-red)
  (local-set-key (kbd "p") #'bms/pdf-annot-colour-purple)
  (local-set-key (kbd "s") #'bms/pdf-annot-colour-silver)
  (local-set-key (kbd ",") #'bms/pdf-selection-style-glyph)
  (local-set-key (kbd ".") #'bms/pdf-selection-style-word))



;; add to pdf-view-mode-hook
(add-hook 'pdf-view-mode-hook #'bms/pdf-tools-mode-config)

(add-hook 'pdf-outline-minor-mode-hook (lambda () (define-key pdf-outline-minor-mode-map (kbd "o") nil)))

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-enabled-themes '(tsdh-dark))
 '(package-selected-packages '(cask pdf-tools)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

Additional context

  • If you are reporting a crash, please try and add the Backtrace / Stacktrace of the crash.
    • didn't crash when I ran emacs --debug-init, but froze up instead
Image
  • If you are reporting a bug, please try and attach an example PDF file where I can reproduce the bug.
  • If you can attach screenshots or recordings, that is a great help
  • Please try reproducing the bug yourself on Vanilla Emacs before reporting the problem.
    • with emacs -q it finds all the results before moving to them, so it
      doesn't crash
  • [ ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions