qt, cpp: Support larger size-hint on 32 bit builds

* NEWS: Mention this.
* lang/cpp/src/data.h, lang/cpp/src/data.cpp (Data::setSizeHint): New.
* lang/qt/src/qgpgmedecryptjob.cpp,
 lang/qt/src/qgpgmedecryptverifyarchivejob.cpp,
 lang/qt/src/qgpgmedecryptverifyjob.cpp,
 lang/qt/src/qgpgmeencryptjob.cpp,
 lang/qt/src/qgpgmesignencryptjob.cpp,
 lang/qt/src/qgpgmesignjob.cpp,
 lang/qt/src/qgpgmeverifydetachedjob.cpp,
 lang/qt/src/qgpgmeverifyopaquejob.cpp: Set size for input IODevice.

--
This fixes the case where the old detection of the size of QIOdevice
using seek would overflow and instead explicitly uses QIODevice::size
to check for the size and pass it through as an uint64.

GnuPG-Bug-Id: T6534
This commit is contained in:
Andre Heinecke 2023-06-16 14:33:19 +02:00
parent cbcea4a09b
commit 5811d069d3
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C
11 changed files with 43 additions and 4 deletions

5
NEWS
View File

@ -1,12 +1,17 @@
Noteworthy changes in version 1.21.0 (unreleased)
-------------------------------------------------
* Qt Jobs working with QIODeviceDataProvider now properly
handle input-size hints and progress for files larger.
2^32 bytes in 32 bit builds. [T6534]
* Error::isCanceled now also returns true for error code
GPG_ERR_FULLY_CANCELED. [T6510]
* Interface changes relative to the 1.20.0 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cpp: Data::setFlag NEW.
cpp: Data::setSizeHint NEW.
Noteworthy changes in version 1.20.0 (2023-04-20)
-------------------------------------------------

View File

@ -285,3 +285,9 @@ GpgME::Error GpgME::Data::setFlag(const char *name, const char *value)
{
return Error(gpgme_data_set_flag(d->data, name, value));
}
GpgME::Error GpgME::Data::setSizeHint(uint64_t size)
{
const std::string val = std::to_string(size);
return Error(gpgme_data_set_flag(d->data, "size-hint", val.c_str()));
}

View File

@ -27,6 +27,7 @@
#include "key.h"
#include <sys/types.h> // for size_t, off_t
#include <cstdint> // unit64_t
#include <cstdio> // FILE
#include <algorithm>
#include <memory>
@ -125,6 +126,9 @@ public:
/** See gpgme_data_set_flag */
Error setFlag(const char *name, const char *value);
/** Set a size hint for this data e.g. for progress calculations. */
Error setSizeHint(uint64_t size);
class Private;
Private *impl()
{

View File

@ -71,7 +71,10 @@ static QGpgMEDecryptJob::result_type decrypt(Context *ctx, QThread *thread,
const _detail::ToThreadMover ptMover(plainText, thread);
QGpgME::QIODeviceDataProvider in(cipherText);
const Data indata(&in);
Data indata(&in);
if (!cipherText->isSequential()) {
indata.setSizeHint(cipherText->size());
}
if (!plainText) {
QGpgME::QByteArrayDataProvider out;

View File

@ -92,6 +92,9 @@ static QGpgMEDecryptVerifyArchiveJob::result_type decrypt_verify(Context *ctx,
QGpgME::QIODeviceDataProvider in{cipherText};
Data indata(&in);
if (!cipherText->isSequential()) {
indata.setSizeHint(cipherText->size());
}
Data outdata;
if (!outputDirectory.isEmpty()) {

View File

@ -76,7 +76,10 @@ static QGpgMEDecryptVerifyJob::result_type decrypt_verify(Context *ctx, QThread
const _detail::ToThreadMover ptMover(plainText, thread);
QGpgME::QIODeviceDataProvider in(cipherText);
const Data indata(&in);
Data indata(&in);
if (!cipherText->isSequential()) {
indata.setSizeHint(cipherText->size());
}
if (!plainText) {
QGpgME::QByteArrayDataProvider out;

View File

@ -112,6 +112,9 @@ static QGpgMEEncryptJob::result_type encrypt(Context *ctx, QThread *thread,
QGpgME::QIODeviceDataProvider in(plainText);
Data indata(&in);
if (!plainText->isSequential()) {
indata.setSizeHint(plainText->size());
}
const auto pureFileName = QFileInfo{fileName}.fileName().toStdString();
if (!pureFileName.empty()) {

View File

@ -108,6 +108,9 @@ static QGpgMESignEncryptJob::result_type sign_encrypt(Context *ctx, QThread *thr
QGpgME::QIODeviceDataProvider in(plainText);
Data indata(&in);
if (!plainText->isSequential()) {
indata.setSizeHint(plainText->size());
}
const auto pureFileName = QFileInfo{fileName}.fileName().toStdString();
if (!pureFileName.empty()) {

View File

@ -81,7 +81,10 @@ static QGpgMESignJob::result_type sign(Context *ctx, QThread *thread,
const _detail::ToThreadMover sgMover(signature, thread);
QGpgME::QIODeviceDataProvider in(plainText);
const Data indata(&in);
Data indata(&in);
if (!plainText->isSequential()) {
indata.setSizeHint(plainText->size());
}
ctx->clearSigningKeys();
Q_FOREACH (const Key &signer, signers)

View File

@ -71,6 +71,9 @@ static QGpgMEVerifyDetachedJob::result_type verify_detached(Context *ctx, QThrea
QGpgME::QIODeviceDataProvider dataDP(signedData);
Data data(&dataDP);
if (!signedData->isSequential()) {
data.setSizeHint(signedData->size());
}
const VerificationResult res = ctx->verifyDetachedSignature(sig, data);
Error ae;

View File

@ -70,7 +70,10 @@ static QGpgMEVerifyOpaqueJob::result_type verify_opaque(Context *ctx, QThread *t
const _detail::ToThreadMover sdMover(signedData, thread);
QGpgME::QIODeviceDataProvider in(signedData);
const Data indata(&in);
Data indata(&in);
if (!signedData->isSequential()) {
indata.setSizeHint(signedData->size());
}
if (!plainText) {
QGpgME::QByteArrayDataProvider out;