From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#28824: 26.0.90; display of pbm images broken? Date: Mon, 16 Oct 2017 01:30:07 -0700 Organization: UCLA Computer Science Department Message-ID: <6c4a985c-b0a1-93a4-8c3b-36f7c2f5721c@cs.ucla.edu> References: <29226.45866.855134.23009@gargle.gargle.HOWL> <83376mjjq7.fsf@gnu.org> <34582.83757.771697.23010@gargle.gargle.HOWL> <86wp3w48ak.fsf@gmail.com> <83a80sgsbb.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F9D14E69FB9D58E10B464B84" X-Trace: blaine.gmane.org 1508142689 24834 195.159.176.226 (16 Oct 2017 08:31:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 16 Oct 2017 08:31:29 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 Cc: 28824-done@debbugs.gnu.org, Roland Winkler To: Eli Zaretskii , Andy Moreton Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 16 10:31:18 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e40nl-00041o-41 for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Oct 2017 10:31:09 +0200 Original-Received: from localhost ([::1]:59953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e40ns-0000Pn-Hm for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Oct 2017 04:31:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e40nj-0000OS-AZ for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 04:31:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e40ne-0000hJ-CA for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 04:31:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33806) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e40ne-0000h0-8m for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 04:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e40ne-0000ea-1H for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 04:31:02 -0400 Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Oct 2017 08:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 28824 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 28824@debbugs.gnu.org, eggert@cs.ucla.edu, winkler@gnu.org Original-Received: via spool by 28824-done@debbugs.gnu.org id=D28824.15081426192435 (code D ref 28824); Mon, 16 Oct 2017 08:31:01 +0000 Original-Received: (at 28824-done) by debbugs.gnu.org; 16 Oct 2017 08:30:19 +0000 Original-Received: from localhost ([127.0.0.1]:42475 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e40mw-0000dC-S0 for submit@debbugs.gnu.org; Mon, 16 Oct 2017 04:30:19 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:55312) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e40mu-0000cz-LZ for 28824-done@debbugs.gnu.org; Mon, 16 Oct 2017 04:30:17 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id DEBA8160062; Mon, 16 Oct 2017 01:30:09 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id UkGJmEbKI0oR; Mon, 16 Oct 2017 01:30:08 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id A395F160071; Mon, 16 Oct 2017 01:30:08 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id eso5SQ1OuJNu; Mon, 16 Oct 2017 01:30:08 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.154.18.85]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 3F9C8160062; Mon, 16 Oct 2017 01:30:08 -0700 (PDT) In-Reply-To: <83a80sgsbb.fsf@gnu.org> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:138505 Archived-At: This is a multi-part message in MIME format. --------------F9D14E69FB9D58E10B464B84 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Eli Zaretskii wrote: >> From: Andy Moreton >> Date: Sun, 15 Oct 2017 18:42:27 +0100 >> >> Eli can decide if reverting the previous "unsigned char" -> "char" >> changes is a better fix. >=20 > Looks like going back to unsigned should be cleaner, but I'd like to > hear what Paul thinks. Andy's fixes look good to me. Going back to unsigned would result in seve= ral=20 pointer casts that are more dangerous than converting to unsigned. They c= an be=20 further improved by encapsulating this stuff into a function, and I insta= lled=20 the attached (the second one is Andy's other fix, which I installed in hi= s name). I looked for related bugs in image.c (i.e., caused by my earlier patch) a= nd did=20 not find any. --------------F9D14E69FB9D58E10B464B84 Content-Type: text/x-patch; name="0001-Fix-regression-in-display-of-PPM-images.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-Fix-regression-in-display-of-PPM-images.patch" =46rom cac318a1fce0a4c8c5c1f81f715c06c49c117592 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 16 Oct 2017 01:14:58 -0700 Subject: [PATCH 1/2] Fix regression in display of PPM images Problem reported by Roland Winkler (Bug#28824#35). Based on a patch proposed by Andy Moreton (Bug#28824#38). * src/image.c (pbm_scan_index): New function. (pbm_load): Use it to decode raw data correctly when its top bit is set. --- src/image.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/image.c b/src/image.c index cd4901b..335a43e 100644 --- a/src/image.c +++ b/src/image.c @@ -5277,6 +5277,25 @@ pbm_scan_number (char **s, char *end) return val; } =20 +/* Scan an index from *S and return it. It is a one-byte unsigned + index if !TWO_BYTE, and a two-byte big-endian unsigned index if + TWO_BYTE. */ + +static int +pbm_scan_index (char **s, bool two_byte) +{ + char *p =3D *s; + unsigned char c0 =3D *p++; + int n =3D c0; + if (two_byte) + { + unsigned char c1 =3D *p++; + n =3D (n << 8) + c1; + } + *s =3D p; + return n; +} + =20 /* Load PBM image IMG for use on frame F. */ =20 @@ -5499,7 +5518,8 @@ pbm_load (struct frame *f, struct image *img) else { int expected_size =3D height * width; - if (max_color_idx > 255) + bool two_byte =3D 255 < max_color_idx; + if (two_byte) expected_size *=3D 2; if (type =3D=3D PBM_COLOR) expected_size *=3D 3; @@ -5522,24 +5542,14 @@ pbm_load (struct frame *f, struct image *img) int r, g, b; =20 if (type =3D=3D PBM_GRAY && raw_p) - { - r =3D g =3D b =3D *p++; - if (max_color_idx > 255) - r =3D g =3D b =3D r * 256 + *p++; - } + r =3D g =3D b =3D pbm_scan_index (&p, two_byte); else if (type =3D=3D PBM_GRAY) r =3D g =3D b =3D pbm_scan_number (&p, end); else if (raw_p) { - r =3D *p++; - if (max_color_idx > 255) - r =3D r * 256 + *p++; - g =3D *p++; - if (max_color_idx > 255) - g =3D g * 256 + *p++; - b =3D *p++; - if (max_color_idx > 255) - b =3D b * 256 + *p++; + r =3D pbm_scan_index (&p, two_byte); + g =3D pbm_scan_index (&p, two_byte); + b =3D pbm_scan_index (&p, two_byte); } else { --=20 2.7.4 --------------F9D14E69FB9D58E10B464B84 Content-Type: text/x-patch; name="0002-Don-t-reject-PBM-header-whitespace-unnecessarily.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0002-Don-t-reject-PBM-header-whitespace-unnecessarily.patch" =46rom 000abe3c89b1934c23377a792a838f289d4bbf8a Mon Sep 17 00:00:00 2001 From: Andy Moreton Date: Mon, 16 Oct 2017 01:23:32 -0700 Subject: [PATCH 2/2] Don't reject PBM header whitespace unnecessarily * lisp/image.el (image-type-header-regexps): Allow two or more CRs or LFs in initial whitespace sequences. See: http://netpbm.sourceforge.net/doc/pbm.html --- lisp/image.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/image.el b/lisp/image.el index 1d07761..32df508 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -34,8 +34,8 @@ 'image-refresh (defconst image-type-header-regexps `(("\\`/[\t\n\r ]*\\*.*XPM.\\*/" . xpm) ("\\`P[1-6]\\(?:\ -\\(?:\\(?:#[^\r\n]*[\r\n]\\)?[[:space:]]\\)+\ -\\(?:\\(?:#[^\r\n]*[\r\n]\\)?[0-9]\\)+\ +\\(?:\\(?:#[^\r\n]*[\r\n]\\)*[[:space:]]\\)+\ +\\(?:\\(?:#[^\r\n]*[\r\n]\\)*[0-9]\\)+\ \\)\\{2\\}" . pbm) ("\\`GIF8[79]a" . gif) ("\\`\x89PNG\r\n\x1a\n" . png) --=20 2.7.4 --------------F9D14E69FB9D58E10B464B84--