AgentD / squashfs-tools-ng

A new set of tools and libraries for working with SquashFS images
Other
196 stars 30 forks source link

malformed extended header in tar created with sqfs2tar #50

Closed smoser closed 4 years ago

smoser commented 4 years ago

I've found an issue in tar creation using sqfs2tar. I'm attaching a image that shows the problem ( my-squashfs.img.gz). It is gzipped because github won't let me upload it otherwise.

I'm running sqfs2tar from ubuntu's 20.10 deb (0.9-1).

$ sqfs2tar --version
sqfs2tar (squashfs-tools-ng) 0.9
Copyright (c) 2019 David Oberhollenzer et al
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ unsquashfs -lln my-squashfs.img
Parallel unsquashfs: Using 32 processors
1 inodes (214 blocks) to write

drwxrwxrwx 1001/1001                34 2020-05-14 11:33 squashfs-root
-rw-r--r-- 0/0                28017887 2020-05-07 17:30 squashfs-root/primary.xml

$ sqfs2tar my-squashfs.img > my.tar

$ tar tvf my.tar ; echo $?
tar: Malformed extended header: missing newline
tar: Substituting `.' for empty member name
?rw-r--r-- 0/0        28017887 2020-05-07 17:30  unknown file type ‘ ’
tar: Exiting with failure status due to previous errors
AgentD commented 4 years ago

Hi!

Thanks for submitting the sample. I could reproduce the problem and track it down to a faulty length accounting of the line length in the PAX header generated for the xattrs.

The header contains a list of plain ASCII key-value pairs that are prefixed with their length. The tricky part being that the length must include the number of digits required to represent the length itself.

There was a typo in the computation of the number of digits (> instead of >=). Your sample triggered the right condition that result was off and too many padding bytes were added, causing the following tar header to be misaligned.

Commit 692cbd0079658a8eb048c9b00dadec2d69d28b14 should fix the problem.

Thanks!