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

xar --dump-toc-raw dumps the wrong part of the file #11

Open
palant opened this issue Aug 16, 2016 · 0 comments
Open

xar --dump-toc-raw dumps the wrong part of the file #11

palant opened this issue Aug 16, 2016 · 0 comments

Comments

@palant
Copy link

palant commented Aug 16, 2016

For the file I generated xar --dump-header produces the following output:

magic:                   0x78617221 (OK)
size:                    28
version:                 1
Compressed TOC length:   15572
Uncompressed TOC length: 78349
TOC Checksum algorithm:  1 (sha1)

When I run xar --dump-toc-raw I get a piece of the file that is 15572 bytes long but it starts at offset 64 and not 28. Consequently, attempts to hash it produce results that don't match the checksum in the archive.

The problem seems to be this line:

if( read(fd, &xh, sizeof(xh)) < (int)sizeof(xar_header_t) ) {

Type of variable xh is xar_header_ex_t which is 64 bytes large, so this will read 64 bytes from the file. And even though the code recognizes reading too much, the file pointer isn't set back.

Since the code doesn't care about the algorithm name, it should just read out the regular xar_header_t structure. If it then discovers that xh.size is larger than what it read already then it can just skip ahead in the file.

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

No branches or pull requests

1 participant