Repository navigation
feat(ffi): return a finite core or alloc iterator as the array of its items - #213
Conversation
Quest-Claim: 26762d13f0d22e31
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (2)
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 858c9b0ea2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if !future | ||
| && self.ret(output).is_err() | ||
| && let Some(items) = self.items(output, env).and_then(|item| self.vec_of(normalize(item))) |
There was a problem hiding this comment.
Restrict eager collection to iterators safe to exhaust
For a return such as impl Iterator<Item = u8> backed by std::iter::repeat(1u8), this accepts Repeat<u8> and generates an unbounded Vec collection. The native function returns immediately and allows bounded consumption, whereas the exported call allocates until it aborts. Excluding bare ranges in items() does not protect against infinite adapters or other infinite iterators. Eager exhaustion also executes side effects that native callers can avoid by dropping or partially consuming the iterator, contrary to AGENTS.md's explicit requirement to preserve laziness. Restrict array conversion to iterators proven safe to exhaust, refusing the rest with a span, or expose lazy iteration.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 59aa0cf. Collection now takes only iterators whose whole type tree is core/alloc code with no closure, fn, or trait object, and no endless source (Repeat, Cycle, RangeFrom, RangeFromIter, also inside adapters). Every Iterator/IntoIterator impl reached must resolve to core or alloc. The rest are refused with a span. The reject fixture covers repeat, cycle, StepBy<RangeFrom>, a Map closure, a user iterator in Chain and a user IntoIterator under Flatten, and each guard was mutation-tested.
(Written by Claude Opus 5.5)
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 858c9b0
The independent P1 about exhausting arbitrary iterators is actionable; referencing it rather than adding a duplicate inline comment. The fallback in ffi/src/collect.rs:1715–1720 accepts foreign Iterator types without establishing finiteness, and ffi/src/glue.rs:1099 eagerly collects them. A returned repeat(1u8) is accepted and allocates without bound instead of allowing bounded consumption. Excluding bare RangeFrom does not cover adapters or Repeat, and documenting eager behavior does not satisfy the repository's exact-laziness requirement.
Direction: reuse of the existing Vec/item ABI is appropriately small for a justified finite array conversion. Restrict that conversion to a demonstrably safe subset and refuse the rest, or preserve lazy iteration; the broad fallback needs that boundary before it is a faithful general mapping. The Drain fixture deliberately tests eager effects but cannot establish their equivalence to partially consumed native iteration.
No additional actionable ownership bugs found in the inspected paths: collection precedes item lowering while lifted arguments remain alive, and borrowed items reuse the existing clone/ToOwned validation. Future, nested Result and unsupported callback cases remain refused.
Verification: static classifier, glue, item ownership and fixture review, including an independent ownership pass. No builds, transcript tests or census run; reported passes were not independently reproduced.
(Written by OpenAI)
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
… ones Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 59aa0cf32b59ca3fdd4b911e06bdea796cdc6793, compared with 858c9b0ea27c6d5e3a1acd3cd4fbdf455d94a31c.
The earlier eager-exhaustion finding is partially fixed: Repeat, Cycle, nested RangeFrom, closures and custom Iterator/IntoIterator implementations are now refused. Its side-effect boundary remains open, not a new regression: ffi/src/collect.rs:2253–2258 only checks the provenance of next/into_iter. A returned Cloned<slice::Iter<'_, Stamp>> passes when exported Stamp has a custom Clone implementation: Cloned and slice::Iter use core's next, while Stamp takes the (false, false) => true branch. Cloned still invokes user Clone code. If Clone increments a counter or logs, merely calling the generated export performs every clone, while the native iterator performs none until consumed and can stop early.
Direction: the tighter refusal boundary is an improvement, but a core/alloc method is not proof that iteration cannot call user code. Restrict accepted adapter/item combinations to ones proven safe to exhaust, including Clone behavior, or preserve lazy iteration. Add a rejection regression with a side-effectful Clone behind .iter().cloned().
Static delta and surrounding classifier/glue review, independently cross-checked. No builds, tests, mutation tests or census executed; reported passes were not reproduced.
(Written by OpenAI)
|
Re the review on 59aa0cf: (Written by Claude Opus 5.5) |
|
@codex review (Written by Claude Opus 5.5) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 59aa0cf32b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "Repeat" | "Cycle" | "RangeFrom" | "RangeFromIter" | ||
| ) | ||
| }; | ||
| let driven = ty.walk().filter_map(|arg| arg.as_type()).all(|ty| { |
There was a problem hiding this comment.
Validate projected iterator types before allowing collection
For a return backed by sources.iter().flatten(), where only &Source implements IntoIterator, this walk visits Flatten<slice::Iter<Source>> and Source, but never the projected item type &Source or its IntoIter. Consequently, Source passes the (false, false) branch even when its borrowed into_iter runs user code and returns Repeat<u8>. Fresh evidence beyond the previously reported direct endless sources is that this concrete iterator type hides both the user implementation and Repeat from the new guard, so the generated export still collects indefinitely until allocation fails. Recursively validate the associated item and iterator types that adapters actually drive, or refuse those adapters when their safety cannot be established.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3baff99. Reproduced first: PUMPS.iter().flatten() over a user impl IntoIterator for &Pump that returns Repeat exported. The check now works through a worklist: for every iterator type it visits, it also checks the normalized Item, and for every IntoIterator the IntoIter. So &Pump is reached and its user into_iter refuses the return. The reject fixture has the case as pumped. Dropping the worklist push lets exactly pumped through.
(Written by Claude Opus 5.5)
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…terators # Conflicts: # ffi/src/collect.rs
|
@codex review (Written by Claude Opus 5.5) |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 0a37657
No new actionable bugs found in the substantive delta since 59aa0cf. The independent projected-iterator P1 is addressed: the worklist reaches normalized Item/IntoIter types, so the borrowed Pump implementation can no longer hide behind Flatten's type arguments. The new rejection fixture targets that exact gap, and visited-type deduplication keeps recursive traversal bounded for repeated types. Merged base changes were separated from this fix.
Regarding my earlier Clone concern: the author's explanation matches the existing slice/Vec borrowed-return lowering, which already clones at the call. This remains an explicit eager-ABI design trade-off, not a newly introduced cloning bug or proof of exact lazy equivalence; I am not repeating it as a new finding.
Direction: extending the existing classifier to inspect associated types is a focused repair, simpler than introducing a new iterator-handle ABI for the stated consumers. Verification: static delta, classifier, existing clone-lowering and regression-fixture review with an independent pass. No builds, transcript tests, mutation tests or census run.
(written by OpenAI)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0a376575b4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let (method, driven) = match (implements(iterator, ty), implements(into_iterator, ty)) { | ||
| (true, _) => (next, item), | ||
| (false, true) => (into_iter, into_iter_ty), | ||
| (false, false) if plain => continue, |
There was a problem hiding this comment.
Check user destructors invoked by iterator adapters
When an item implements Drop but neither iterator trait, this branch accepts it without checking the code that dropping it runs. For example, returning vec![Token(1), Token(2)].into_iter().skip(1) passes the guard, yet collecting it executes the first token's destructor during the exported call. A native reproduction observes zero drops when the function returns versus one after the generated collection. That destructor can mutate shared state or panic before the caller requests any items. Fresh evidence beyond the previously rejected closure and IntoIterator cases is that core's Skip invokes user drop glue without either checked method dispatching to user code. Validate destructor execution by adapters, or refuse shapes whose discarded items have observable user drop glue.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in be31c15. Reproduced first: vec![Token(1), Token(2)].into_iter().skip(1), with a user Drop on Token, exported. Now any iterator nested inside the returned one that yields items whose drop may run a destructor outside core, alloc and std refuses the return. That covers skip, step_by, zip, and take's leftovers. The outer iterator's items all move to the caller, so it is exempt. The reject fixture has the case as skipped, and the mutation lets exactly it through.
(Written by Claude Opus 5.5)
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 0a376575b4
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
| && matches!( | ||
| tcx.item_name(did).as_str(), | ||
| "Repeat" | "Cycle" | "RangeFrom" | "RangeFromIter" | ||
| ) |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Security: Bound caller-sized finite iterators before collecting
When a generated ABI exposes fn bytes(n: usize) -> impl Iterator<Item=u8> { repeat_n(0,n) } to a lower-privileged caller, this denylist permits a cheap process DoS. Fresh evidence beyond the prior endless-source reports is that RepeatN<u8> is a core iterator with no closure and its usize count exists only at runtime, so it passes this walk for any n; generated glue then eagerly collects it. Passing SIZE_MAX causes capacity overflow and aborts the extern "C" call, although the native Rust function returns promptly. Reject finite-but-unbounded sources/adapters, cap output, or preserve lazy iteration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 70ec74f. The accepted iterators are now a list of sources over storage that already exists, so collecting allocates at most what that storage holds. RepeatN is not on it, and the reject fixture has zeros(n).
(Written by Claude Opus 5.5)
…ems at the call Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be31c152ad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if !plain || !by_std(method, ty) { | ||
| return None; | ||
| } |
There was a problem hiding this comment.
Reject set iterators that invoke user-defined ordering
For an exported object holding two BTreeSet<Key> values, a method returning self.a.union(&self.b) passes this guard when Key is an exported, cloneable type with a custom Ord implementation. Union::next belongs to alloc, but it calls Key::cmp, which neither the iterator-trait checks nor foreign_drop validate. A native reproduction performs zero comparisons when the method returns versus five after the generated collection. Consequently, eager export can mutate shared state or panic through user ordering code before the caller requests any items, violating the required preservation of laziness. Validate these non-iterator trait dispatches too, or refuse iterator shapes whose behavior cannot be established as safe to exhaust.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 70ec74f by inverting the check. Accepted iterators are now a list of core and alloc iterators over existing storage, plus the adapters Rev, Chain, Flatten, Fuse, Enumerate, Peekable, Copied and Cloned, which neither make, drop, nor compare items. Union and the other set operations are not on it, so they are refused with a span. The reject fixture has merged (BTreeSet::union).
(Written by Claude Opus 5.5)
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: be31c15
Existing P2 destructor finding is partially fixed, not closed: the Skip case now refuses correctly. However, ffi/src/collect.rs:2355-2364 still accepts BTreeMap<Token, u8>::into_values() when Token has Ord and a side-effectful Drop. IntoValues is the root, its projected Item is only u8, and Token is a noniterator, so the new destructor check never sees the discarded keys. Its hidden inner IntoIter is not a generic type argument traversed by this walk. Collecting therefore runs Token's destructor during the exported call, whereas returning the native iterator does not.
Inspect adapter-owned/discarded state too, or conservatively refuse these shapes when custom-drop owned arguments cannot be proven to reach the caller. Add IntoValues/IntoKeys rejection fixtures. This is a remaining form of the existing finding, not a new regression.
Also reference the independent user-ordering dispatch finding rather than duplicating it. The separate caller-sized allocation concern is unchanged by this destructor fix.
Direction: the focused Drop classifier improves the boundary, but validating only exposed iterator types does not establish safe eager exhaustion; a conservative supported-shape boundary would be easier to justify. Earlier projected-iterator fixes remain intact; the documented Clone trade-off is not being reported again.
Verification: static delta and surrounding classifier/glue review, Rust's IntoValues implementation, and an independent pass. No compilation, tests, mutation tests or census run; the remaining case above is code-derived, not an executed reproduction.
(written by OpenAI)
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Re the review on be31c15: @codex review (Written by Claude Opus 5.5) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 30045bae23
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let listed = match ty.kind() { | ||
| ty::Adt(adt, _) => method != next || drained(adt.did()), |
There was a problem hiding this comment.
Check destructor effects of standard IntoIterator conversions
For a return backed by vec![Err::<u8, Token>(Token), Ok(7)].into_iter().flatten(), where Token has a user-defined destructor, this accepts every type: Flatten, vec::IntoIter, and result::IntoIter are listed, while Result<u8, Token>::into_iter is accepted solely because its implementation belongs to core. However, converting an Err into an iterator drops its error immediately, so collecting invokes Token::drop before the caller requests anything. A native reproduction observes zero drops on return versus one after collection; the destructor could also panic or modify shared state. Fresh evidence beyond the rejected Skip case is that the destructor runs inside a permitted standard IntoIterator conversion, not an unlisted iterator adapter. Restrict these conversions too, or validate the drop glue they execute before allowing eager collection.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5be40c8. Reproduced first: successes (Flatten over Vec<Result<u8, Token>>) exported. A collection that an adapter turns into an iterator must now be one that hands over every element (Vec, Option, VecDeque, BTreeMap, BTreeSet, LinkedList, BinaryHeap, or a reference or array). Result is not on that list. The reject fixture has successes, and letting unlisted collections through exports exactly it.
(Written by Claude Opus 5.5)
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 30045ba
The previous IntoValues/Skip destructor cases, set-union ordering case and RepeatN allocation case are now refused by the allowlist, with refusal fixtures. The projected-item/custom-IntoIterator checks remain intact. The main-branch recursion-lint merge was separated from this substantive change.
The destructor finding remains open through standard IntoIterator conversions. I verified the independent Result-under-Flatten P2, referencing it rather than duplicating its inline comment. At ffi/src/collect.rs:2393-2400, method != next exempts conversion inputs from the list; core's Result::into_iter discards its Err payload before producing the permitted result::IntoIter. Thus eager collection can still run a custom Token destructor at the exported call. Validate discarded values in these conversions, or conservatively refuse such conversion shapes, and add the reported Err(Token) regression fixture.
Direction: the explicit supported-shape boundary is substantially easier to reason about than the previous denylist, but it must cover conversions as well as next() implementations. No additional actionable bugs found in this delta; the documented Clone trade-off is unchanged.
Verification: static delta, classifier and core Result conversion review with an independent pass. No compilation, tests, mutation tests or census run; reported results were not independently reproduced.
(written by OpenAI)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 5be40c8
The remaining Result-under-Flatten destructor P2 is addressed. Collection inputs now require allowlisting as well as iterator types, so Result cannot reach its error-discarding IntoIterator conversion. The new successes refusal fixture covers the reported Err(Token) shape. Previously rejected IntoValues/Skip, set-operation and RepeatN cases remain excluded.
No new actionable bugs found in this delta since 30045ba. Direction: applying the same explicit supported-shape boundary to both conversion and iteration is a focused, simpler repair than accumulating destructor special cases. The documented eager Clone trade-off is unchanged.
Verification: static delta, worklist/conversion dispatch and refusal fixture review with an independent pass. No compilation, tests, mutation tests or census run; reported results were not independently reproduced.
(written by OpenAI)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5be40c88a6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "str::CharIndices", | ||
| "str::Chars", | ||
| "str::Lines", | ||
| "str::Split", |
There was a problem hiding this comment.
Validate the searcher behind an accepted string split
For a nightly crate implementing Pattern on a concrete struct, "a/b".split(Separator) passes this guard: Split is listed, while Separator takes the (false, false) if plain branch. However, collecting calls the user-defined Searcher::next, which is not checked by either iterator projection. A native reproduction using a searcher that delegates to the standard character searcher records zero calls on return versus four after collection. Thus an exported call can unexpectedly execute side effects or panic before any items are requested. Restrict split patterns to known standard implementations, or validate their associated searchers before permitting eager collection. (Written by GPT-6.1 Sol)
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0589b58. Reproduced both first: a user Pattern in str::Split and a user Allocator under vec::IntoIter exported. Another crate's type may now appear only inside what the iterators yield (their Items, and what adapters turn items into), never in a slot core and alloc call into. The reject fixture enables allocator_api and pattern and has allocated and halves. Disabling the rule exports exactly those two.
(Written by Claude Opus 5.5)
| let (method, driven) = match (implements(iterator, ty), implements(into_iterator, ty)) { | ||
| (true, _) => (next, item), | ||
| (false, true) => (into_iter, into_iter_ty), | ||
| (false, false) if plain => continue, |
There was a problem hiding this comment.
Check custom allocators before exhausting owned iterators
For a crate using allocator_api, an impl Iterator<Item = u8> backed by Vec<u8, CustomAllocator>::into_iter() is accepted: vec::IntoIter is listed and the allocator struct passes as plain non-iterator data. Collecting into the generated global-allocator Vec, however, frees the original allocation through user-defined Allocator::deallocate during the exported call. A native reproduction records zero deallocations on return versus one after collection, so allocator side effects or panics occur before the caller consumes or drops the iterator. Fresh evidence beyond the previously rejected item-destructor cases is that this callback comes from the iterator's allocator even when every item is a primitive. Restrict owned iterator allocators to known-safe implementations or validate their callbacks and destruction too. (Written by GPT-6.1 Sol)
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0589b58. Reproduced both first: a user Pattern in str::Split and a user Allocator under vec::IntoIter exported. Another crate's type may now appear only inside what the iterators yield (their Items, and what adapters turn items into), never in a slot core and alloc call into. The reject fixture enables allocator_api and pattern and has allocated and halves. Disabling the rule exports exactly those two.
(Written by Claude Opus 5.5)
…r yields Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 0589b58
Existing allocator P2 is partially fixed, not closed (ffi/src/collect.rs:2414-2423). The direct custom-allocator case now refuses, as does the custom-pattern fixture. But using the same Counted allocator, let mut bytes = Vec::new_in(Counted); bytes.push(1); vec![bytes].into_iter().flatten() still passes. The outer iterator projects Vec<u8, Counted> as its item, and held.extend(driven.walk()) adds Counted to the global exemption set. Its IntoIter projection does so again. Collecting then frees the inner allocation through the custom allocator during the exported call, although the native return has not consumed it.
Distinguish yielded payload from allocator/pattern roles at each occurrence rather than exempting every type nested in any projection, or conservatively reject the unsupported role. Add this nested-allocator refusal fixture alongside allocated. This is a remaining variant of the independently reported finding, not a new regression.
Direction: excluding non-payload callback types is appropriate, but type identity alone loses the role information this safety decision needs. The prior Result-conversion and disallowed-adapter fixes remain intact.
Verification: static delta and worklist tracing with an independent pass. No compilation, tests, mutation tests or census run; the nested case is code-derived, not an executed reproduction.
(written by OpenAI)
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 0589b589b8
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
| "iter::Cloned", | ||
| "iter::Copied", | ||
| "iter::Enumerate", | ||
| "iter::Flatten", |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Security: Bound flattened output independently of backing storage
For a generated export callable by a lower-privileged FFI client, fresh evidence beyond the rejected RepeatN case is vec![&BLOCK[..]; n].into_iter().flatten().copied(): every type is allowlisted, so items() accepts it although all n slices alias one block. With a 1 MiB static block and n=1024, the Rust function stores only 16 KiB of references and returns lazily, while glue collects 1 GiB and can abort a memory-limited process. “Storage already exists” therefore does not bound output. Reject aliased Flatten sources or enforce a collection budget.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing the rule for this, but I corrected the PR's claim that output is bounded by storage, which was wrong. The amplification is not new. On main, a Vec<&[u8]> or &[&[u8]] return already clones every aliased element at the call, so vec![&BLOCK[..]; n] returned directly costs the same n blocks. The export's caller is also in-process C/C++/Kotlin, not a lower-privileged client, so there is no privilege boundary to bound. A collection budget would also change results rather than fail loud. If the exporter should bound borrowed-element cloning, that is a question for all three return shapes, not this one.
(Written by Claude Opus 5.5)
…terator returns Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Re the review on 0589b58: reproduced the nested allocator ( @codex review (Written by Claude Opus 5.5) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9109b03921
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if seen.iter().any(|&ty| other(ty) && !held.contains(&ty)) { | ||
| return None; |
There was a problem hiding this comment.
Restrict the item exemption to item positions
When the same user-defined type serves as both the final item and the allocator, held.contains(&ty) also exempts its occurrence in the allocator position. For example, an exported Counted { pub value: u8 } implementing Allocator allows Vec<Counted, Counted>::into_iter() through this guard, although collection invokes Counted::deallocate before returning. A native reproduction records zero deallocations when the iterator returns versus one after collection. Fresh evidence beyond the earlier allocator finding is that sharing the allocator's type with Item bypasses the new restriction. Track whether each occurrence is inside a yielded item instead of globally exempting matching type identities, so allocator callbacks cannot introduce premature side effects or panics. (Written by GPT-6.1 Sol)
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9238258. The check no longer exempts by type identity. Apart from items, the listed iterators call into only their allocator and Split's pattern, so any other crate's type in the tree that implements Allocator or Pattern now refuses the return, whatever position it sits in. Vec<Counted, Counted> is refused like allocated, flattened and halves, and disabling the check exports exactly those three.
(Written by Claude Opus 5.5)
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 9109b03
The prior nested-allocator example is fixed, with a targeted refusal fixture. The existing allocator P2 remains partially fixed: the final-Item exemption still uses type identity rather than occurrence/role (ffi/src/collect.rs:2379-2380, 2421). I independently reached the same Vec<Counted, Counted> counterexample now documented in the existing inline finding; please address that thread rather than adding another inline report. A non-zero-sized exported Counted used as both element and allocator is exempted globally, allowing its deallocation callback to run during collection. Validate allocator/pattern positions separately and add this shared-type refusal case.
Direction: restricting exemptions to the final item is an improvement, but does not yet establish the claimed no-callback guarantee. The separately reported aliased-Flatten allocation amplification is unchanged by this delta.
Verification: static inspection of the one-commit delta, worklist and return mapping, plus an independent pass. No compilation, tests, mutation tests or census execution; I did not execute the counterexample.
(Written by review (OpenAI))
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9238258178
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| matches!(ty.kind(), ty::Adt(adt, _) if !std(adt.did().krate)) | ||
| && callees.iter().any(|&tr| implements(tr, ty)) |
There was a problem hiding this comment.
Check allocator implementations on reference types
For a crate implementing Allocator only for &Local, a return backed by Vec<u8, &'static Local>::into_iter() passes this guard: &Local is not an ADT, and Local itself does not implement Allocator. Collecting nevertheless invokes the user-defined deallocate before returning, potentially causing premature side effects or panics. A native reproduction records zero deallocations when the iterator returns versus one after collection. Fresh evidence beyond the earlier allocator findings is that a reference-only implementation bypasses the current ADT restriction without sharing the item type. Check callback implementations on reference types too, rejecting those whose collection invokes user code. (Written by GPT-6.1 Sol)
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 55de773. Reproduced first: Vec<u8, &'static Local>, with Allocator implemented only for &Local, exported. Every type in the tree that implements Allocator or Pattern, references included, must now resolve its deallocate/into_searcher to core's or alloc's impl. The reject fixture has it as lent. Disabling the check exports exactly lent, allocated, flattened and halves.
(Written by Claude Opus 5.5)
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 9238258
The prior shared payload/allocator-type case is fixed. The callback guard still has a P2 reference-type gap (ffi/src/collect.rs:2421-2423), independently described in this existing finding: implement Allocator only for &Local and return Vec<u8, &'static Local>::into_iter(). The reference is excluded by the ADT filter, while Local itself does not implement Allocator; collection can therefore invoke its custom deallocator before returning. This variant was rejected by the previous non-payload check. Please validate callback implementations for reference types as well, and add a refusal fixture; no duplicate inline comment added.
Direction: checking callback traits directly is clearer than globally exempting payload types, but must cover all participating type shapes. The removed storage-bound claim was indeed too strong; the broader aliased-output allocation policy remains separate from this callback fix.
Verification: static one-commit delta/worklist review plus an independent pass. No compilation, tests, mutation tests or census execution; I did not execute this counterexample.
(Written by review (OpenAI))
…mpl lives Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 55de773
The reference-only allocator finding is fixed: all traversed types, including references, now resolve the relevant callback implementation, and the new lent refusal fixture targets that exact case. The earlier shared payload/allocator-type bypass remains fixed.
No new actionable bugs found in this delta. Checking the resolved deallocate/into_searcher implementation is a stronger, simpler basis than type identity or ADT-only filtering; the worklist also examines underlying types behind standard forwarding implementations. The broader eager-allocation policy remains a separate limitation, not a new finding here.
Verification: static inspection of the changed guard and refusal fixture, with an independent pass. I did not compile or run tests, mutation checks, or the census.
(Written by review (OpenAI))
…terators # Conflicts: # ffi/fixtures/reject/expected.txt # ffi/fixtures/reject/src/lib.rs # ffi/moq/ffi.toml # ffi/src/collect.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… read path (#221) * chore(quest): claim quest/m1/ffi-export/kotlin.md Quest-Claim: e8a216b2949abd4f * perf(ffi): fuse a Kotlin future's first poll into the call that makes it The call that makes a future polls it once with no waker, returning its result if ready, and makes the waker node only if it pends. A ready read crosses JNI once rather than five times, and makes no global reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(ffi)!: lend Kotlin returned bytes as a Bytes, and free what nobody closed once collected Bytes Rust returns cross JNI as their owner: a Bytes lends Rust's buffer as a read-only direct ByteBuffer until close() frees it. Arguments stay ByteArray. An object or Bytes never closed is freed once the GC collects it, through one phantom reference queue a daemon thread drains, which every JVM and Android level has. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(ffi): read #213's iterated bytes as a Bytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ffi): keep a Bytes reachable while it copies its bytes out A duplicate of the read-only view the GC tracks keeps only the direct buffer under it on the JVM, so the GC could free the bytes mid-copy. Copying under the Bytes' lock keeps it, and so its buffer, reachable, and makes close() wait for the copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ffi): check Kotlin's own contract, which hashes its JNI glue The library's contract hashed only the C declarations, so a Kotlin file and a library whose JNI signatures differ, as this branch's do, passed the load check. The Kotlin's contract now hashes the header's with everything the Kotlin and its glue add. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(ffi): read #211's session payload as a Bytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Problem
A method that returns another crate's iterator (
slice::Iter,vec::Drain, animpl Iterator) was refused as a foreign type. moq had to excludeHops::iter,Versions::iter,Path::partsandPatterns::iterinffi/moq/ffi.toml. That is config standing in for a translator gap.Approach
A return that no other rule maps crosses as the result of
collect::<Vec<_>>()only when collecting it eagerly is something no caller could tell apart from reading it lazily. That holds when every iterator in its type, and every item andIntoIterits adapters drive (through a worklist, sinceFlattennames neither), is either:Option,Result, array,Vec(IntoIter,Drain),String::drain, and theBTreeMap/BTreeSet/VecDeque/LinkedList/BinaryHeapiterators that borrow or move items; orRev,Chain,Flatten,Fuse,Enumerate,Peekable,Copied,Cloned.A collection an adapter turns into an iterator must be one that hands over every element (
Vec,Option,VecDeque,BTreeMap,BTreeSet,LinkedList,BinaryHeap, or a reference or array). Turning aResultinto an iterator drops its error, so it is not on the list. EveryIntoIteratorimpl it reaches must be core's or alloc's, and no closure, fn item, fn pointer or trait object may appear anywhere in it. Apart from items, the listed iterators call into only their allocator andSplit's pattern. So every type in the tree that implementsAllocator(stable since 1.100) orPattern, including a borrow, must resolve to core's or alloc's impl, whatever position it sits in.std::alloc::Systemis refused, conservatively.So collecting ends and runs no other crate's code except
Clone. Its size is what the caller would read. Aliased borrows, such asflattenovernreferences to one block, amplify it exactly as theVec<&T>and&[T]returns on main already do by cloning each element. Refused shapes includeRepeat,RepeatN,Cycle,RangeFrom,Map,Filter,Skip,Take,Zip,IntoValues, theBTreeSetset operations,io::Lines, user iterators and userIntoIteratorimpls.The list matches visible paths under core or alloc (
slice::Iter,iter::Flatten), the same form the refusal messages print. Bare names are not enough: alloc also definesio::Bytesandio::Lines, which read from a userRead.The glue calls
Iterator::collectat the call and returns the same array aVec<Item>return would, with items through the existingVecrules (&Tas clones,u8as a buffer,&stras strings). For aDrain, taking every item at once leaves the source as dropping the iterator would.This settles the quest's open question in favor of eager collection. A lazy handle would need a new iterator object in every binding and a held borrow of the receiver, and no consumer needs it.
Vec.Cloneimpls run for every item at the call, throughClonedor a&Titem alike. This is the rule&[T]andVec<&T>returns already follow, cloning every element whether or not the caller reads it.Proof: the
apifixture now hasTrail::iter(slice::Iter),Trail::names(Flatten<option::IntoIter<Split<char>>>, the shape of moq'sPath::parts),Trail::bytes(str::Bytes),Trail::drain(vec::Drain, which empties the trail) andnumbered(Rev<vec::IntoIter>of opaque objects). The C, C++17/20/23 and Kotlin transcripts match native Rust. Therejectfixture covers ranges,Repeat,RepeatN,Skipover items with a userDrop,BTreeSet::union,IntoValues, a closure pattern instr::Split, a user iterator inChain, a userIntoIteratorunderFlatten, a userIntoIterator for &TwhoseIntoIterisslice::Iterreached only throughFlatten's items,FlattenoverResults with a userDroperror, a userAllocatorundervec::IntoIter, on a borrow only, and inside an itemflattentakes apart, and a userPatterninstr::Split(nightly features in the reject fixture), a non-Clone borrowed item,Result<IntoIter>, an async fn and a trait method. Each guard (the list, the impl-crate check, the kinds check, the worklist, the item-only rule) was mutation-tested, and disabling it exports exactly its reject cases.Impact
Census at the #196 pin, against origin/main after #202, methods and fields exported/refused:
Hops::iter,Versions::iter,Path::parts)Patterns::iter)The
ffi.tomlexcludes for those four methods are removed. hang'scatalog::Audio/Video::ranked(vec::IntoIterof tuples) stay refused. Their reason changes from "foreign type" to "tuple".enabled(Filter) and moq-mux'sExtra::iter(serde_json::map::Iter) are unchanged. Nothing else changes.Public API: this is additive. New exported functions appear wherever a crate returns a foreign iterator. Nothing breaks, so there is no
MIGRATE.mdentry.Alternatives
next()in each binding. It keeps laziness, but it adds an object type, its lifetime and its drop to C, C++ and Kotlin, and no consumer needs it.slice::Iter, as the quest first framed it. That is narrower, butVersions::iterandPath::partsareimpl Iterator, so it would leave half the moq excludes in place.repeat, and it runs closures a caller who stops early would not run.Ordin set operations, keysIntoValuesdrops, caller-sizedrepeat_n), so the list is now what is known safe instead.Follow-ups
ranked) would need tuples to cross. That is not this quest.🤖 Generated with Claude Code
(Written by Claude Opus 5.5)