Skip to content
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

Fix header FSM in webserver, fix Windows uploads #7805

Merged
merged 1 commit into from
Jan 1, 2021

Conversation

earlephilhower
Copy link
Collaborator

When a file upload ends in \r\n (i.e. a Windows formatted text file) the
sequence of bytes on the wire is \r\n\r\n----...boundary-marker....

When the FSM in Webserver was evaluating the stream, that 2nd \r would
be written as valid data and the FSM parser would be reset and see \n
as the 1st character, which wouldn't match. This would a) add an extra
\r to uploaded files, and b) cause uploads to hang.

Fix by checking on a header FSM mismatch if the next character input
could possibly match our marker, and if so handle it properly.

Fixes #7803

When a file upload ends in \r\n (i.e. a Windows formatted text file) the
sequence of bytes on the wire is `\r\n\r\n----...boundary-marker...`.

When the FSM in Webserver was evaluating the stream, that 2nd `\r` would
be written as valid data and the FSM parser would be reset and see `\n`
as the 1st character, which wouldn't match.  This would a) add an extra
`\r` to uploaded files, and b) cause uploads to hang.

Fix by checking on a header FSM mismatch if the next character input
could possibly match our marker, and if so handle it properly.

Fixes esp8266#7803
@earlephilhower
Copy link
Collaborator Author

@luc-github can you please try this and report back?

@luc-github
Copy link
Contributor

luc-github commented Jan 1, 2021

I have just tested and issue is solved - thank you

C:\Users\luc\Desktop\webserver>curl -v -L -F "file=@gpl.txt" http://192.168.1.75/upload
*   Trying 192.168.1.75...
* TCP_NODELAY set
* Connected to 192.168.1.75 (192.168.1.75) port 80 (#0)
> POST /upload HTTP/1.1
> Host: 192.168.1.75
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Length: 36006
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------4738aa4a9bc8107f
>
* Done waiting for 100-continue
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Content-Length: 9
< Connection: keep-alive
< Keep-Alive: timeout=2000
<
ok boomer* Connection #0 to host 192.168.1.75 left intact
Connecting to WIFI_OFFICE_B2G
.......
Connected! IP address: 192.168.1.75
HTTP server started
Starting upload
Filename gpl.txt
..................
Ending upload

@earlephilhower earlephilhower merged commit da13845 into esp8266:master Jan 1, 2021
@earlephilhower earlephilhower deleted the winlf branch January 1, 2021 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebServer upload is stuck with latest git but ok in 2.7.4 and previous
2 participants