Bug 103 - tar cannot handle names that are exactly 100 chars
Summary: tar cannot handle names that are exactly 100 chars
Status: RESOLVED WORKSFORME
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.13.x
Hardware: All Linux
: P5 enhancement
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-11 21:10 UTC by Frans Meulenbroeks
Modified: 2009-05-02 14:35 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frans Meulenbroeks 2009-02-11 21:10:52 UTC
confirmed in 1.13.2:

tar cannot handle filenames that are exactly 100 characters.
It creates an entry of the normal type (so no gnu long extension), and the name header field is completely filled.
When extracting such a file, the name is copied with strdup, but as there is no 0 byte after the name, the rights are also copied, resulting in a file that e.g. ends in 000644.

Fix is probably in get_header_tar.c after line 254:
	file_header->name = xstrdup(tar.name);
add a statement like:
    if (strlen(file_header->name) > 100) file_header->name[100] = 0;

but there might be a better solution.
Comment 1 Denys Vlasenko 2009-02-12 23:29:08 UTC
The code is:

        if (!p_longname && parse_names) {
                /* we trash mode[0] here, it's ok */
                //tar.name[sizeof(tar.name)] = '\0'; - gcc 4.3.0 would complain
                tar.mode[0] = '\0';
                if (tar.prefix[0]) {
                        /* and padding[0] */
                        //tar.prefix[sizeof(tar.prefix)] = '\0';
                        tar.padding[0] = '\0';
                        file_header->name = concat_path_file(tar.prefix, tar.name);
                } else
                        file_header->name = xstrdup(tar.name);
        }

Note how tar.mode[0] = '\0' inserts terminating NUL, thus xstrdup will stop at 100th char.

I also tried to reproduce it and successfully tarred and untarred a file with a 100-characher filename.

Please attach a tar file which unpacks incorrectly with busybox tar.