Repository navigation
Conversation
This was referenced Dec 3, 2026
Replace `KtlsStream`'s bare `Option<(usize, Vec<u8>)>` drained field with a private `DrainedBuf` type that maintains `pos < buf.len()` whenever a buffer is present. This fixes three cursor bugs together: - `poll_read` shadowed `drained` with `&drained[*drain_index..]` and compared `*drain_index >= drained.len()` against the remaining length, silently dropping tail bytes once partial reads passed the midpoint. - `KtlsStream::new` accepted `Some(Vec::new())`, causing the first `poll_read` to return a spurious 0-byte read instead of polling the inner stream (`into_raw().0` now returns `None` in this case). - `KtlsStream::into_raw` discarded `drain_index` and returned bytes that had already been read. Also drop the unnecessary `cx.waker().wake_by_ref()` on the drained path, which already returns `Poll::Ready(Ok(()))`.
ArniDagur
force-pushed
the
fix-drained-buf
branch
from
December 4, 2026 00:07
626a85c to
cae4e1e
Compare
ArniDagur
marked this pull request as ready for review
December 4, 2026 00:08
Contributor
Author
|
@cpu could you take a look? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces
KtlsStream's bareOption<(usize, Vec<u8>)>drained field with a privateDrainedBufthat enforcespos < buf.len()whenever a buffer is present.This structurally eliminates three cursor bugs:
poll_read:let drained = &drained[*drain_index..];shadowed theVec<u8>, so*drain_index >= drained.len()compared against the remaining length instead of the full length and silently dropped tail bytes once reads passed the midpoint.KtlsStream::new: passingSome(Vec::new())leftSome((0, vec![])), causing the firstpoll_readto returnPoll::Ready(Ok(()))with 0 bytes (a spurious EOF) instead of polling the inner stream. Note:KtlsStream::new(io, Some(Vec::new())).into_raw().0now returnsNoneinstead ofSome(vec![]), matchingdrain().KtlsStream::into_raw:drain_indexwas ignored, returning bytes that had already been consumed by earlierpoll_readcalls.Also drops the unnecessary
cx.waker().wake_by_ref()on the drained path, which already returnsPoll::Ready(Ok(())), and adds tests inktls/tests/integration_test.rscovering all three bugs and boundary cases.