-
Notifications
You must be signed in to change notification settings - Fork 284
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
readUntilSmall may read over separator [critical] #1741
Comments
s-ludwig
added a commit
that referenced
this issue
May 14, 2017
Also fixes handling of the max_bytes parameter in the fast path.
s-ludwig
added a commit
that referenced
this issue
May 14, 2017
Also fixes handling of the max_bytes parameter in the fast path.
s-ludwig
added a commit
that referenced
this issue
May 14, 2017
Also fixes handling of the max_bytes parameter in the fast path.
s-ludwig
added a commit
that referenced
this issue
May 14, 2017
Also fixes handling of the max_bytes parameter in the fast path.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Under certain conditions readUntilSmall might read over an separator.
Here's a debug log, matching vibe.D
0.7.31
.Pasting the relevant code:
Considering this input string in the stream:
0\r\n
, separator\r\n
.In the first iteration there's never been a call to
read
orleastSize
(i.e. the blocking functions) so the internal buffer is empty,peek
returns[]
. Because of that the slow path is taken and callsread
.read
returns two bytes but internally fills the buffer with more data. Dst is set to"0"
and nmatched is1
as the\r
has been found.The loop continues in the next iteration. This time peek returns a cached buffer and the fast path is taken. The fast block now searches for
end_marker[0]
, even thoughnmatched == 1
and it should search forend_marker[nmatched]
.I reproduced this with a custom stream implementation, but I think this could happen for any stream.
I've switched to one-byte
\n
separators as a workaround, but this bug could be critical for other applications.The text was updated successfully, but these errors were encountered: