Skip to content

Tar.Header.make and PAX #142

@reynir

Description

@reynir

The Tar.Header.make function checks the size required for the file size, uid and gid and creates an extended header if needed. This could as well check the file name size and other fields.

ocaml-tar/lib/tar.ml

Lines 466 to 489 in ef66a98

(** Helper function to make a simple header *)
let make ?(file_mode=0o400) ?(user_id=0) ?(group_id=0) ?(mod_time=0L) ?(link_indicator=Link.Normal) ?(link_name="") ?(uname="") ?(gname="") ?(devmajor=0) ?(devminor=0) file_name file_size =
(* If some fields are too big, we must use a pax header *)
let need_pax_header =
Int64.unsigned_compare file_size 0o077777777777L > 0
|| user_id > 0x07777777
|| group_id > 0x07777777 in
let extended =
if need_pax_header
then Some (Extended.make ~file_size ~user_id ~group_id ())
else None in
{ file_name;
file_mode;
user_id;
group_id;
file_size;
mod_time;
link_indicator;
link_name;
uname;
gname;
devmajor;
devminor;
extended }

A problem, though, is that the compatibility level is not considered, and in our writer we don't check the compatibility level before writing the extended header. This means we can set compatibility level to V7 but still get PAX extended headers. There is as well a discrepancy how we handle this for GNU compatibility level -- there we synthesize the GNU LongLink in the writer instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions