diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-11-29 17:54:12 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-11-29 17:54:12 +0100 |
commit | 5303ca008e760e4e4707c0816449fb83f278426b (patch) | |
tree | d42e4d2fdcfc55e3ff2ad7135dba7b9ba2078e1b /src | |
parent | 94152da2ef18a673a996e3d5cfb3780a8f5f7feb (diff) |
Matrix: set filesize limit to int64 and remove 300mb limit for non-image files
Diffstat (limited to 'src')
-rw-r--r-- | src/FileAnalyzer.cpp | 6 | ||||
-rw-r--r-- | src/Storage.cpp | 4 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 22 |
3 files changed, 16 insertions, 16 deletions
diff --git a/src/FileAnalyzer.cpp b/src/FileAnalyzer.cpp index 65c33b5..361211f 100644 --- a/src/FileAnalyzer.cpp +++ b/src/FileAnalyzer.cpp @@ -240,9 +240,9 @@ namespace QuickMedia { dimensions = std::nullopt; duration_seconds = std::nullopt; - struct stat stat; + struct stat64 stat; memset(&stat, 0, sizeof(stat)); - if(fstat(fileno(file), &stat) == -1) { + if(fstat64(fileno(file), &stat) == -1) { perror(filepath); fclose(file); return false; @@ -315,7 +315,7 @@ namespace QuickMedia { return content_type; } - size_t FileAnalyzer::get_file_size() const { + int64_t FileAnalyzer::get_file_size() const { return file_size; } diff --git a/src/Storage.cpp b/src/Storage.cpp index 7554b73..c09e23b 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -191,10 +191,10 @@ namespace QuickMedia { } int file_get_size(const Path &path, int64_t *size) { - struct stat file_stat; + struct stat64 file_stat; memset(&file_stat, 0, sizeof(file_stat)); int ret; - EINTR_RETRY(ret, stat(path.data.c_str(), &file_stat)); + EINTR_RETRY(ret, stat64(path.data.c_str(), &file_stat)); if(ret == 0 && S_ISREG(file_stat.st_mode)) { *size = file_stat.st_size; return 0; diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 6040edd..38ab6d0 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -4870,20 +4870,14 @@ namespace QuickMedia { if(filename.empty()) filename = file_get_filename(filepath); - int upload_limit; + int64_t upload_limit; PluginResult config_result = get_config(&upload_limit); if(config_result != PluginResult::OK) { err_msg = "Failed to get file size limit from server"; return config_result; } - // Checking for sane file size limit client side, to prevent loading a huge file and crashing - if(file_analyzer.get_file_size() > 300 * 1024 * 1024) { // 300mb - err_msg = "File is too large! client-side limit is set to 300mb"; - return PluginResult::ERR; - } - - if((int)file_analyzer.get_file_size() > upload_limit) { + if(file_analyzer.get_file_size() > upload_limit) { err_msg = "File is too large! max upload size on your homeserver is " + std::to_string((double)upload_limit / 1024.0 / 1024.0) + " mb, the file you tried to upload is " + std::to_string((double)file_analyzer.get_file_size() / 1024.0 / 1024.0) + " mb"; return PluginResult::ERR; } @@ -4912,6 +4906,12 @@ namespace QuickMedia { fprintf(stderr, "Failed to create temporary file for video thumbnail, ignoring thumbnail...\n"); } } else if(upload_thumbnail && is_content_type_image(file_analyzer.get_content_type())) { + // Checking for sane file size limit client side, to prevent loading a huge file and crashing + if(file_analyzer.get_file_size() > 300 * 1024 * 1024) { // 300mb + err_msg = "File is too large! client-side limit for images is set to 300mb"; + return PluginResult::ERR; + } + char tmp_filename[] = "/tmp/quickmedia_thumbnail_XXXXXX"; int tmp_file = mkstemp(tmp_filename); if(tmp_file != -1) { @@ -5758,7 +5758,7 @@ namespace QuickMedia { return message->user->room->get_user_display_name(message->user); } - PluginResult Matrix::get_config(int *upload_size) { + PluginResult Matrix::get_config(int64_t *upload_size) { // TODO: What if the upload limit changes? is it possible for the upload limit to change while the server is running? if(upload_limit) { *upload_size = upload_limit.value(); @@ -5782,10 +5782,10 @@ namespace QuickMedia { return PluginResult::ERR; const rapidjson::Value &upload_size_json = GetMember(json_root, "m.upload.size"); - if(!upload_size_json.IsInt()) + if(!upload_size_json.IsInt64()) return PluginResult::ERR; - upload_limit = upload_size_json.GetInt(); + upload_limit = upload_size_json.GetInt64(); *upload_size = upload_limit.value(); return PluginResult::OK; } |