Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Ephemeral
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Volkor Barbarian Warrior
Ephemeral
Commits
81d45ffa
Verified
Commit
81d45ffa
authored
1 year ago
by
Volkor Barbarian Warrior
Browse files
Options
Downloads
Patches
Plain Diff
FIX: crashing on files smaller than 2048 bytes
parent
8c4cebfe
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/handlers/upload.rs
+7
-5
7 additions, 5 deletions
src/handlers/upload.rs
with
7 additions
and
5 deletions
src/handlers/upload.rs
+
7
−
5
View file @
81d45ffa
...
@@ -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
=
v
ec
!
[
0
;
2048
]
;
let
mut
buffer
=
V
ec
::
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
());
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment