after calling
>
> aesEncryptFileOpen(QString inFile, QString outFile);
>
> aesEncryptFilePump()
>
> is called, to start it then the GUI keeps pumping. I don't know why the
> MeterFilter should _ever_ crash? readLength is 65536.
>
>
Xcode has instruments. You should consider setting up a new Xcode
configuration within your project and enable the memory checking tools.
Also see
https://developer.apple.com/library/mac/recipes/xcode_help-scheme_editor/Articles/SchemeDiagnostics.html
> void Hash::aesEncryptFileOpen(QString inFile, QString outFile) {
>>
>> inFilename = inFile;
>>
>> outFilename = outFile;
>>
>>
>> QString ivHex = hashFile(inFilename, false).mid(0,32);
>>
>> QByteArray binIv = QByteArray::fromHex(ivHex.toUtf8());
>>
>> char inFilename_[256];
>>
>> char outFilename_[256];
>>
>> memset(inFilename_, 0, sizeof(inFilename_));
>>
>> memset(outFilename_, 0, sizeof(outFilename_));
>>
>>
>> strncpy(inFilename_, inFilename.toLocal8Bit().constData(),
>> inFilename.toLocal8Bit().length());
>>
>> strncpy(outFilename_, outFilename.toLocal8Bit().constData(),
>> outFilename.toLocal8Bit().length());
>>
>>
It looks like a potential memory error here. Filenames can get quite long
on iOS. They include a ASCII representation of a UUID and the sandbox
directories. strncpy may be getting you in trouble because its a breeding
ground for buffer overflows and useless return values. Also see
http://linux.die.net/man/3/strncpy.
Consider switching to snprintf. snprintf takes a length as a second arg. It
also backfills with 0, so the memset is not needed. Finally, it does not
NULL terminate if it runs out of space, but it does allow you to test for
success/failure. Maybe something like:
int rc = snprintf(inFilename, COUNTOF(inFilename), ...);
if( rc < 0 || rc >= COUNTOF(inFilename))
/* Failure, Truncation or no NULL terminator */
iOS also provides the BSD safer string gear. You might consider using it if
you can't use C++. In the case of strncpy, you would use strlcpy. See the
Apple Secure Programming Guide for details. (It used be be download-able
from Apple's site, but I can't find it at the moment).
> _fileSource = new CryptoPP::FileSource(inFilename_, false);
>>
>> _fileSink = new CryptoPP::FileSink(outFilename_);
>>
>> _meterFilter= new CryptoPP::MeterFilter();
>>
>> CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption e((const byte
>> *)_key.constData(), _key.length(), (const byte *)binIv.constData(), 1);
>>
>> _stf = new CryptoPP::StreamTransformationFilter(e);
>>
>>
>> if (_base64Output)
>>
>> _base64Encoder = new CryptoPP::Base64Encoder();
>>
>> else
>>
>> _base64Encoder = NULL;
>>
>>
>> _fileSource->Attach(_meterFilter);
>>
>> _meterFilter->Attach(_stf);
>>
>> if (_base64Encoder) {
>>
>> _stf->Attach(_base64Encoder);
>>
>> _base64Encoder->Attach(_fileSink);
>>
>> } else {
>>
>> _stf->Attach(_fileSink);
>>
>> }
>>
>> QFileInfo fi (inFilename);
>>
>> totalBytesToEncrypt = fi.size();
>>
>> bytesEncrypted = 0;
>>
>>
>> }
>>
>>
It looks like the FileSource is leaked. It needs to be deleted eventually.
>
>> void Hash::aesEncryptFilePump() {
>>
>> qlonglong readLength = qMin(_blockSize, totalBytesToEncrypt -
>> bytesEncrypted);
>>
>> bytesEncrypted += readLength - _fileSource->Pump(readLength);
>>
>> if (_fileSource->SourceExhausted())
>>
>> {
>>
>> aesEncryptFileClose();
>>
>> emit aesEncryptFileComplete(inFilename);
>>
>> }
>>
>> }
>>
>>
You should probably call MessageEnd() on the StreamTransformationFilter.
Jeff
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.