From d85cce8264361fa2d2ff3836c76d9d04f4aeccc7 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Sun, 27 Mar 2022 14:29:11 +0200 Subject: [PATCH] Prevent empty archive extraction --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 17fddb1..2957ae1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use actix_files::{Files, NamedFile}; use actix_multipart::Multipart; use actix_web::{App, Error, HttpRequest, HttpResponse, HttpServer, web}; use actix_web::dev::{fn_service, ServiceRequest, ServiceResponse}; -use actix_web::error::{ErrorInternalServerError, ErrorUnauthorized}; +use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorUnauthorized}; use actix_web::middleware::Logger; use bytes::BufMut; use clap::Parser; @@ -178,6 +178,11 @@ async fn replace_files(args: web::Data, req: HttpRequest, mut payload: Mul } } + // Check if at least a file was sent + if new_files.is_empty() { + return Err(ErrorBadRequest("No file to extract!")); + } + // Delete all current files in storage for entry in std::fs::read_dir(args.storage_path())? { let entry = entry?;