]> git.eshelyaron.com Git - emacs.git/commitdiff
Ensure CID filenames are unique when browsing Gnus article HTML
authorEric Abrahamsen <eric@ericabrahamsen.net>
Fri, 8 Dec 2023 17:48:51 +0000 (09:48 -0800)
committerEshel Yaron <me@eshelyaron.com>
Fri, 8 Dec 2023 18:20:30 +0000 (19:20 +0100)
Bug#67002

* lisp/gnus/gnus-art.el (gnus-article-browse-html-save-cid-content):
It's possible that multiple CID parts will have the same filename,
leading to temporary files clobbering one another during browsing.
This ensures that the temporary filenames are unique.

lisp/gnus/gnus-art.el

index bd9a49eb6a5d63e23bedd16c698a39ad28d68f59..b4abb3680cba49b606ecb86ecd0de63a082b1118 100644 (file)
@@ -2871,12 +2871,15 @@ Return file name relative to the parent of DIRECTORY."
                              cid handle directory))
              (throw 'found file)))
           ((equal (concat "<" cid ">") (mm-handle-id handle))
-           (setq file (or (mm-handle-filename handle)
-                          (concat
-                           (make-temp-name "cid")
-                           (car (rassoc (car (mm-handle-type handle))
-                                        mailcap-mime-extensions))))
-                 afile (expand-file-name file directory))
+            ;; Randomize filenames: declared filenames may not be unique.
+            (setq file (format "cid-%d-%s"
+                              (random 99)
+                              (or (mm-handle-filename handle)
+                                  (concat
+                                   (make-temp-name "cid")
+                                   (car (rassoc (car (mm-handle-type handle))
+                                                mailcap-mime-extensions)))))
+                  afile (expand-file-name file directory))
            (mm-save-part-to-file handle afile)
            (throw 'found (concat (file-name-nondirectory
                                   (directory-file-name directory))