From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Richard Copley <rcopley@gmail.com>
Cc: 35739@debbugs.gnu.org, Noam Postavsky <npostavs@gmail.com>
Subject: bug#35739: Bad signature from GNU ELPA
Date: Wed, 29 May 2019 14:45:50 -0400 [thread overview]
Message-ID: <jwvlfyprwoq.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAPM58oh+mU9N55k-eF+fihrmmKT0Wb-eTBJSx9j3y8Soqvga5A@mail.gmail.com> (Richard Copley's message of "Wed, 15 May 2019 07:46:12 +0100")
> Not in detail, it's not an area of expertise of mine. We call
> (decode-coding-region (point-min) (point-max) 'undecided) on the
> payload of "https://elpa.gnu.org/packages/archive-contents",
> which is raw text. The resulting buffer's buffer-file-coding-
> system is iso-latin-1-dos.
Indeed, it seems that url-insert-file-contents sets
buffer-file-coding-system. Maybe we can use that in the emacs-26
branch. Can you try the emacs-26 code with the patch below to see if it
fixes the current problem?
Stefan
2019-05-29 Stefan Monnier <monnier@iro.umontreal.ca>
* lisp/emacs-lisp/package.el: Obey buffer-file-coding-system.
`url-insert-file-contents` saves in buffer-file-coding-system
the coding-system used to decode the contents. Preserve this
as the contents is moved from buffer to string to buffer, and use
it when saving the contents to file, so as to try and better preserve
the original byte sequence (bug#35739).
(package--buffer-string, package--cs): New functions.
(package--check-signature): Encode `string` if a coding-system
was specified in buffer-file-coding-system.
(package--download-one-archive, package-install-from-archive):
Obey and preserve the buffer-file-coding-system if specified.
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 1a185de4a5..46f7c91272 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1241,6 +1241,17 @@ package--check-signature-content
(signal 'bad-signature (list sig-file)))
good-signatures)))
+(defun package--buffer-string ()
+ (let ((string (buffer-string)))
+ (when (and buffer-file-coding-system
+ (> (length string) 0))
+ (put-text-property 0 1 'package--cs buffer-file-coding-system string))
+ string))
+
+(defun package--cs (string)
+ (and (> (length string) 0)
+ (get-text-property 0 'package--cs string)))
+
(defun package--check-signature (location file &optional string async callback unwind)
"Check signature of the current buffer.
Download the signature file from LOCATION by appending \".sig\"
@@ -1260,8 +1271,12 @@ package--check-signature
UNWIND, if provided, is a function to be called after everything
else, even if an error is signaled."
- (let ((sig-file (concat file ".sig"))
- (string (or string (buffer-string))))
+ (let* ((sig-file (concat file ".sig"))
+ (string (or string (package--buffer-string)))
+ (cs (package--cs string)))
+ ;; Re-encode the downloaded file with the coding-system with which
+ ;; it was decoded, so we (hopefully) get the exact same bytes back.
+ (when cs (setq string (encode-coding-string string cs)))
(package--with-response-buffer location :file sig-file
:async async :noerror t
;; Connection error is assumed to mean "no sig-file".
@@ -1529,7 +1544,7 @@ package--download-one-archive
:error-form (package--update-downloads-in-progress archive)
(let* ((location (cdr archive))
(name (car archive))
- (content (buffer-string))
+ (content (package--buffer-string))
(dir (expand-file-name (format "archives/%s" name) package-user-dir))
(local-file (expand-file-name file dir)))
(when (listp (read content))
@@ -1538,7 +1553,8 @@ package--download-one-archive
(member name package-unsigned-archives))
;; If we don't care about the signature, save the file and
;; we're done.
- (progn (let ((coding-system-for-write 'utf-8))
+ (progn (let ((coding-system-for-write
+ (or (package--cs content) 'utf-8)))
(write-region content nil local-file nil 'silent))
(package--update-downloads-in-progress archive))
;; If we care, check it (perhaps async) and *then* write the file.
@@ -1546,7 +1562,7 @@ package--download-one-archive
location file content async
;; This function will be called after signature checking.
(lambda (&optional good-sigs)
- (let ((coding-system-for-write 'utf-8))
+ (let ((coding-system-for-write (or (package--cs content) 'utf-8)))
(write-region content nil local-file nil 'silent))
;; Write out good signatures into archive-contents.signed file.
(when good-sigs
@@ -1838,15 +1854,17 @@ package-install-from-archive
(let ((save-silently t))
(package-unpack pkg-desc))
;; If we care, check it and *then* write the file.
- (let ((content (buffer-string)))
+ (let ((content (package--buffer-string)))
(package--check-signature
location file content nil
;; This function will be called after signature checking.
(lambda (&optional good-sigs)
;; Signature checked, unpack now.
- (with-temp-buffer (insert content)
- (let ((save-silently t))
- (package-unpack pkg-desc)))
+ (with-temp-buffer
+ (insert content)
+ (setq buffer-file-coding-system (package--cs content))
+ (let ((save-silently t))
+ (package-unpack pkg-desc)))
;; Here the package has been installed successfully, mark it as
;; signed if appropriate.
(when good-sigs
next prev parent reply other threads:[~2019-05-29 18:45 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-14 21:25 bug#35739: Bad signature from GNU ELPA Richard Copley
2019-05-14 21:37 ` bug#35739: Acknowledgement (Bad signature from GNU ELPA) Richard Copley
2019-05-14 22:04 ` bug#35739: Bad signature from GNU ELPA Noam Postavsky
2019-05-14 22:26 ` Richard Copley
2019-05-14 22:42 ` Richard Copley
2019-05-15 2:42 ` Eli Zaretskii
2019-05-15 7:13 ` Richard Copley
2019-05-15 14:03 ` Stefan Monnier
2019-05-15 15:03 ` Eli Zaretskii
2019-05-18 22:36 ` Stefan Monnier
2019-05-22 5:19 ` Eli Zaretskii
2019-05-22 16:20 ` Stefan Monnier
2019-05-22 17:09 ` Eli Zaretskii
2019-05-22 19:40 ` Stefan Monnier
2019-05-23 3:50 ` Eli Zaretskii
2019-05-23 4:06 ` Stefan Monnier
2019-05-23 4:52 ` Eli Zaretskii
2019-05-23 12:10 ` Stefan Monnier
2019-05-23 14:15 ` Eli Zaretskii
2019-05-24 14:22 ` Stefan Monnier
2019-05-24 15:00 ` Eli Zaretskii
2019-05-24 19:31 ` Stefan Monnier
2019-05-24 19:43 ` Eli Zaretskii
2019-05-24 19:51 ` Stefan Monnier
2019-05-25 7:36 ` Eli Zaretskii
2019-05-25 18:38 ` Stefan Monnier
2019-05-25 19:13 ` Eli Zaretskii
2019-05-15 2:41 ` Eli Zaretskii
2019-05-15 6:46 ` Richard Copley
2019-05-15 14:40 ` Eli Zaretskii
2019-05-15 15:12 ` Richard Copley
2019-05-29 18:45 ` Stefan Monnier [this message]
2019-05-29 19:11 ` Richard Copley
2019-05-29 20:07 ` Stefan Monnier
2019-05-29 20:50 ` Noam Postavsky
2019-05-30 2:35 ` Eli Zaretskii
2019-05-31 4:54 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvlfyprwoq.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=35739@debbugs.gnu.org \
--cc=npostavs@gmail.com \
--cc=rcopley@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.