Subject: cp -a --attributes-only zeroes a file with more than one link

From: Matt Kloss <[email-masked]>
Date: Tue, 31 Mar 2020 14:32:13 +0200

Hello,

When you cp -a --attributes-only a file which has a more than one “hardlink”, it zeroes the file:

$ echo hello > aaa

$ cp aaa foo

$ chmod 777 aaa

$ ls -li

total 8

407584 -rwxrwxrwx 1 matt matt 6 mars  31 14:19 aaa

399313 -rw-r--r-- 1 matt matt 6 mars  31 14:19 foo

$ cp -a --attributes-only aaa foo   # this is fine

$ ls -li

total 8

407584 -rwxrwxrwx 1 matt matt 6 mars  31 14:19 aaa

399313 -rwxrwxrwx 1 matt matt 6 mars  31 14:19 foo

$ ln foo foo2

$ cp -a --attributes-only aaa foo   # here comes the bug

$ ls -li

total 8

407584 -rwxrwxrwx 1 matt matt 6 mars  31 14:19 aaa

407740 -rwxrwxrwx 1 matt matt 0 mars  31 14:19 foo

399313 -rwxrwxrwx 1 matt matt 6 mars  31 14:19 foo2

foo has a size of 0 bytes!

The user thinks he's replicating timestamp and permissions, and he's actually deleting data. (Well, the data is still in foo2, but...)

coreutils 8.30

Matt