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: Invalid reads for requests that contain multi-byte characters #661

Merged
merged 3 commits into from
Mar 27, 2024

Conversation

scohen
Copy link
Collaborator

@scohen scohen commented Mar 25, 2024

We would get sporadic failures where the transport would keep reading headers after they were done. This was due to the previous request containing unicode characters at specific locations, which would confuse the transport, since it was reading the body of the request with IO.read, which reads characters, but it was passing in the content-length, which is counted in bytes. This would cause us to over-read the body, and consume part of the next body as we were reading the headers, and then the whole thing would fail when we tried to parse the headers.

The change is simple, switch to binread, which takes the number of bytes to read.

We would get sporadic failures where the transport would keep reading
headers after they were done. This was due to the previous request
containing unicode characters at specific locations, which would
confuse the transport, since it was reading the body of the request
with IO.read, which reads _characters_, but it was passing in the
content-length, which is counted in bytes. This would cause us to
over-read the body, and consume part of the next body as we were
reading the headers, and then the whole thing would fail when we tried
to parse the headers.

The change is simple, switch to `binread`, which takes the number of
bytes to read.
@scohen scohen requested review from scottming and Moosieus March 25, 2024 21:32
@scohen scohen changed the title FIX: Invalid reads for unicode requests FIX: Invalid reads for requests that contain multi-byte characters Mar 25, 2024
@scohen scohen force-pushed the fix-stdio-read-bytes branch from 884d74b to dc0681e Compare March 26, 2024 00:04
@Moosieus
Copy link
Collaborator

Looks good aside from the Dialyzer complaining about no return. Is there a good reason for using System.halt/0 over its more graceful System.stop/0 counterpart?

@scohen scohen requested a review from Moosieus March 26, 2024 16:33
@scohen
Copy link
Collaborator Author

scohen commented Mar 26, 2024

Is there a good reason for using System.halt/0 over its more graceful System.stop/0 counterpart?

Nope, changed it.

@scohen scohen merged commit f6ca36f into main Mar 27, 2024
9 checks passed
@scohen scohen deleted the fix-stdio-read-bytes branch March 27, 2024 05:25
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.

2 participants