Subject: 29.0.60; WEBP header regexp in image-type-header-regexps fails files containing newlines
From: Visuwesh <[email-masked]>
To: [email-masked]
Date: Wed, 12 Apr 2023 19:17:13 +0530
List-Id: <debbugs-submit.debbugs.gnu.org>

Attached image contains a newline in the header after "RIFF" which the
regexp in image-type-header-regexps fails to match.  This makes
create-image return nil for such an image when FILE-OR-DATA is DATA and
DATA-P is non-nil.

The following patch fixes the issue for me,

diff --git a/lisp/image.el b/lisp/image.el
index 29c39c5dd5..9221057bce 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -51,7 +51,7 @@ image-type-header-regexps
     ("\\`\\(?:MM\0\\*\\|II\\*\0\\)" . tiff)
     ("\\`[\t\n\r ]*%!PS" . postscript)
     ("\\`\xff\xd8" . jpeg)    ; used to be (image-jpeg-p . jpeg)
-    ("\\`RIFF....WEBPVP8" . webp)
+    ("\\`RIFF[^z-a][^z-a][^z-a][^z-a]WEBPVP8" . webp)
     (,(let* ((incomment-re "\\(?:[^-]\\|-[^-]\\)")
 	     (comment-re (concat "\\(?:!--" incomment-re "*-->[ \t\r\n]*<\\)")))
 	(concat "\\(?:<\\?xml[ \t\r\n]+[^>]*>\\)?[ \t\r\n]*<"

[ [^z-a] is documented in (info "(elisp) Regexp Special").  ]

In GNU Emacs 29.0.60 (build 2, x86_64-pc-linux-gnu, X toolkit, Xaw
 scroll bars) of 2023-03-23 built on astatine
Repository revision: be8147c53f9dd2d896c27d5b32bf4f38b0af9b3f
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Debian GNU/Linux bookworm/sid

Configured using:
 'configure --with-sound=alsa --with-x-toolkit=lucid --with-json
 --without-xaw3d --without-gconf --without-libsystemd --without-cairo'
Configured features:
ACL DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG JSON
LIBOTF LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG
SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS WEBP X11 XDBE XFT
XIM XINPUT2 XPM LUCID ZLIB
Important settings:
  value of $LC_MONETARY: ta_IN.UTF-8
  value of $LC_NUMERIC: ta_IN.UTF-8
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  hexl-follow-ascii: t
  csv-field-index-mode: t
  recentf-mode: t
  shell-dirtrack-mode: t
  server-mode: t
  paredit-mode: t
  eros-mode: t
  flymake-mode: t
  pdf-occur-global-minor-mode: t
  minibuffer-depth-indicate-mode: t
  repeat-mode: t
  display-time-mode: t
  display-battery-mode: t
  delete-selection-mode: t
  xterm-mouse-mode: t
  straight-use-package-mode: t
  straight-package-neutering-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  use-hard-newlines: t
  tab-bar-history-mode: t
  tab-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  undelete-frame-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  abbrev-mode: t

Load-path shadows:
None found.

Features:
(ruler-mode hl-line hexl expand-region text-mode-expansions
cc-mode-expansions the-org-mode-expansions python-el-fgallina-expansions
er-basic-expansions expand-region-core ...)

Memory information:
((conses 16 5541494 789498)
 (symbols 48 70186 141)
 (strings 32 495814 72788)
 (string-bytes 1 144111870)
 (vectors 16 216791)
 (vector-slots 8 4288415 706143)
 (floats 8 37436 2621)
 (intervals 56 497259 17293)
 (buffers 976 448))