Page MenuHome GnuPG

gpgme block when trying to encrypt
Open, HighPublic

Description

This happens quite rarely but when reencrypt 1000 emails, it will happens at least once and then block the whole process

When using QGpgME::EncryptJob with exec, I get the following backtrace (with start(), the job just never ends up calling finished)

#0  0x00007f3f08e87402 in __syscall_cancel_arch () from /lib64/libc.so.6
#1  0x00007f3f08e7b72a in __internal_syscall_cancel () from /lib64/libc.so.6
#2  0x00007f3f08e7b774 in __syscall_cancel () from /lib64/libc.so.6
#3  0x00007f3f08ef4a0e in poll () from /lib64/libc.so.6
#4  0x00007f3f09dc6d0f in _gpgme_io_select_poll (fds=0x7f3ee00039f0, nfds=10, nonblock=0) at /home/carl/kde6/src/gpgme/src/posix-io.c:761
#5  _gpgme_io_select (fds=0x7f3ee00039f0, nfds=10, nonblock=nonblock@entry=0) at /home/carl/kde6/src/gpgme/src/posix-io.c:928
#6  0x00007f3f09d9dd39 in _gpgme_wait_on_condition (ctx=ctx@entry=0x7f3e98c62eb0, cond=cond@entry=0x0, op_err_p=op_err_p@entry=0x0) at /home/carl/kde6/src/gpgme/src/wait-private.c:83
#7  0x00007f3f09d9df49 in _gpgme_wait_one (ctx=ctx@entry=0x7f3e98c62eb0) at /home/carl/kde6/src/gpgme/src/wait-private.c:166
#8  0x00007f3f09d9f134 in gpgme_op_encrypt_ext (ctx=0x7f3e98c62eb0, recp=0x3da43b0, recpstring=0x0, flags=GPGME_ENCRYPT_ADD_RECP, plain=0x390d980, cipher=0x390ea00) at /home/carl/kde6/src/gpgme/src/encrypt.c:336
#9  0x00007f3f09df7b27 in GpgME::Context::encrypt (this=this@entry=0x44cf490, recipients=std::vector of length 1, capacity 1 = {...}, plainText=..., cipherText=..., flags=flags@entry=GpgME::Context::AddRecipient)
    at /home/carl/kde6/src/gpgmepp/src/context.cpp:1391
#10 0x00007f3f09ece435 in encrypt (ctx=ctx@entry=0x44cf490, thread=thread@entry=0x0, recipients=std::vector of length 1, capacity 1 = {...}, plainText_=std::weak_ptr<QIODevice> (use count 3, weak count 1) = {...}, 
    cipherText_=std::weak_ptr<QIODevice> (empty) = {...}, eflags=GpgME::Context::AddRecipient, outputIsBsse64Encoded=false, inputEncoding=1296137311, fileName=Python Exception <class 'gdb.error'>: Invalid reinterpret_cast
) at /home/carl/kde6/src/gpgmeqt/src/qgpgmeencryptjob.cpp:137
#11 0x00007f3f09ecec01 in encrypt_qba (ctx=0x44cf490, recipients=std::vector of length 1, capacity 1 = {...}, plainText=Python Exception <class 'gdb.error'>: Invalid reinterpret_cast
, eflags=eflags@entry=GpgME::Context::AddRecipient, outputIsBsse64Encoded=<optimized out>, 
    inputEncoding=1296137311, fileName=Python Exception <class 'gdb.error'>: Invalid reinterpret_cast
) at /home/carl/kde6/src/gpgmeqt/src/qgpgmeencryptjob.cpp:164
#12 0x00007f3f09eced89 in QGpgME::QGpgMEEncryptJob::exec (this=0x3fdff80, recipients=std::vector of length 1, capacity 1 = {...}, plainText=Python Exception <class 'gdb.error'>: Invalid reinterpret_cast

Event Timeline

CarlSchwan created this task.

Interesing part of the logs:

gpg: public key decryption failed: Operation cancelled
gpg: modifiying the recipients is not possible decryption failed

the I get:

2025-06-13 11:40:26 gpgme[132506.207b6] _gpgme_io_select: check: poll on [ r=33 ]
2025-06-13 11:40:26 gpgme[132506.207b6] _gpgme_io_select: checkdecryption faileddecryption failed: poll OK [ r=0 ]
2025-06-13 11:40:26 gpgme[132506.207b6]         _gpgme_io_select: leave: result=1
2025-06-13 11:40:26 gpgme[132506.207b6]         _gpgme_run_io_cb: call: item=0x00007fd3bc000bd0 handler (0x00007fd3bc001d20, 33)
2025-06-13 11:40:26 gpgme[132506.207b6]         _gpgme_data_inbound_handler: enter: dh=0x00007fd3bc001d20 fd=33
2025-06-13 11:40:26 gpgme[132506.207b6]           _gpgme_io_read: enter: fd=33 buffer=0x00007fd3cb7fc510 count=4096
2025-06-13 11:40:26 gpgme[132506.207b6]           _gpgme_io_read: leave: result=0
2025-06-13 11:40:26 gpgme[132506.207b6]           _gpgme_io_close: enter: fd=33
2025-06-13 11:40:26 gpgme[132506.207b6]           _gpgme_io_close: check: invoking close handler 0x00007fd43decca90/0x00007fd3bc0044e0
2025-06-13 11:40:26 gpgme[132506.207b6]             _gpgme_remove_io_cb: call: data=0x00007fd3bc000bb0 setting fd 0x21 (item=0x00007fd3bc000bd0) done
2025-06-13 11:40:26 gpgme[132506.207b6]           _gpgme_io_close: leave: result=0
2025-06-13 11:40:26 gpgme[132506.207b6]         _gpgme_data_inbound_handler: leave: 
2025-06-13 11:40:26 gpgme[132506.207b6]         _gpgme_io_select: enter: nfds=10, nonblock=0

And afterward I get the following on repeat forever:

2025-06-13 11:40:26 gpgme[132506.207b6] _gpgme_io_select: check: poll on [ r=29 r=31 r=33 w=37 ]
2025-06-13 11:40:26 gpgme[132506.207b6] _gpgme_io_select: check: poll OK [ ]
2025-06-13 11:40:26 gpgme[132506.207b6]         _gpgme_io_select: leave: result=1
2025-06-13 11:40:26 gpgme[132506.207b6]         _gpgme_io_select: enter: nfds=10, nonblock=0

looks like the error is not correctly forwarded

Do you start other process while this context is in use? If you do a fork, you need to make sure that all file descriptors are closed. How is that done?

For each part that needs to be reencrypted I create a QGpgME Encrypt Job

auto job = QGpgME::openpgp()->encryptJob(true, true);
job->setEncryptionFlags(GpgME::Context::AddRecipient);
auto error = job->start(m_currentKeys, encryptedContent);

While we are reencrypting only one mail at the time, if a mail contains multiple encrypted parts two or more gpgme encrypt jobs are running at the same time but it should be in any case in the same process.

It seems to work much more reliably once I updated gnupg and libassuan to the laster version from master, so maybe the issue is already resolved. I need to test a bit more.