From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alex Bochannek Newsgroups: gmane.emacs.bugs Subject: bug#43441: 27.1; [PATCH] Fix incorrectly base64-padded faces in gnus-convert-face-to-png Date: Tue, 15 Sep 2020 23:06:53 -0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15875"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (darwin) To: 43441@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 16 08:08:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kIQby-0003y6-Hg for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Sep 2020 08:08:10 +0200 Original-Received: from localhost ([::1]:59778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIQbx-0006Ai-9k for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Sep 2020 02:08:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQbq-0006AX-T5 for bug-gnu-emacs@gnu.org; Wed, 16 Sep 2020 02:08:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49655) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kIQbq-00057n-Hb for bug-gnu-emacs@gnu.org; Wed, 16 Sep 2020 02:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kIQbq-0001rz-BP for bug-gnu-emacs@gnu.org; Wed, 16 Sep 2020 02:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alex Bochannek Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 16 Sep 2020 06:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 43441 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16002364287119 (code B ref -1); Wed, 16 Sep 2020 06:08:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Sep 2020 06:07:08 +0000 Original-Received: from localhost ([127.0.0.1]:32968 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kIQay-0001qk-1P for submit@debbugs.gnu.org; Wed, 16 Sep 2020 02:07:08 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:54440) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kIQaw-0001qd-29 for submit@debbugs.gnu.org; Wed, 16 Sep 2020 02:07:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQav-00066U-Tj for bug-gnu-emacs@gnu.org; Wed, 16 Sep 2020 02:07:05 -0400 Original-Received: from 50-0-39-243.dsl.static.fusionbroadband.com ([50.0.39.243]:35082 helo=mail.lapseofthought.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIQaq-00053j-Ht for bug-gnu-emacs@gnu.org; Wed, 16 Sep 2020 02:07:04 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.lapseofthought.com (Postfix) with ESMTP id 4BrqPC4nXDz3jjXb for ; Tue, 15 Sep 2020 23:06:55 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at lapseofthought.com Original-Received: from mail.lapseofthought.com ([127.0.0.1]) by localhost (mail.lapseofthought.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kssvzpc3i_9E for ; Tue, 15 Sep 2020 23:06:54 -0700 (PDT) Original-Received: from awb-mbp.local (unknown [IPv6:2601:646:4200:b470:b0ed:26e8:d479:c855]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by mail.lapseofthought.com (Postfix) with ESMTPSA id 4BrqPB0kF3z3jhcB for ; Tue, 15 Sep 2020 23:06:54 -0700 (PDT) Received-SPF: softfail client-ip=50.0.39.243; envelope-from=alex@bochannek.com; helo=mail.lapseofthought.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/16 02:06:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 2 X-Spam_score: 0.2 X-Spam_bar: / X-Spam_report: (0.2 / 5.0 requ) BAYES_00=-1.9, FORGED_SPF_HELO=1, KHOP_HELO_FCRDNS=0.399, SPF_HELO_PASS=-0.001, SPF_SOFTFAIL=0.665, TVD_RCVD_IP=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:188161 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline Content-Description: Fix incorrectly base64-padded faces in gnus-convert-face-to-png 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) --=-=-= Content-Type: text/plain -- Alex. (abochannek@google.com) --=-=-=--