bricke / Qt-AES

Native Qt AES encryption class
The Unlicense
501 stars 187 forks source link

suggest to add more check to decode() method paremeters #57

Closed xikuibin closed 11 months ago

xikuibin commented 1 year ago

If the size of encoded data is wrong, the decode() will cause heap corruption. So suggest that decode() should verify the length of input rrawText. It the lenght is not mutiple of 16 bytes(AES block), return an empty buffer.

Example code:

    QByteArray encodedText("123456");    // wrong length
                                                                 // QByteArray encodedText("1234561234561234"); does not cause failure.
    QByteArray hashKey = QCryptographicHash::hash(seed, QCryptographicHash::Sha256);
    QByteArray decoded = QAESEncryption::Decrypt(QAESEncryption::AES_128, QAESEncryption::ECB, encodedText, hashKey);
    QByteArry res = QAESEncryption::RemovePadding(decoded);

This will cause

HEAP CORRUPTION DETECTED: after Normal block (#42796) at 0x0000023DF89F0770.
CRT detected that the application wrote to memory after end of heap buffer.