Skip to content

Commit

Permalink
Explicitly strip newlines from chunks when uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmark committed Oct 25, 2023
1 parent 43088ab commit ac6dd8e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions python/web/src/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
auth_active,
is_bridge_configured,
is_safe_path,
upload_with_dropzonejs,
upload_to_dir,
browser_supports_modern_themes,
)
from settings import (
Expand Down Expand Up @@ -1035,7 +1035,7 @@ def upload_file():
else:
return make_response(_("Unknown destination"), 403)

return upload_with_dropzonejs(destination_dir)
return upload_to_dir(destination_dir)


@APP.route("/files/create", methods=["POST"])
Expand Down
7 changes: 5 additions & 2 deletions python/web/src/web_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def is_safe_path(file_name):
return {"status": True, "msg": ""}


def upload_with_dropzonejs(image_dir):
def upload_to_dir(image_dir):
"""
Takes (str) image_dir which is the path to the image dir to store files.
Opens a stream to transfer a file via the embedded dropzonejs library.
Expand All @@ -345,7 +345,10 @@ def upload_with_dropzonejs(image_dir):
try:
with open(save_path, "ab") as save:
save.seek(int(request.form["dzchunkbyteoffset"]))
save.write(file_object.stream.read())
chunk = file_object.stream.read()
# Remove CRLF characters from the end of the chunk
chunk = chunk.rstrip(b"\r\n")
save.write(chunk)
except OSError:
log.exception("Could not write to file")
return make_response(_("Unable to write the file to disk!"), 500)
Expand Down

0 comments on commit ac6dd8e

Please sign in to comment.