symlink – Symbolic link UID/GID not restored by Busybox tar

I’m using Busybox tar (version 1.36.1, built with ‘defconfig’ configuration) to uncompress archives with symbolic links but theirs UID and GID are not preserved:

Setup:

: touch file1
: ln -s file1 link1
: ln -s file1 link2
: sudo chown -h root:root link2
: ls -l

-rw-r--r-- 1 ek1nox ek1nox 0 Jan  2 09:43 file1
lrwxrwxrwx 1 ek1nox ek1nox 5 Jan  2 09:44 link1 -> file1
lrwxrwxrwx 1 root   root   5 Jan  2 09:46 link2 -> file1

Compress / uncompress:

: sudo ../busybox-1.36.1/busybox tar czpf archive.tar.gz file1 link1 link2
: mkdir out
: cd out
: sudo ../../busybox-1.36.1/busybox tar xpf ../archive.tar.gz
: ls -l

-rw-r--r-- 1 ek1nox ek1nox 0 Jan  2 09:43 file1
lrwxrwxrwx 1 root   root   5 Jan  2 09:56 link1 -> file1
lrwxrwxrwx 1 root   root   5 Jan  2 09:56 link2 -> file1

Link1 should be owned by ‘ek1nox/ek1nox’ not ‘root/root’.

GNU tar preserves symlink UID/GID:

With the same archive:

: rm *
: sudo tar xpf ../archive.tar.gz
: ls -l

-rw-r--r-- 1 ek1nox ek1nox 0 Jan  2 09:43 file1
lrwxrwxrwx 1 ek1nox ek1nox 5 Jan  2 09:44 link1 -> file1
lrwxrwxrwx 1 root   root   5 Jan  2 09:46 link2 -> file1

From Busybox sources, function create_links_from_list (git.busybox.net/busybox/tree/archival/libarchive/unsafe_symlink_target.c), symbolic links are created but UID/GID are not set.

Is it an intentional behavior, a ‘missing functionality’ (bug) or something I have not understood?

Read more here: Source link