I am creating a client server application in Qt.
I serialize and deserialize some structures using my own algorithm, however in order to deserialize them, I need to load the QByteArray
that contains the object into memory. In order to prevent some sort of hacker attacks that would cause the server go OOM, I set a fixed limit for a maximum size of the array that shouldn't, in normal situation be ever exceeded, so that if some "hacker" attempted to send for example array that contains 200GB of data, the server rejects it, instead of reading the data until it dies OOM.
Now the problem is that I implemented compression to the network protocol in order to speed it up. So I don't really know the size of uncompressed data, until I run qUncompress
on the byte array I received from client. I am not sure if it's technically possible, but I think that someone in theory, could craft data that are so easy to compress that even if compressed version has few kb, uncompressed version could have gigabytes.
Is it possible? If so, is there any way to prevent this? For example run qUncompress
in a way that it doesn't allow inflating over some specific size?