Hi Toybox maintainers,
First, thank you for your work on Toybox—it’s a great project and widely used (especially in Android).
I’m looking at the is_tar_header() function in toys/posix/tar.c, which includes this check:
if (p[148] != '0' && p[148] != ' ') return 0;
This appears to reject any tar header whose checksum field (at offset 148) does not start with either '0' or a space ' '.
However, I did not find this regulation in the POSIX ustar specification (IEEE Std 1003.1):
The fields magic, uname, and gname are character strings ...... typeflag contains a single character. All other fields are leading zero-filled octal numbers using digits from the ISO/IEC 646:1991 standard IRV. Each numeric field is terminated by one or more or NUL characters.
The chksum field shall be the ISO/IEC 646:1991 standard IRV representation of the octal value of the simple sum of all octets in the header logical record. Each octet in the header shall be treated as an unsigned value. These values shall be added to an unsigned integer, initialized to zero, the precision of which is not less than 17 bits. When calculating the checksum, the chksum field is treated as if it were all characters.
The standard does not require the checksum string to begin with '0' or a space—it only specifies that it be an octal, leading zero-filled number (Does that mean the meaning of that is must start with zero). Therefore, a valid checksum such as "123456 " should be acceptable, and its first byte would be '1'.
Could you clarify the rationale behind this restriction? Is it:
A deliberate compatibility choice (e.g., for Android’s expected tar format)?
An optimization to quickly reject malformed headers?
Or possibly an overly strict heuristic that could be relaxed to improve standards compliance?
If the goal is robustness, perhaps the check could be removed and rely solely on sscanf("%8o", ...) + checksum verification, which would align Toybox more closely with POSIX and other implementations.
Thanks again for your time and for maintaining this excellent codebase!
Best regards,
EMROF-H
Hi Toybox maintainers,
First, thank you for your work on Toybox—it’s a great project and widely used (especially in Android).
I’m looking at the is_tar_header() function in
toys/posix/tar.c, which includes this check:This appears to reject any tar header whose checksum field (at offset 148) does not start with either
'0'or a space' '.However, I did not find this regulation in the POSIX ustar specification (IEEE Std 1003.1):
The standard does not require the checksum string to begin with '0' or a space—it only specifies that it be an octal, leading zero-filled number (Does that mean the meaning of that is must start with zero). Therefore, a valid checksum such as "123456 " should be acceptable, and its first byte would be '1'.
Could you clarify the rationale behind this restriction? Is it:
A deliberate compatibility choice (e.g., for Android’s expected tar format)?
An optimization to quickly reject malformed headers?
Or possibly an overly strict heuristic that could be relaxed to improve standards compliance?
If the goal is robustness, perhaps the check could be removed and rely solely on sscanf("%8o", ...) + checksum verification, which would align Toybox more closely with POSIX and other implementations.
Thanks again for your time and for maintaining this excellent codebase!
Best regards,
EMROF-H