Skip to content

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

@palant

Description

@palant

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions