[Interest] It's time again to play Find-That-Bug

Bill Crocker william.crocker at analog.com
Fri Sep 13 13:19:45 CEST 2013


Hello:

It's time again to play Find-That-Bug:

I just spent several days tracking down a bug in the following code.
It was difficult to find because it is a reduced probability,
data-specific event; It can be completely function,
completely dysfunctional, and all shades in between.

I am using Qt 4.7.1
Let's assume all of the input strings are ASCII.

Can you find it?

     QString
     MakeDigest( QStringList list ) {
         QCryptographicHash ch(QCryptographicHash::Md5);
         foreach( QString s, list )
             ch.addData( s.toAscii() );
         return ch.result();
     }

----------------------------

Scroll down if you need a hint.


























If you need a hint, run this code:

     for( int i=60; i<70; i++ ) {
         QStringList list; list << QString::number(i) << QString::number(i);
         QString d = MakeDigest(list);
         qDebug() << "digest size: " << i << ' ' << 8 * d.size();
     }

------------------------------------

If you need another hint, see the description of this:

     QString::QString ( const QByteArray &ba )

I take issue with the behavior of this constructor
because we know the length of ba and QStrings can contain QChar('\0').

While there is probably a good reason for the behavior,
I did not see it coming.

I tend to use QStrings over QByteArrays as QStrings
provide more operations.




More information about the Interest mailing list