Repository navigation
hostarch: omit a head truncated to zero bytes in AddrRangeSeq.DropFirst - #17402
Merged
copybara-service[bot] merged 1 commit intoNov 11, 2026
Merged
copybara-service[bot] merged 1 commit into
copybara-service[bot] merged 1 commit into
Conversation
AddrRangeSeq.DropFirst documents that it always omits a zero-length head, even if n is 0, so that a Head/DropFirst loop ends. It only checked whether all bytes of the head were dropped. If TakeFirst truncated the head to 0 bytes and two or more AddrRanges remain, DropFirst(0) returned the sequence unchanged. usermem.CopyInVec and CopyOutVec use this loop. For example, IOSequence.CopyIn with an 8-byte dst, over two 8-byte AddrRanges limited by TakeFirst(4), copied 4 bytes and then did not return. Treat the head as empty if the limit is 0. Assisted-by: Claude Code (claude-opus-5-5) Signed-off-by: 0z5a <[email protected]>
aaltinaydev
reviewed
Nov 10, 2026
aaltinaydev
left a comment
There was a problem hiding this comment.
[🤖] Review agent has no findings.
Automated review agent. Please address valid findings before human review, or close them with a reason.
milantracy
approved these changes
Nov 11, 2026
copybara-service Bot
pushed a commit
that referenced
this pull request
Nov 11, 2026
Fixes #17399 `AddrRangeSeq.DropFirst` documents that it always omits a zero-length head, even if `n` is 0, so that the Head/DropFirst loop in its doc comment ends. It only checked whether all bytes of the head were dropped. If `TakeFirst` truncated the head to 0 bytes (`limit == 0`) and two or more AddrRanges remain, `DropFirst(0)` returned the sequence unchanged. `usermem.CopyInVec` and `CopyOutVec` run that loop. For example, `IOSequence.CopyIn` with an 8-byte `dst`, over `{[0,8) [16,24)}.TakeFirst(4)`, copied 4 bytes and then did not return. This change also treats the head as empty if the limit is 0. Each range that `TakeFirst` truncated to 0 bytes is still visited, as a zero-length head, and is then dropped. A head that was partly consumed leaves one extra zero-length step, at `[4,4)` in the example above. **Compatibility tag:** none. This is a library fix in `pkg/hostarch`. I found no syscall path that reaches it today: in-tree callers size their buffers to `NumBytes()` or iterate in other ways. **Tests:** - New `TestAddrRangeSeqTakeFirstDropFirstIteration` in `pkg/hostarch/addr_range_seq_test.go`. It walks `TakeFirst(n)` for n = 0..12 over three ranges with Head/DropFirst. - Before: it fails at `TakeFirst(0)` because `DropFirst(0)` returns the same sequence. - After: it passes. - `go test ./pkg/hostarch/ ./pkg/usermem/ ./pkg/safemem/` pass. They were run on the `go` branch with master's test files, on Linux amd64 with go1.27.3. - `gofmt` and `go vet` are clean. Not run: `make test TARGETS=//pkg/hostarch:hostarch_test`, `make lint` and nogo (no bazel or docker on the host). **Performance:** `DropFirst64` is on the usermem copy path. The change adds one comparison in the branch for sequences of two or more ranges. ### AI disclosure Claude Code, model claude-opus-5-5. AI was used to: - find the bug; - write the repro, the fix, the test and this description. AI-generated code: - `pkg/hostarch/addr_range_seq_unsafe.go`: the 3-line change in `DropFirst64`; - `pkg/hostarch/addr_range_seq_test.go`: `TestAddrRangeSeqTakeFirstDropFirstIteration` (26 lines). The commit carries `Assisted-by: Claude Code (claude-opus-5-5)`, the same trailer form used in merged gVisor commits. FUTURE_COPYBARA_INTEGRATE_REVIEW=#17402 from 0z5a:fix/hostarch-dropfirst-truncated-head 3fc515d PiperOrigin-RevId: 1018828650
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.
Fixes #17399
AddrRangeSeq.DropFirstdocuments that it always omits a zero-length head, even ifnis 0, so that the Head/DropFirst loop in its doc comment ends.It only checked whether all bytes of the head were dropped. If
TakeFirsttruncated the head to 0 bytes (limit == 0) and two or more AddrRanges remain,DropFirst(0)returned the sequence unchanged.usermem.CopyInVecandCopyOutVecrun that loop. For example,IOSequence.CopyInwith an 8-bytedst, over{[0,8) [16,24)}.TakeFirst(4), copied 4 bytes and then did not return.This change also treats the head as empty if the limit is 0. Each range that
TakeFirsttruncated to 0 bytes is still visited, as a zero-length head, and is then dropped. A head that was partly consumed leaves one extra zero-length step, at[4,4)in the example above.Compatibility tag: none. This is a library fix in
pkg/hostarch. I found no syscall path that reaches it today: in-tree callers size their buffers toNumBytes()or iterate in other ways.Tests:
TestAddrRangeSeqTakeFirstDropFirstIterationinpkg/hostarch/addr_range_seq_test.go. It walksTakeFirst(n)for n = 0..12 over three ranges with Head/DropFirst.TakeFirst(0)becauseDropFirst(0)returns the same sequence.go test ./pkg/hostarch/ ./pkg/usermem/ ./pkg/safemem/pass. They were run on thegobranch with master's test files, on Linux amd64 with go1.27.3.gofmtandgo vetare clean. Not run:make test TARGETS=//pkg/hostarch:hostarch_test,make lintand nogo (no bazel or docker on the host).Performance:
DropFirst64is on the usermem copy path. The change adds one comparison in the branch for sequences of two or more ranges.AI disclosure
Claude Code, model claude-opus-5-5. AI was used to:
AI-generated code:
pkg/hostarch/addr_range_seq_unsafe.go: the 3-line change inDropFirst64;pkg/hostarch/addr_range_seq_test.go:TestAddrRangeSeqTakeFirstDropFirstIteration(26 lines).The commit carries
Assisted-by: Claude Code (claude-opus-5-5), the same trailer form used in merged gVisor commits.