Skip to content
Snippets Groups Projects
Verified Commit 81d45ffa authored by Volkor Barbarian Warrior's avatar Volkor Barbarian Warrior
Browse files

FIX: crashing on files smaller than 2048 bytes

parent 8c4cebfe
No related branches found
No related tags found
No related merge requests found
...@@ -51,13 +51,15 @@ pub async fn upload(req: &mut Request, res: &mut Response) { ...@@ -51,13 +51,15 @@ pub async fn upload(req: &mut Request, res: &mut Response) {
engine::generate_filename(length, file.name().unwrap_or("file").to_string()).await; engine::generate_filename(length, file.name().unwrap_or("file").to_string()).await;
// Get the temporary file // Get the temporary file
let mut mime_file = File::open(file.path()).expect("Error opening file"); let mime_file = File::open(file.path()).expect("Error opening file");
let mut buffer = vec![0; 2048]; let mut buffer = Vec::with_capacity(2048);
// Load up 2048 bytes (There wasn't a decent answer on how much or little I should read) // Load up 2048 bytes (There wasn't a decent answer on how much or little I should read)
mime_file mime_file.take(2048)
.read_exact(&mut buffer) .read_to_end(&mut buffer).expect("couldn't read mimetype buffer");
.expect("Error reading file");
tracing::trace!("read bytes for mime parsing: {:x?}", buffer);
// Guess the mimetype // Guess the mimetype
let mimetype: &str = &detect_mime_type(&buffer).unwrap_or("text/plain".to_string()); let mimetype: &str = &detect_mime_type(&buffer).unwrap_or("text/plain".to_string());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment