all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#43441: 27.1; [PATCH] Fix incorrectly base64-padded faces in gnus-convert-face-to-png
@ 2020-09-16  6:06 Alex Bochannek
  2020-09-17 15:31 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Alex Bochannek @ 2020-09-16  6:06 UTC (permalink / raw)
  To: 43441

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

Hello!

I noticed a problem with Faces not showing up despite a Face-header
being present in a message. In this particular case,
base64-decode-region failed to decode the header, which had incorrect
(i.e., excessive) padding. A command line and a Web-based decoder
happily ignored the superfluous '='s at the end of the string. Here is
the string in question:

"iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAMFBMVEUwXjFLc0vD0cS7y7zw9PDZ4tkWSRaVrZZ+m39qi2tXfVj////7+/utwK4IPggAOAAJUUA7AAABKklEQVQ4jWPYjQMwDFYJp0NKEKCNJmEf9h8CsimXiL2e33s3/e7F7K2Cs3f3dCMkQkMKj4YuCY3K3iR+e7fMaiSjvkX0/5cFGrWpe2uLzOpaExUVqMS/8PX/Re5ey960OLBTZpFA8+IlSBKPQ92zNyUUBsosN58uIY0k8f+/ONCoYytkVuhWzVwNkYiYbqk5M3NmOVBi41YZ8RsGF7shEtFb5KJ3r969CyixM7OTPeFUxG2IxLO8/9/SvqXlc+/x3h295YzLlj2nIRJQj//nRvc5TEIal8RsXBLVuCQwIgoq/u80DomP6HEOk/iOS+IJLonZOCT+ReOQ+Lkbh0QKLonbOCR+7MYhsRqHBJrVcIl/1TgklqKLQyQ+tGKIgyQOqXpjig94diZRAgAXmDX6jyWafAAAAABJRU5ErkJggg======"

The correct number of '='s here is two.

I don't suspect this problem is widespread in other uses of the base64
decoder, so it seems appropriate to me to just patch
gnus-convert-face-to-png to generate the right amount of padding.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix incorrectly base64-padded faces in gnus-convert-face-to-png --]
[-- Type: text/x-patch, Size: 1111 bytes --]

diff --git a/lisp/gnus/gnus-fun.el b/lisp/gnus/gnus-fun.el
index c95449762e..f1773db29a 100644
--- a/lisp/gnus/gnus-fun.el
+++ b/lisp/gnus/gnus-fun.el
@@ -205,11 +205,27 @@ gnus-face-encode
 (defun gnus-convert-face-to-png (face)
   "Convert FACE (which is base64-encoded) to a PNG.
 The PNG is returned as a string."
-  (mm-with-unibyte-buffer
-    (insert face)
-    (ignore-errors
-      (base64-decode-region (point-min) (point-max)))
-    (buffer-string)))
+  (let ((face (replace-regexp-in-string "[^[:graph:]]" "" face)))
+    ;; Calculate correct base64 padding
+    (if (string-match "=" face)
+	(let ((length (match-beginning 0))
+	      (padding nil))
+	  (progn (setq padding
+		       (/
+			(- 24
+			   (pcase (mod (* length 6) 24)
+			     (`0 24)
+			     (n n)))
+			6))
+		 (setq face (concat
+			     (substring face 0
+					(match-beginning 0))
+			     (make-string padding ?=))))))
+    (mm-with-unibyte-buffer
+      (insert face)
+      (ignore-errors
+	(base64-decode-region (point-min) (point-max)))
+      (buffer-string))))
 
 ;;;###autoload
 (defun gnus-convert-png-to-face (file)

[-- Attachment #3: Type: text/plain, Size: 35 bytes --]


-- 
Alex. (abochannek@google.com)

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

end of thread, other threads:[~2020-09-28 15:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-16  6:06 bug#43441: 27.1; [PATCH] Fix incorrectly base64-padded faces in gnus-convert-face-to-png Alex Bochannek
2020-09-17 15:31 ` Lars Ingebrigtsen
2020-09-28  6:05   ` Alex Bochannek
2020-09-28 12:10     ` Lars Ingebrigtsen
2020-09-28 15:58       ` Alex Bochannek

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.