gpg: overwriting .pdf on encryption => decryption fails

David Shaw dshaw at jabberwocky.com
Thu Jun 21 15:34:34 CEST 2012


On Jun 21, 2012, at 5:47 AM, Marius Hofert wrote:

> I'm not sure if I found a bug. I asked on stackoverflow where it was recommended
> to write to this mailing list. Here is the link to the problem:
> http://stackoverflow.com/questions/11134583/gpg-overwriting-pdf-on-encryption-decryption-fails 
> 
> For convenience, here is the problem description (as on stackoverflow):
> 
> I use gpg (GnuPG) 1.4.11. to encrypt a file foo.pdf via gpg -c foo.pdf. The encrypted file is then foo.pdf.gpg and, additionally, the original file foo.pdf exists. I can then decrypt foo.pdf.gpg via gpg foo.pdf.gpg as expected. However, if I use gpg -o foo.pdf -c foo.pdf and choose to overwrite the existing file on encryption, then use gpg foo.pdf to decrypt the encrypted file, and finally choose to overwrite the existing file foo.pdf (again), the file is still protected and can't be viewed.
> 
> I then tried to execute gpg foo.pdf again (I thought decrypting failed the first time, that's why I tried it again). Now the file seems to be corrupted: "gpg: [don't know]: 1st length byte missing"

GPG is writing to the same file it's reading from (no temp files).   As it reads plaintext to encrypt, that data is being clobbered by the already-encrypted data GPG is writing out (or vice versa on decryption).

David




More information about the Gnupg-devel mailing list