Bug 1225407

Summary: GNU tar hangs when extracting certain hard links
Product: [openSUSE] openSUSE Tumbleweed Reporter: Tristan Miller <psychonaut>
Component: BasesystemAssignee: Antonio Teixeira <antonio.teixeira>
Status: NEW --- QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None    
Version: Current   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Tristan Miller 2024-05-27 18:49:45 UTC
The version of GNU tar 1.35 packaged for openSUSE Tumbleweed hangs when using --wildcards to extract a symlink to another file in the archive that does not match the wildcard.  The problem may be specific to the openSUSE RPMs; I cannot reproduce it when using GNU tar 1.35 compiled from source.

An example of an archive that can reproduce this problem is at <http://files.nothingisreal.com/tmp/news002f1.tar.bz2>.  Using the command line

tar xavf news002f1.tar.bz2

the archive is successfully extracted.  But if I add a --wildcards option such as

tar xavf news002f1.tar.bz2 --wildcards '*trek*'

then tar hangs when it gets to the file news002f1/b5/net.startrek/24. This file, which matches the wildcard, is a symlink to the file news002f1/b5/net.sf-lovers/141, which does not match the wildcard. Running tar with strace shows that tar gets stuck in a loop:

mkdirat(AT_FDCWD, "news002f1", 0755)    = -1 EEXIST (File exists)
mkdirat(AT_FDCWD, "news002f1/b5", 0755) = -1 EEXIST (File exists)
mkdirat(AT_FDCWD, "news002f1/b5/net.startrek", 0755) = -1 EEXIST (File exists)
newfstatat(AT_FDCWD, "news002f1/b5/net.startrek", {st_mode=S_IFDIR|0755, st_size=4096, ...}, 0) = 0
linkat(AT_FDCWD, "news002f1/b5/net.sf-lovers/141", AT_FDCWD, "news002f1/b5/net.startrek/24", 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "news002f1/b5/net.sf-lovers/141", 0x7fffcaca26a0, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)

By contrast, GNU tar 1.35 compiled from source does not hang; it instead emits the error messages of the following sort for the affected symlinks and then continues processing the archive:

Cannot hard link to ‘news002f1/b5/net.sf-lovers/141’: No such file or directory
Comment 1 Tristan Miller 2024-05-28 13:37:55 UTC
s/symlink/hard link/g