QcStreamLimits Namespace
Bounds for counts read from untrusted streams (network, save files), so corrupt input cannot trigger huge allocations. More...
| Header: | #include <common/protocol/QcStreamLimits.h> |
Variables
| const quint32 | maxDefinitions |
| const quint32 | maxTranslations |
Functions
| std::optional<QStringList> | readBoundedStrings(QDataStream &stream, quint32 maxCount, qsizetype maxLength) |
| std::optional<quint32> | readCount(QDataStream &stream, quint32 limit) |
Detailed Description
Strings and byte arrays are bounded by the frame size (QcProtocol::maxFrameBytes); QDataStream reads them incrementally, so an announced length beyond the frame fails without allocating it.
Variable Documentation
const quint32 QcStreamLimits::maxDefinitions
The bound of most counts of the content (definitions of one kind, the drops of a block, the translations of one file).
const quint32 QcStreamLimits::maxTranslations
Translations of all languages together (decision E-371). A short entry costs about 100 bytes of heap but only 16 bytes in a stream, so the frame size alone would let 2 million entries (200 MB per copy) through; the base game holds about 2,600.
Function Documentation
std::optional<QStringList> QcStreamLimits::readBoundedStrings(QDataStream &stream, quint32 maxCount, qsizetype maxLength)
Reads a list written as a QStringList (count, then the strings) from stream without trusting the count: QDataStream's own QStringList operator reserves whatever count the stream announces. Returns the list, or std::nullopt when the stream fails, the count is above maxCount or a string is longer than maxLength (the stream is then set to ReadCorruptData).
std::optional<quint32> QcStreamLimits::readCount(QDataStream &stream, quint32 limit)
Reads a quint32 count from stream and checks it against limit. Returns the count, or std::nullopt when the stream fails or the count is above the limit (the stream is then set to ReadCorruptData).