unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* archive-mode lzh filename fiddling problems (patch)
@ 2007-04-14 22:02 Kevin Ryde
  2007-04-16  4:32 ` Richard Stallman
  2007-04-16 19:43 ` Chong Yidong
  0 siblings, 2 replies; 3+ messages in thread
From: Kevin Ryde @ 2007-04-14 22:02 UTC (permalink / raw)
  To: emacs-devel

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

In tinkering with some lzh archives I noticed two apparent problems
with the filename downcasing done by archive-lzh-summarize.

First, on an archive created by the lha for unix program, a file with
an all uppercase name only produces an empty buffer when viewed.  Eg.

	echo hi >README
	lha a foo.lzh README
	emacs -Q foo.lzh
	Ret
	=> empty buffer

where I hoped to see "hi".  Only upper case filenames seem affected,
you can see "Readme" or "readme" ok.

Second, on an archive file of "MS-DOS" type but with a mixed-case
name, viewing the member similarly produces an empty buffer.  I
noticed this on some downloaded self-extracting exes (which might come
from w32, if someone has that obscure system to try directly).  Eg.

	wget http://kanex.or.jp/history/BRO07.exe
	dd ibs=1 skip=30720 <BRO07.exe >BRO07.lzh
	emacs -Q BRO07.lzh
	Ret
	=> empty buffer

where I hoped to see the price of chicken futures.  You can also
change the .exe to .lzh by adding something to the archive, if you
don't trust dd.  Eg.

	lha a BRO07.exe /etc/passwd
	=> writes BRO07.lzh

Either way the .csv file in the archive isn't empty, you can see it
with the following.  (The contents are shift-jis, I don't think that
affects anything.)

	lha pq BRO07.lzh bro07.csv


I believe archive-lzh-summarize has to follow the lha program's
up/down casing, because that munged form is what it expects on the
command line when asked for an "lha pq" extract etc, as done by
archive-mode.  I get some joy from the change below.

For exercising the cases, lha for unix produces level 1 type U (unix)
archives, or with the g flag produces level 0 (generic, and upcase
names).  The broilers download above is level 2 type M (msdos) with
mixed case name.  And I tried some level 0 (generic) with mixed case
names from kanex which are no longer available for download.


2007-04-14  Kevin Ryde  <user42@zip.com.au>

	* arc-mode.el (archive-lzh-summarize): Two fixes to filename fiddling.

	Only apply the "downcase if all upcase" rule to OS-ID 0 "generic".
	This fixes extracting of upper case files like "README" from archives
	created on unix (such filenames should be left alone).

	Alwyas apply a downcase to OS-ID M "MSDOS".  This fixes extracting of
	mixed-case filenames from archives apparently created on w32 systems,
	eg. http://kanex.or.jp/history/BR07.exe (delete the first 30720 bytes
	of self-extracting code to make a .lzh).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: arc-mode.el.lzh-filename-fiddle.diff --]
[-- Type: text/x-diff, Size: 2612 bytes --]

*** arc-mode.el	12 Mar 2007 10:14:18 +1100	1.79
--- arc-mode.el	14 Apr 2007 19:13:53 +1000	
***************
*** 1415,1421 ****
  	     (time2   (archive-l-e (+ p 17) 2))	;and UNIX format in level 2 header.)
  	     (hdrlvl  (char-after (+ p 20))) ;header level
  	     thsize		;total header size (base + extensions)
! 	     fnlen efnname fiddle ifnname width p2
  	     neh	;beginning of next extension header (level 1 and 2)
  	     mode modestr uid gid text dir prname
  	     gname uname modtime moddate)
--- 1415,1421 ----
  	     (time2   (archive-l-e (+ p 17) 2))	;and UNIX format in level 2 header.)
  	     (hdrlvl  (char-after (+ p 20))) ;header level
  	     thsize		;total header size (base + extensions)
! 	     fnlen efnname osid fiddle ifnname width p2
  	     neh	;beginning of next extension header (level 1 and 2)
  	     mode modestr uid gid text dir prname
  	     gname uname modtime moddate)
***************
*** 1474,1480 ****
  	      (setq thsize (- neh p))))
  	(if (= hdrlvl 0)  ;total header size
  	    (setq thsize hsize))
! 	(setq fiddle  (if efnname (string= efnname (upcase efnname))))
  	(setq ifnname (if fiddle (downcase efnname) efnname))
  	(setq prname (if dir (concat dir ifnname) ifnname))
  	(setq width (if prname (string-width prname) 0))
