mirage / ocaml-tar

Pure OCaml library to read and write tar files
ISC License
54 stars 34 forks source link

pax and trailing '/' as directory #131

Closed reynir closed 9 months ago

reynir commented 1 year ago

In tar.2.5.1 I added backward compatible logic in Tar.Header.unmarshal to synthesize a Tar.Header.Link.Directory link indicator if the link indicator is either '0' or '\000' and the file name ends in a /.

In a95d00a5c9327072fbd089000314e2c3afbbccca a test was added with a specially crafted tar archive with an empty regular file placeholder with a preceding pax header setting path=clearly/a/directory/. I found that in GNU tar and bsdtar they list a directory clearly/a/directory as does tar.2.5.1.

@liebach was helpful in testing the behavior on OpenBSD:

# file pax-shenanigans.tar
pax-shenanigans.tar: data
# cat pax-shenanigans.tar
paxheader00004000000000000000000000000043000000000000006505x00000035 path=clearly/a/directory/
placeholder00004000000000000000000000000000000000000000006627
# tar tvf pax-shenanigans.tar
-r--------  1 root     wheel           35 Jan  1  1970 paxheader
-r--------  1 root     wheel            0 Jan  1  1970 placeholder
# tar xvf pax-shenanigans.tar  
paxheader
placeholder
# cat paxheader
00000035 path=clearly/a/directory/
# cat placeholder
# pax  -rv < pax-shenanigans.tar 
paxheader
placeholder
pax: tar vol 1, 2 files, 2560 bytes read, 0 bytes written.
#

It seems OpenBSD's tar and pax are not as easily convinced that the archive clearly contains a directory. It may be worth investigating why OpenBSD's tools treat the archive differently. In any case it's an archive unlikely to be found in the wild I suspect.

hannesm commented 9 months ago

Done in #127