Fail fast on photos bigger than 10 MB.

GitOrigin-RevId: 4f4cfd5415c3e9a851fd7d580ecfa11b3d7c6046
This commit is contained in:
levlam 2019-01-07 20:41:05 +03:00
parent d61f44ac35
commit 8e402b8a48
3 changed files with 12 additions and 7 deletions

View File

@ -30,7 +30,7 @@ class SHA1Bench : public td::Benchmark {
alignas(64) unsigned char data[DATA_SIZE];
std::string get_description() const override {
return PSTRING() << "SHA1 OpenSSL [" << (DATA_SIZE >> 10) << "KB]";
return PSTRING() << "SHA1 OpenSSL [" << (DATA_SIZE >> 10) << "kB]";
}
void start_up() override {
@ -55,7 +55,7 @@ class AESBench : public td::Benchmark {
td::UInt256 iv;
std::string get_description() const override {
return PSTRING() << "AES OpenSSL [" << (DATA_SIZE >> 10) << "KB]";
return PSTRING() << "AES OpenSSL [" << (DATA_SIZE >> 10) << "kB]";
}
void start_up() override {
@ -152,7 +152,7 @@ class Crc32Bench : public td::Benchmark {
alignas(64) unsigned char data[DATA_SIZE];
std::string get_description() const override {
return PSTRING() << "Crc32 zlib [" << (DATA_SIZE >> 10) << "KB]";
return PSTRING() << "Crc32 zlib [" << (DATA_SIZE >> 10) << "kB]";
}
void start_up() override {
@ -176,7 +176,7 @@ class Crc64Bench : public td::Benchmark {
alignas(64) unsigned char data[DATA_SIZE];
std::string get_description() const override {
return PSTRING() << "Crc64 Anton [" << (DATA_SIZE >> 10) << "KB]";
return PSTRING() << "Crc64 Anton [" << (DATA_SIZE >> 10) << "kB]";
}
void start_up() override {

View File

@ -624,7 +624,8 @@ string FileManager::get_file_name(FileType file_type, Slice path) {
}
Status FileManager::check_local_location(FullLocalFileLocation &location, int64 &size) {
constexpr int64 MAX_THUMBNAIL_SIZE = 200 * (1 << 10) /* 200KB */;
constexpr int64 MAX_THUMBNAIL_SIZE = 200 * (1 << 10) /* 200 kB */;
constexpr int64 MAX_PHOTO_SIZE = 10 * (1 << 20) /* 10 MB */;
if (location.path_.empty()) {
return Status::Error("File must have non-empty path");
@ -659,7 +660,11 @@ Status FileManager::check_local_location(FullLocalFileLocation &location, int64
}
if ((location.file_type_ == FileType::Thumbnail || location.file_type_ == FileType::EncryptedThumbnail) &&
size >= MAX_THUMBNAIL_SIZE && !begins_with(PathView(location.path_).file_name(), "map")) {
return Status::Error(PSLICE() << "File \"" << location.path_ << "\" is too big for thumbnail "
return Status::Error(PSLICE() << "File \"" << location.path_ << "\" is too big for a thumbnail "
<< tag("size", format::as_size(size)));
}
if (location.file_type_ == FileType::Photo && size >= MAX_PHOTO_SIZE) {
return Status::Error(PSLICE() << "File \"" << location.path_ << "\" is too big for a photo "
<< tag("size", format::as_size(size)));
}
if (size >= MAX_FILE_SIZE) {

View File

@ -192,7 +192,7 @@ inline StringBuilder &operator<<(StringBuilder &logger, Size t) {
uint64 value;
};
static constexpr NamedValue sizes[] = {{"B", 1}, {"KB", 1 << 10}, {"MB", 1 << 20}, {"GB", 1 << 30}};
static constexpr NamedValue sizes[] = {{"B", 1}, {"kB", 1 << 10}, {"MB", 1 << 20}, {"GB", 1 << 30}};
static constexpr size_t sizes_n = sizeof(sizes) / sizeof(NamedValue);
size_t i = 0;