--- 1474,1495 ----
  	      (setq thsize (- neh p))))
  	(if (= hdrlvl 0)  ;total header size
  	    (setq thsize hsize))
!         ;; OS ID field not present in level 0 header, use code 0 "generic"
!         ;; in that case as per lha program header.c get_header()
! 	(setq osid (cond ((= hdrlvl 0)  0)
!                          ((= hdrlvl 1)  (char-after (+ p 22 fnlen 2)))
!                          ((= hdrlvl 2)  (char-after (+ p 23)))))
!         ;; Filename fiddling must follow the lha program, otherwise the name
!         ;; passed to "lha pq" etc won't match (which for an extract silently
!         ;; results in no output).  As of version 1.14i it goes from the OS ID,
!         ;; - For 'M' MSDOS: msdos_to_unix_filename() downcases always, and
!         ;;   converts "\" to "/".
!         ;; - For 0 generic: generic_to_unix_filename() downcases if there's
!         ;;   no lower case already present, and converts "\" to "/".
!         ;; - For 'm' MacOS: macos_to_unix_filename() changes "/" to ":" and
!         ;;   ":" to "/"
! 	(setq fiddle (cond ((= ?M osid) t)
!                            ((= 0 osid)  (string= efnname (upcase efnname)))))
  	(setq ifnname (if fiddle (downcase efnname) efnname))
  	(setq prname (if dir (concat dir ifnname) ifnname))
  	(setq width (if prname (string-width prname) 0))

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

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

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

* Re: archive-mode lzh filename fiddling problems (patch)
  2007-04-14 22:02 archive-mode lzh filename fiddling problems (patch) Kevin Ryde
@ 2007-04-16  4:32 ` Richard Stallman
  2007-04-16 19:43 ` Chong Yidong
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Stallman @ 2007-04-16  4:32 UTC (permalink / raw)
  To: emacs-devel; +Cc: Kevin Ryde

Would someone else please look at this patch
to verify it is fully correct?


From: Kevin Ryde <user42@zip.com.au>
To: emacs-devel@gnu.org
Date: Sun, 15 Apr 2007 08:02:55 +1000
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Subject: archive-mode lzh filename fiddling problems (patch)

--=-=-=

In tinkering with some lzh archives I noticed two apparent problems
with the filename downcasing done by archive-lzh-summarize.

First, on an archive created by the lha for unix program, a file with
an all uppercase name only produces an empty buffer when viewed.  Eg.

	echo hi >README
	lha a foo.lzh README
	emacs -Q foo.lzh
	Ret
	=> empty buffer

where I hoped to see "hi".  Only upper case filenames seem affected,
you can see "Readme" or "readme" ok.

Second, on an archive file of "MS-DOS" type but with a mixed-case
name, viewing the member similarly produces an empty buffer.  I
noticed this on some downloaded self-extracting exes (which might come
from w32, if someone has that obscure system to try directly).  Eg.

	wget http://kanex.or.jp/history/BRO07.exe
	dd ibs=1 skip=30720 <BRO07.exe >BRO07.lzh
	emacs -Q BRO07.lzh
	Ret
	=> empty buffer

where I hoped to see the price of chicken futures.  You can also
change the .exe to .lzh by adding something to the archive, if you
don't trust dd.  Eg.

	lha a BRO07.exe /etc/passwd
	=> writes BRO07.lzh

Either way the .csv file in the archive isn't empty, you can see it
with the following.  (The contents are shift-jis, I don't think that
affects anything.)

	lha pq BRO07.lzh bro07.csv


I believe archive-lzh-summarize has to follow the lha program's
up/down casing, because that munged form is what it expects on the
command line when asked for an "lha pq" extract etc, as done by
archive-mode.  I get some joy from the change below.

For exercising the cases, lha for unix produces level 1 type U (unix)
archives, or with the g flag produces level 0 (generic, and upcase
names).  The broilers download above is level 2 type M (msdos) with
mixed case name.  And I tried some level 0 (generic) with mixed case
names from kanex which are no longer available for download.


