From 5303ca008e760e4e4707c0816449fb83f278426b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 29 Nov 2022 17:54:12 +0100 Subject: Matrix: set filesize limit to int64 and remove 300mb limit for non-image files --- src/plugins/Matrix.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/plugins') 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; } -- cgit v1.2.3