Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Getting opengl function address panics if the address contains a null terminator #1400

Closed
morr0ne opened this issue Apr 28, 2022 · 3 comments

Comments

@morr0ne
Copy link

morr0ne commented Apr 28, 2022

Window.get_proc_address accepts a &str which gets then converted to a CString without checking for null bytes and just calling unwrap. Passing a &str with internal null bytes will crash the program. The conversion can also be expensive considering that most opengl loaders will use a CString/CStr directly. This means that in most cases the following conversion happens:
CString => &str => CString.

it's probably a good idea for get_proc_address to ask directly for a &CStr and let the library user handle the conversion if necessary.

related #1314

@kchibisov
Copy link
Member

That makes sense, could probably change that.

@morr0ne
Copy link
Author

morr0ne commented Apr 29, 2022

Upon further inspection it looks like some tools like the one used in the examples (gl_generator) use &str for loading, hence probably why that was used. Making a change like that probably also means changing the generator used. Phosporus seems to be the best alternative, it used by glow and transitively by bigger projects like wgpu and bevy.

@kchibisov
Copy link
Member

kchibisov commented Sep 3, 2022

Fixed in #1435.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants