Crash when copying unencrypted backup to encrypted GDrive (invalid memory address or nil pointer dereference)

Hey Guys, I’ve got a duplicacy crash when I’m trying to copy my non-encrypted SFTP storage to encrypted (both with password and RSA) GDrive.

My setup:

I’m backing up couple of PC’s to my NAS via SFTP (“unencrypted” duplicacy storage).

Some parts of my NAS are backed up to GDrive (that is “encrypted” one, with both password and RSA encryption).

I’ve tried to copy my “unencrypted” NAS storage to the same storage on the GDrive, but encrypt it on-the-fly.

In order to do so, I’ve created “fake” id on the NAS itself, pointing the the same storage as my PC’s, and than I’ve ran duplicacy copy command.

As a result I’ve got a crash, listed below.

My “preferences” file from the NAS:

        "name": "default",
        "id": "<fake_name>",
        "repository": "/root",
        "storage": "<path_to_local_unencrypted_chunks>",
        "encrypted": false,
        "no_backup": false,
        "no_restore": false,
        "no_save_password": false,
        "nobackup_file": "",
        "keys": null,
        "filters": ""
        "name": "gdrive",
        "id": "<name_of_real_storage_on_gdrive>",
        "repository": "",
        "storage": "gcd://Backup/Duplicacy",
        "encrypted": true,
        "no_backup": false,
        "no_restore": false,
        "no_save_password": false,
        "nobackup_file": "",
	"keys": {
            "gcd_token": "/root/gcd-token.json",
            "password": "<password>"
        "filters": "/root/filters"

Please describe what you are doing to trigger the bug:

duplicacy copy -key <path_to_private_key.pem> -from default -to gdrive

and than I’m putting a passphrase to the key

Please describe what you expect to happen (but doesn’t):

Not to crash, and copy contents of the backup :slight_smile:

Please describe what actually happens (the wrong behaviour):

I get this crash with stack trace:

root@duplicacy:~ # duplicacy copy -key <path_to_key> -from default -to gdrive
Repository set to /root
Source storage set to /mnt/duplicacy
Enter the passphrase for /root/private.pem:*********************************************
runtime error: invalid memory address or nil pointer dereference
goroutine 1 [running]:
runtime/debug.Stack(0x41, 0x0, 0x0)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
	/usr/local/go/src/runtime/debug/stack.go:16 +0x22
	/Users/chgang/zincbox/go/src/ +0xee
panic(0xd0ef20, 0x166e880)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
crypto/rsa.EncryptOAEP(0xfc9200, 0xc0000d4300, 0xfb0e80, 0xc0000941b0, 0x0, 0xc0000bc2e0, 0x20, 0x20, 0x0, 0x0, ...)
	/usr/local/go/src/crypto/rsa/rsa.go:377 +0x38*Config).loadRSAPrivateKey(0xc000226180, 0x7fffffffedc4, 0x20, 0xc0000bc140, 0x14)
	/Users/chgang/zincbox/go/src/ +0x592*BackupManager).LoadRSAPrivateKey(...)
main.loadRSAPrivateKey(0x7fffffffedc4, 0x20, 0xc000240000, 0xc00012e420, 0x0)
	/Users/chgang/zincbox/go/src/ +0x1aa
	/Users/chgang/zincbox/go/src/ +0x41b, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe46fb9, 0x2a, 0x0, ...)
	/Users/chgang/zincbox/go/src/ +0x74d*App).Run(0xc0001e4480, 0xc0000b2000, 0x8, 0x8, 0x0, 0x0)
	/Users/chgang/zincbox/go/src/ +0x64f
	/Users/chgang/zincbox/go/src/ +0x5b58

You don’t need to provide the private key when copying to the gdrive storage. It is only needed when copying out of an RSA-encrypted storage to another.

Nevertheless Duplicacy should have just thrown an error message instead of crashing. I’ll fix this bug.

1 Like

The crash has been fixed by Do not take an RSA private key if the storage wasn't RSA encrypted. · gilbertchen/duplicacy@733b68b · GitHub

However, I found another (more serious) bug when the destination storage is RSA-encrypted. In the copy command we relied on the encryption flag to determine if a chunk is a snapshot chunk or now, but if the source storage is not RSA-encrypted then every chunk is treated as a snapshot chunk and thus the RSA encryption is not enabled for any chunk when uploading to the destination storage.

I’ve fixed this bug in Fixed a bug that disabled RSA when copying from a non RSA-encrypted s… · gilbertchen/duplicacy@6699e2f · GitHub. I’ll release a new version 2.4.1 for this fix.