Subject: 31.0.50; arc-mode: Split PKZIP archive signature not recognized

From: Jens Schmidt <[email-masked]>
Date: Fri, 18 Apr 2025 14:30:59 +0200

The attached zip file is a "real" one, in the sense that it has been
created in the wild.  It is a stripped down "terraform stack" generated
by one of the cloud providers.

InfoZIP's unzip can handle that file without problems:

  [emacs-master]$ unzip -v
  UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.
  [...]

  [emacs-master]$ unzip -l tf-stack.zip
  Archive:  tf-stack.zip
    Length      Date    Time    Name
  ---------  ---------- -----   ----
         38  2025-04-01 08:43   provider.tf
  ---------                     -------
         38                     1 file

However, "./src/emacs -Q tf-stack.zip" fails on it with:

  File mode specification error: (error "Buffer format not recognized")

It turns out that the zip file starts with a special marker 0x08074b50
for spanned or split archives, as defined in the pseudo zip file
specification "APPNOTE.txt" by PKWARE.  See section 8.5 "Capacities and
Markers" of that document for more details.

The attached patch provides support for the aforementioned special
marker, alongside with the already present "temporary spanning marker"
0x30304b50.  The patch itself is trivial, but I tried to provide above
information also in the commit message for future reference.

WDYT?

Thanks!

In GNU Emacs 31.0.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.16.0) of 2025-04-18 built on sappc2
Repository revision: 9f0c43a3d1b38c93bf21bf25db0f5dd489338d7c
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12201009
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure --with-native-compilation --with-mailutils'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP
NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS WEBP X11 XDBE XIM XINERAMA XINPUT2 XPM XRANDR GTK3
ZLIB

Important settings:
  value of $LC_COLLATE: POSIX
  value of $LC_TIME: POSIX
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug lisp-mnt message mailcap yank-media puny
dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg
rfc6068 epg-config gnus-util time-date mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
compile text-property-search comint subr-x ansi-osc ansi-color ring
comp-run bytecomp byte-compile comp-common rx arc-mode archive-mode rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd touch-screen tool-bar dnd fontset image regexp-opt
fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting cairo gtk x-toolkit xinput2 x multi-tty move-toolbar
make-network-process tty-child-frames native-compile emacs)

Memory information:
((conses 16 72011 11711) (symbols 48 7037 0) (strings 32 18600 1457)
 (string-bytes 1 583099) (vectors 16 11590)
 (vector-slots 8 158155 10743) (floats 8 23 12) (intervals 56 264 0)
 (buffers 984 13))

From d6deeb6724b5d22a15af67c73e0a5752b7cebb46 Mon Sep 17 00:00:00 2001
From: Jens Schmidt <[email-masked]>
Date: Fri, 18 Apr 2025 14:16:17 +0200
Subject: [PATCH] Detect more types of split zip archives

According to the inofficial zip file specification APPNOTE.txt by
PKWARE, zip files can come with extra signatures 0x08074b50 or
0x30304b50 before the local header.  See Section "Capacities and
Markers" of that document.

* lisp/arc-mode.el (archive-find-type): Detect more types of split zip
archives.  (Bug XXXXX)
---
 lisp/arc-mode.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el
index 28be1e9c617..b4c45318028 100644
--- a/lisp/arc-mode.el
+++ b/lisp/arc-mode.el
@@ -792,7 +792,7 @@ archive-find-type
   ;; The funny [] here make it unlikely that the .elc file will be treated
   ;; as an archive by other software.
   (let (case-fold-search)
-    (cond ((looking-at "\\(PK00\\)?[P]K\003\004") 'zip)
+    (cond ((looking-at "\\(?:PK00\\|PK\007\010\\)?[P]K\003\004") 'zip)
 	  ((looking-at "..-l[hz][0-9ds]-") 'lzh)
 	  ((looking-at "....................[\334]\247\304\375") 'zoo)
 	  ((and (looking-at "\C-z")	; signature too simple, IMHO
--
2.39.5