Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tar.Header.marshal computes incorrect checksum when buffer is larger than Tar.Header.length and is non-zero #144

Closed
reynir opened this issue Feb 15, 2024 · 2 comments · Fixed by #145

Comments

@reynir
Copy link
Member

reynir commented Feb 15, 2024

Now I am struggling to write a reproducing example, but I had Tar.Header.marshal buf hdr which produced a new checksum every time even if the file was the same. Then I rewrote it to Tar.Hheader.marshal (Cstruct.sub buf 0 Tar.Header.length) hdr and the checksum was correct. It was a very long buffer with some random data near the end. It seems the header checksum is computed over the whole buffer, but we should only consider the first 512 bytes (the actual header).

This was observed in tar.2.6.0, but it seems it's an issue with main branch judging from the source code.

@reynir
Copy link
Member Author

reynir commented Feb 16, 2024

Reproducing snippet:

let cs = Cstruct.create 1024 in
Tar.Header.make "test" 5L |> Tar.Header.marshal cs;
(* Blit "Hello, World!" well outside the tar header *)
Cstruct.blit_from_string "Hello, World!" 0 cs 800 13;
Tar.Header.unmarshal cs

@reynir
Copy link
Member Author

reynir commented Feb 16, 2024

This is also an issue in Tar.Header.unmarshal on 2.6.0. In main branch we check the input buffer is Tar.Header.length long and thus does not allow this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant