lzip-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tarlz: error archiving broken symbolic link


From: Antonio Diaz Diaz
Subject: Re: tarlz: error archiving broken symbolic link
Date: Mon, 07 Mar 2022 17:40:34 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14

Hello Jason,

Jason Lenz wrote:
$ tarlz -cf test.tar.lz /path/to/files
...
tarlz: /path/to/files/broken-symlink: Error reading link

I guess there is some difference between your system and mine, because I can't reproduce the error (not even by writing the archive to test.tar.lz):

$ md dir
$ touch dir/a dir/b
$ ln -s foo dir/broken-symlink
$ ls -go dir
total 0
-rw-r--r-- 1 0 Mar  7 16:35 a
-rw-r--r-- 1 0 Mar  7 16:35 b
lrwxrwxrwx 1 3 Mar  7 16:36 broken-symlink -> foo
$ tarlz -c dir | tarlz -tv ; echo $?
drwxr-xr-x antonio/users        0 2022-03-07 16:36 dir
-rw-r--r-- antonio/users        0 2022-03-07 16:35 dir/a
-rw-r--r-- antonio/users        0 2022-03-07 16:35 dir/b
lrwxrwxrwx antonio/users        0 2022-03-07 16:36 dir/broken-symlink -> foo
0

When replacing tarlz with standard GNU tar version 1.34 and the exact
same command line, it would successfully create the archive containing
the broken symlink files.

Thanks for the hint. I think I may have found the cause of the problem. In line 443 of create.cc tarlz calls readlink passing the size of the buffer and expecting as return value the size of the contents of the symbolic link:

  len = sz = readlink( filename, (char *)header + linkname_o, linkname_l );

But according to POSIX[1]:

"If the number of bytes in the symbolic link is less than bufsize, the contents of the remainder of buf are unspecified."

and

"Upon successful completion, these functions shall return the count of bytes placed in the buffer."

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html

So readlink may be returning more bytes than it should if the link is shorter than the buffer. One possible fix would be to change line 443 to ask just for the bytes required instead of passing the full size of the buffer:

  len = sz = readlink( filename, (char *)header + linkname_o, st.st_size );

I have tried this change and it works. Please, test the change and report back. If it also works for you, I'll release a corrected version.

P.S.: I really appreciate your efforts on lzip and associated utilities.

Thanks. :-)

Best regards,
Antonio.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]