2007-04-14  Kevin Ryde  <user42@zip.com.au>

	* arc-mode.el (archive-lzh-summarize): Two fixes to filename fiddling.

	Only apply the "downcase if all upcase" rule to OS-ID 0 "generic".
	This fixes extracting of upper case files like "README" from archives
	created on unix (such filenames should be left alone).

	Alwyas apply a downcase to OS-ID M "MSDOS".  This fixes extracting of
	mixed-case filenames from archives apparently created on w32 systems,
	eg. http://kanex.or.jp/history/BR07.exe (delete the first 30720 bytes
	of self-extracting code to make a .lzh).


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment; filename=arc-mode.el.lzh-filename-fiddle.diff

*** arc-mode.el	12 Mar 2007 10:14:18 +1100	1.79
--- arc-mode.el	14 Apr 2007 19:13:53 +1000	
***************
*** 1415,1421 ****
  	     (time2   (archive-l-e (+ p 17) 2))	;and UNIX format in level 2 header.)
  	     (hdrlvl  (char-after (+ p 20))) ;header level
  	     thsize		;total header size (base + extensions)
! 	     fnlen efnname fiddle ifnname width p2
  	     neh	;beginning of next extension header (level 1 and 2)
  	     mode modestr uid gid text dir prname
  	     gname uname modtime moddate)
--- 1415,1421 ----
  	     (time2   (archive-l-e (+ p 17) 2))	;and UNIX format in level 2 header.)
  	     (hdrlvl  (char-after (+ p 20))) ;header level
  	     thsize		;total header size (base + extensions)
! 	     fnlen efnname osid fiddle ifnname width p2
  	     neh	;beginning of next extension header (level 1 and 2)
  	     mode modestr uid gid text dir prname
  	     gname uname modtime moddate)
***************
*** 1474,1480 ****
  	      (setq thsize (- neh p))))
  	(if (= hdrlvl 0)  ;total header size
  	    (setq thsize hsize))
! 	(setq fiddle  (if efnname (string= efnname (upcase efnname))))
  	(setq ifnname (if fiddle (downcase efnname) efnname))
  	(setq prname (if dir (concat dir ifnname) ifnname))
  	(setq width (if prname (string-width prname) 0))
--- 1474,1495 ----
  	      (setq thsize (- neh p))))
  	(if (= hdrlvl 0)  ;total header size
  	    (setq thsize hsize))
!         ;; OS ID field not present in level 0 header, use code 0 "generic"
!         ;; in that case as per lha program header.c get_header()
! 	(setq osid (cond ((= hdrlvl 0)  0)
!                          ((= hdrlvl 1)  (char-after (+ p 22 fnlen 2)))
!                          ((= hdrlvl 2)  (char-after (+ p 23)))))
!         ;; Filename fiddling must follow the lha program, otherwise the name
!         ;; passed to "lha pq" etc won't match (which for an extract silently
!         ;; results in no output).  As of version 1.14i it goes from the OS ID,
!         ;; - For 'M' MSDOS: msdos_to_unix_filename() downcases always, and
!         ;;   converts "\" to "/".
!         ;; - For 0 generic: generic_to_unix_filename() downcases if there's
!         ;;   no lower case already present, and converts "\" to "/".
!         ;; - For 'm' MacOS: macos_to_unix_filename() changes "/" to ":" and
!         ;;   ":" to "/"
! 	(setq fiddle (cond ((= ?M osid) t)
!                            ((= 0 osid)  (string= efnname (upcase efnname)))))
  	(setq ifnname (if fiddle (downcase efnname) efnname))
  	(setq prname (if dir (concat dir ifnname) ifnname))
  	(setq width (if prname (string-width prname) 0))

--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
--=-=-=--

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

* Re: archive-mode lzh filename fiddling problems (patch)
  2007-04-14 22:02 archive-mode lzh filename fiddling problems (patch) Kevin Ryde
  2007-04-16  4:32 ` Richard Stallman
@ 2007-04-16 19:43 ` Chong Yidong
  1 sibling, 0 replies; 3+ messages in thread
From: Chong Yidong @ 2007-04-16 19:43 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: emacs-devel

Kevin Ryde <user42@zip.com.au> writes:

> In tinkering with some lzh archives I noticed two apparent problems
> with the filename downcasing done by archive-lzh-summarize.

Thanks for the patch.  It looks plausible (I don't know much about
lzh) so I checked it in.

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

end of thread, other threads:[~2007-04-16 19:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-14 22:02 archive-mode lzh filename fiddling problems (patch) Kevin Ryde
2007-04-16  4:32 ` Richard Stallman
2007-04-16 19:43 ` Chong Yidong

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).