I have a custom QIODevice that decrypts the data stream from another QIODevice (it might be a file). It is used it to encrypt and decrypt files. Some of the files are images. Then QImageReader is used to load the image directly from the encryption stream, but in some rare cases QImageReader fails to read the image from that stream. There is one PNG image that can be properly read by QImageReader from unencrypted file. But when my custom QIODevice is layered over QFile and passed to QImageReader, it would fail and prints

"libpng error: IDAT: CRC error"

I've done some intensive debugging and traced all the reads and seeks that QImageReader would invoke on my QIODevice, and put them along with these of QFile of unencrypted file:

Qt Code:
  1. device.read(encData, 2 );
  2. file.read(pngData, 2 );
  3. Q_ASSERT(memcmp(encData, pngData, 2) == 0);
  4. device.read(encData, 6 );
  5. file.read(pngData, 6 );
  6. Q_ASSERT(memcmp(encData, pngData, 6) == 0);
  7. device.seek(0 );
  8. file.seek(0 );
  9. ....
To copy to clipboard, switch view to plain text mode 

And it turned out that all the data read from a file is exactly the same as the data coming from the stream...

why it would return that libpng error?