Skip to content

Fix buffer and scoped interface pointer provenance - #5242

Merged
Kenny Kerr (kennykerr) merged 1 commit into
masterfrom
fix/optional-buffer-provenance
Oct 28, 2026
Merged

Kenny Kerr (kennykerr) merged 1 commit into
masterfrom
fix/optional-buffer-provenance

Conversation

@kennykerr

Copy link
Copy Markdown
Collaborator

Fix optional writable buffers passing pointers derived from shared borrows. Also keep the original allocation pointer when constructing scoped interfaces in bindgen and #[interface].

Add regressions and extend Miri beyond string literals to cover both paths under Stacked Borrows and Tree Borrows.

Fixes #5189.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the pointer-provenance changes in generated bindings and scoped interfaces.

No open issues 🎉

What changed in this PR

This PR addresses pointer-provenance problems related to #5189 in generated Windows bindings and scoped interfaces, with regression coverage in Miri.

Changes:

  • Derive optional writable-buffer pointers from mutable borrows and regenerate affected bindings.
  • Preserve allocation pointers when constructing scoped interfaces in bindgen and #[interface].
  • Add buffer and scoped-interface regressions, with Miri checks under Stacked Borrows and Tree Borrows.
File Description
crates/​tests/​libs/​bindgen/​src/​provenance_tests.rs Adds buffer-write and scoped-interface lifetime regressions.
crates/​tests/​libs/​bindgen/​src/​lib.rs Registers provenance tests.
crates/​tests/​libs/​bindgen/​input/​optional_buffers.rdl Defines optional-buffer and scoped-interface fixtures.
crates/​tests/​libs/​bindgen/​expected/​unspecified_direction.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​type_closure.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​type_closure_shallow.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​type_closure_minimal.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​string_aliases.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​query_buffers.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​optional_buffers.rs Adds expected buffer wrappers and scoped constructors.
crates/​tests/​libs/​bindgen/​expected/​native_references.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​method_return.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​method_params.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​interface_required.rs Updates expected scoped constructors.
crates/​tests/​libs/​bindgen/​expected/​interface_out_array.rs Updates expected scoped constructors.
crates/​tests/​libs/​bindgen/​expected/​implement_pattern.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​com_interface.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​com_implement.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​buffer_relationships.rs Updates expected scoped construction.
crates/​tests/​libs/​bindgen/​expected/​buffer_contracts.rs Updates expected scoped constructors.
crates/​libs/​windows/​src/​Windows/​Win32/​xaudio2/​mod.rs Preserves allocation pointers in XAudio2 scoped constructors.
crates/​libs/​windows/​src/​Windows/​Win32/​wmcodecdsp/​mod.rs Uses mutable pointers for optional codec-string buffers.
crates/​libs/​windows/​src/​Windows/​Win32/​winspool/​mod.rs Uses mutable pointers for optional package-path buffers.
crates/​libs/​windows/​src/​Windows/​Win32/​winsock2/​mod.rs Fixes optional socket-registration buffer pointers.
crates/​libs/​windows/​src/​Windows/​Win32/​wincrypt/​mod.rs Fixes the optional encryption-buffer pointer.
crates/​libs/​windows/​src/​Windows/​Win32/​wincodecsdk/​mod.rs Fixes optional metadata-information buffer pointers.
crates/​libs/​windows/​src/​Windows/​Win32/​wincodec/​mod.rs Fixes optional imaging buffer pointers.
crates/​libs/​windows/​src/​Windows/​Win32/​winbase/​mod.rs Fixes the optional audit object-type buffer pointer.
crates/​libs/​windows/​src/​Windows/​Win32/​vswriter/​mod.rs Preserves allocation pointers in VSS scoped constructors.
crates/​libs/​windows/​src/​Windows/​Win32/​usp10/​mod.rs Fixes the optional fixed-size layout-buffer pointer.
crates/​libs/​windows/​src/​Windows/​Win32/​shobjidl_core/​mod.rs Fixes the optional rename-buffer pointer.
crates/​libs/​windows/​src/​Windows/​Win32/​securitybaseapi/​mod.rs Fixes optional access-check buffer pointers.
crates/​libs/​windows/​src/​Windows/​Win32/​sapiddk/​mod.rs Preserves allocation pointers in speech-task scoped constructors.
crates/​libs/​windows/​src/​Windows/​Win32/​sapi/​mod.rs Preserves the speech-callback allocation pointer.
crates/​libs/​windows/​src/​Windows/​Win32/​ro/​mod.rs Preserves allocation pointers in metadata scoped constructors.
crates/​libs/​windows/​src/​Windows/​Win32/​oledb/​mod.rs Fixes optional property-set buffer pointers.
crates/​libs/​windows/​src/​Windows/​Win32/​memoryapi/​mod.rs Fixes optional extended-parameter buffer pointers.
crates/​libs/​windows/​src/​Windows/​Win32/​gdiplustypes/​mod.rs Preserves the GDI+ callback allocation pointer.
crates/​libs/​windows/​src/​Windows/​Win32/​esent/​mod.rs Fixes the optional column-retrieval buffer pointer.
crates/​libs/​windows/​src/​Windows/​Win32/​d3dcommon/​mod.rs Preserves the include-handler allocation pointer.
crates/​libs/​windows/​src/​Windows/​Win32/​d3d12/​mod.rs Preserves allocation pointers in reflection scoped constructors.
crates/​libs/​windows/​src/​Windows/​Win32/​d3d11/​mod.rs Preserves allocation pointers in reflection scoped constructors.
crates/​libs/​windows/​src/​Windows/​Win32/​d3d10/​mod.rs Preserves allocation pointers in effect and reflection constructors.
crates/​libs/​windows/​src/​Windows/​Win32/​bcrypt/​mod.rs Fixes optional initialization-vector buffer pointers.
crates/​libs/​interface/​src/​generation.rs Generates scoped interfaces from raw allocation pointers.
crates/​libs/​bindgen/​src/​types/​cpp_method.rs Generates mutable borrows for optional writable buffers.
crates/​libs/​bindgen/​src/​types/​cpp_interface.rs Generates scoped constructors that preserve allocation pointers.
.github/​workflows/​miri.yml Adds provenance and interface-macro checks under both borrow models.

Review effort: Balanced

@kennykerr
Kenny Kerr (kennykerr) merged commit 0fabe80 into master Oct 28, 2026
39 checks passed
@kennykerr
Kenny Kerr (kennykerr) deleted the fix/optional-buffer-provenance branch October 28, 2026 22:20
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.

GetKeyboardState (and other &mut [T] out-buffer wrappers) pass as_ptr() to a callee that writes, which miscompiles in release

2 participants