mirage / ocaml-tar

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

Incorrect parsing logic for pax Extended Headers #113

Closed MisterDA closed 1 year ago

MisterDA commented 1 year ago

otar (thus Tar_gz) cannot decompress itself, with the source archive generated by GitHub.

$ cd $(mktemp -d) || exit 
$ curl -LO 'https://github.com/mirage/ocaml-tar/archive/refs/heads/main.tar.gz'
$ tar tzf main.tar.gz 
ocaml-tar-main/
ocaml-tar-main/.gitattributes
ocaml-tar-main/.github/
ocaml-tar-main/.github/workflows/
# omitted for sobriety 
$ otar list main.tar.gz 
Fatal error: exception Tar.Header.Checksum_mismatch
Raised at Tar.Header.unmarshal in file "lib/tar.ml", line 378, characters 35-58
Called from Tar.HeaderReader.read.next_block.(fun) in file "lib/tar.ml", line 536, characters 13-45
Called from Tar.HeaderReader.read.get_hdr in file "lib/tar.ml", line 546, characters 6-13
Called from Tar.HeaderReader.read in file "lib/tar.ml", line 606, characters 4-14
Called from Tar_gz.Make.get_next_header in file "lib/tar_gz.ml", line 127, characters 4-36
Called from Dune__exe__Otar.list.go in file "bin/otar.ml", line 107, characters 24-49
Called from Dune__exe__Otar in file "bin/otar.ml", line 124, characters 4-17

They're generating POSIX tar archives.

MisterDA commented 1 year ago

I think it's just the decoding logic in Tar.header.unmarshal that is wrong for pax Extended Headers: there's no checksum in them.