From 315a649777274d5ae1c67f4b49b7dba869a1a8f8 Mon Sep 17 00:00:00 2001 From: orhun Date: Wed, 28 Jul 2021 00:25:18 +0300 Subject: [PATCH] fix(upload): prevent sending zero bytes --- src/server.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/server.rs b/src/server.rs index a2dceee..b980cb2 100644 --- a/src/server.rs +++ b/src/server.rs @@ -56,6 +56,10 @@ async fn upload( return Err(error::ErrorPayloadTooLarge("upload limit exceeded")); } } + if bytes.is_empty() { + log::warn!("{} sent zero bytes", host); + return Err(error::ErrorBadRequest("invalid file size")); + } let bytes_unit = Byte::from_bytes(bytes.len() as u128).get_appropriate_unit(false); let file_name = &file::save(content.get_file_name()?, &bytes, &config)?; log::info!("{} ({}) is uploaded from {}", file_name, bytes_unit, host);