Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Decrypt_file hangs indefinitely on AttributeError if using output_file and invalid file object #152

@vsajip

Description

@vsajip

Original report by Anonymous.


Hi,

I noticed that the decrypt_file funtion hangs indefinitely if the file argument is a string instead of a file object and the output-argument is given. Without the output argument, the function call returns with invalid state.

Code

#!python

crypt = gnupg.GPG(gnupghome=conf.GPG_HOME)
file_path = "foobar.txt"
decrypted = crypt.decrypt_file(file_path, passphrase="", output="decrypted.txt")

Relevant log messages

#!bash

2021-05-25T09:02:25.288 gnupg              DD [] 7: gpg --status-fd 2 --no-tty --no-verbose --fixed-list-mode --batch --with-colons --homedir /var/gpghome --version
2021-05-25T09:02:25.288 gnupg              DD [] stderr reader: <Thread(Thread-1, initial daemon)>
2021-05-25T09:02:25.288 gnupg              DD [] stdout reader: <Thread(Thread-2, initial daemon)>
2021-05-25T09:02:25.290 gnupg              DD [] chunk: b'gpg (GnuPG) 2.2.12\nlibgcrypt 1.8.4\nCopyright (C) 2018 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to '
2021-05-25T09:02:25.290 gnupg              DD [] gpg: WARNING: unsafe permissions on homedir '/var/gpghome'
2021-05-25T09:02:25.292 gnupg              DD [] 10: gpg --status-fd 2 --no-tty --no-verbose --fixed-list-mode --batch --with-colons --homedir /var/gpghome --decrypt --output /local_backups/restore-2021-05-25T09:02:25.tar
2021-05-25T09:02:25.292 gnupg              DD [] data copier: <Thread(Thread-3, initial daemon)>, 'foobar.txt', <_io.BufferedWriter name=5>
Exception in thread Thread-3:
2021-05-25T09:02:25.292 gnupg              DD [] stderr reader: <Thread(Thread-4, initial daemon)>
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner
2021-05-25T09:02:25.293 gnupg              DD [] stdout reader: <Thread(Thread-5, initial daemon)>
    self.run()
  File "/usr/local/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/root/.local/lib/python3.9/site-packages/gnupg.py", line 147, in _copy_data
    data = instream.read(1024)
AttributeError: 'str' object has no attribute 'read'
2021-05-25T09:02:25.294 gnupg              DD [] gpg: WARNING: unsafe permissions on homedir '/var/gpghome'

Versions:

Python 3.9.5

Python-gnupg 0.4.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtrivial

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions