Make checked read of sticker sets order.

In case local data is corrupted previously it lead to OOM crash.
This commit is contained in:
John Preston 2020-03-13 12:07:05 +04:00
parent 07eab8555a
commit 6bf3dd10c1

View file

@ -3673,7 +3673,23 @@ void _readStickerSets(FileKey &stickersKey, Stickers::Order *outOrder = nullptr,
// Read orders of installed and featured stickers.
if (outOrder) {
stickers.stream >> *outOrder;
auto outOrderCount = quint32();
stickers.stream >> outOrderCount;
if (!_checkStreamStatus(stickers.stream)
|| outOrderCount < 0
|| outOrderCount > 1000) {
return failed();
}
outOrder->reserve(outOrderCount);
for (auto i = 0; i != outOrderCount; ++i) {
auto value = uint64();
stickers.stream >> value;
if (!_checkStreamStatus(stickers.stream)) {
outOrder->clear();
return failed();
}
outOrder->push_back(value);
}
}
if (!_checkStreamStatus(stickers.stream)) {
return failed();