Subject: bug#24244: bug: dd deletes file

From: Pádraig Brady <[email-masked]>
Date: Tue, 16 Aug 2016 17:03:53 +0100

On 16/08/16 16:44, puggy wrote:
> i've just found a bug in "dd".
> 
> by mistakes i used the same input and output file.
> dd said it wrote 0 bytes, but what it actually did
> is overwrite the file and setting it back to zero.
> doing so, dd deleted a 4.3G file in a fraction of
> a blink.
> 
> luckily i can download the file again. but before 
> it took me 2 hours to download this file. now i 
> have to download it again, wait for another 2 
> hours and i can't work for this time. 2 hours for
> a little mistake. 4 hours time loss!
> 
> this can't happen. mistakes happen. by simple
> logics it doesn't make sense to delete a file,
> just because input and output file are the same.
> also there is barely anything easier to check
> for.
> 
> please find some solution for it. if it is
> intentional, make an option for it. this way
> you can also shorten the command. otherwise 
> if input and output are the same, warn the user!

Well dd is a low level tool so we have to be careful
to not preclude operations which may be valid in some cases.
For example one might definitely want to read/write the same device.
Also conv=notrunc might be useful with regular files
to fully allocate holes etc. Maybe we could:

  if (IS_REG() && conv!=notrunc)
    disallow input==output