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

WGSL front end: Fix panic on invalid input #95

Merged
merged 1 commit into from
Jul 3, 2020
Merged

WGSL front end: Fix panic on invalid input #95

merged 1 commit into from
Jul 3, 2020

Conversation

LingMan
Copy link
Contributor

@LingMan LingMan commented Jul 3, 2020

Until now the WGSL parser would interpret a character index as a byte index.
This could lead to a panic on invalid input strings like ""\u{2}ПЀ\u{0}"",
because it would use that index to slice a string without ensuring the slicing
happens on a character boundary.

One possible fix would have been to call str::find instead of position,
however by relying on splitn instead of slicing a str manually it is
easier to convince ourselves that this code can no longer panic.

Fixes #90

Until now the WGSL parser would interpret a character index as a byte index.
This could lead to a panic on invalid input strings like "\"\u{2}ПЀ\u{0}\"",
because it would use that index to slice a string without ensuring the slicing
happens on a character boundary.

One possible fix would have been to call `str::find` instead of `position`,
however by relying on `splitn` instead of slicing a str manually it is
easier to convince ourselves that this code can no longer panic.

Fixes #90
Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@kvark kvark merged commit dff3111 into gfx-rs:master Jul 3, 2020
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.

WGSL front end crashes on malformed input
2 participants