New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra Newline Added to Binary File Upload #2761
Comments
mohamedlmoutaouakil
pushed a commit
to mohamedlmoutaouakil/werkzeug
that referenced
this issue
Aug 10, 2023
mohamedlmoutaouakil
pushed a commit
to mohamedlmoutaouakil/werkzeug
that referenced
this issue
Aug 11, 2023
mohamedlmoutaouakil
pushed a commit
to mohamedlmoutaouakil/werkzeug
that referenced
this issue
Aug 11, 2023
mohamedlmoutaouakil
pushed a commit
to mohamedlmoutaouakil/werkzeug
that referenced
this issue
Aug 11, 2023
6 tasks
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
pgjones
pushed a commit
to pgjones/werkzeug
that referenced
this issue
Aug 12, 2023
6 tasks
pgjones
pushed a commit
that referenced
this issue
Aug 12, 2023
Closed by #2763 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Problem:
After uploading a specific binary file, an unexpected newline character (\n) is being added to the beginning of the file. This behavior is traced back to Werkzeug's multipart request body parsing during POST requests.
Steps to Reproduce:
Root Cause:
This issue arises due to Werkzeug's _parse_data method. Specifically, when a newline (\n or \r) is present at the second position (index 1) of the file's content and no additional newlines are within the first 64KB of the request body, an extra newline is inadvertently introduced during parsing.
Code Flow:
Solution:
To resolve this, a correction in the _parse_data method is needed. The index returned by last_newline should be adjusted by adding the data_start before slicing data.
Proposed Fix:
Update _parse_data as follows:
Environment:
Python: 3.10.12
Werkzeug: 2.3.6
Resolution:
A pull request will be created to implement this fix, preventing unintended newline addition in binary file uploads. This adjustment ensures proper index handling, preventing unintended manipulation of file content during parsing.
The text was updated successfully, but these errors were encountered: