Skip to content

Mark RawHandleWrapper::set_display_handle as unsafe - #25267

Merged
mockersf merged 1 commit into
bevyengine:mainfrom
yilin0518:fix_set_display
Aug 2, 2026
Merged

Mark RawHandleWrapper::set_display_handle as unsafe#25267
mockersf merged 1 commit into
bevyengine:mainfrom
yilin0518:fix_set_display

Conversation

@yilin0518

@yilin0518 yilin0518 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Objective

  • Fix a soundness issue in RawHandleWrapper::set_display_handle.
  • set_display_handle is currently a safe function even though its documentation requires the provided RawDisplayHandle to be valid.
  • Safe Rust can construct a RawDisplayHandle containing a non-null but invalid platform pointer and pass it to this method. Bevy may later use that value with DisplayHandle::borrow_raw or wgpu::Instance::create_surface_unsafe, both of which rely on the raw display handle being valid.
  • This allows safe code to violate an invariant relied upon by unsafe code.
  • This also makes set_display_handle inconsistent with set_window_handle, which already enforces the equivalent requirement through an unsafe function.

Solution

I take the minimal fix:

  • Mark RawHandleWrapper::set_display_handle as unsafe.

Testing

I didn't check any test about this PR because I can't find any place that use set_display_handle. So I think this change no need to do any test.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

@mockersf
mockersf added this pull request to the merge queue Aug 2, 2026
Merged via the queue into bevyengine:main with commit f63f7fa Aug 2, 2026
38 checks passed
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.

3 participants