Add PhotoSizeSource FileType checks.

GitOrigin-RevId: 92685f8d05de9543e381ba753e8fe66dbeee286e
This commit is contained in:
levlam 2019-06-20 04:53:50 +03:00
parent e6cc07a244
commit 8cf10f3fd3
2 changed files with 9 additions and 4 deletions

View File

@ -30,7 +30,13 @@ void store(const PhotoSizeSource::Thumbnail &source, StorerT &storer) {
template <class ParserT> template <class ParserT>
void parse(PhotoSizeSource::Thumbnail &source, ParserT &parser) { void parse(PhotoSizeSource::Thumbnail &source, ParserT &parser) {
parse(source.file_type, parser); int32 raw_type;
parse(raw_type, parser);
if (raw_type < 0 || raw_type >= static_cast<int32>(FileType::Size)) {
return parser.set_error("Wrong file type in PhotoSizeSource::Thumbnail");
}
source.file_type = static_cast<FileType>(raw_type);
parse(source.thumbnail_type, parser); parse(source.thumbnail_type, parser);
if (source.thumbnail_type < 0 || source.thumbnail_type > 255) { if (source.thumbnail_type < 0 || source.thumbnail_type > 255) {
parser.set_error("Wrong thumbnail type"); parser.set_error("Wrong thumbnail type");
@ -63,8 +69,7 @@ void parse(PhotoSizeSource::DialogPhoto &source, ParserT &parser) {
switch (source.dialog_id.get_type()) { switch (source.dialog_id.get_type()) {
case DialogType::SecretChat: case DialogType::SecretChat:
case DialogType::None: case DialogType::None:
parser.set_error("Invalid chat id"); return parser.set_error("Invalid chat id");
break;
default: default:
break; break;
} }

View File

@ -14,7 +14,7 @@
namespace td { namespace td {
enum class FileType : int8 { enum class FileType : int32 {
Thumbnail, Thumbnail,
ProfilePhoto, ProfilePhoto,
Photo, Photo,