fix(upload): prevent sending zero bytes

This commit is contained in:
orhun 2021-07-28 00:25:18 +03:00
parent f4a3c07def
commit 315a649777
No known key found for this signature in database
GPG key ID: F83424824B3E4B90

View file

@ -56,6 +56,10 @@ async fn upload(
return Err(error::ErrorPayloadTooLarge("upload limit exceeded")); 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 bytes_unit = Byte::from_bytes(bytes.len() as u128).get_appropriate_unit(false);
let file_name = &file::save(content.get_file_name()?, &bytes, &config)?; let file_name = &file::save(content.get_file_name()?, &bytes, &config)?;
log::info!("{} ({}) is uploaded from {}", file_name, bytes_unit, host); log::info!("{} ({}) is uploaded from {}", file_name, bytes_unit, host);