-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix find_width_of_character_at_span bounds check #48522
Fix find_width_of_character_at_span bounds check #48522
Conversation
Commit 0bd9667 added bounds checking of our current target byte position to prevent infinite loops. Unfortunately it was comparing the file-relative `target` versus the global relative `file_start_pos` and `file_end_pos`. The result is failing to detect multibyte characters unless their file-relative offset fit within their global offset. This causes other parts of the compiler to generate spans pointing to the middle of a multibyte character which will ultimately panic in `bytepos_to_file_charpos`. Fix by comparing the `target` to the total file size when moving forward and doing checked subtraction when moving backwards. This should preserve the intent of the bounds check while removing the offset confusion. Fixes #48508
(rust_highfive has picked a reviewer for you, use r? to override) |
Could you add a test to catch any regressions? |
This is named for the issue as it's testing the specific details of that bug. It's a bit tricky as the ICE requires multiple files and debug info enabled to trigger.
@estebank Added a new commit with a test |
@bors r+ |
📌 Commit c237d4f has been approved by |
r? @estebank |
Fails pretty:
|
@Manishearth That looks like a bug in pretty, no? The test compiles and runs correctly so I'm not sure why pretty can't typecheck it. Is it worth committing this without the test? cc @estebank |
@@ -0,0 +1,16 @@ | |||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this file be in the auxiliary folder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything in auxillary
is treated as a crate. This needs to be a module to trigger #48508
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok
Perhaps. The |
The out-of-line module #37195
Looks like this was triggering #37195. Pushed an |
@bors r=estebank |
📌 Commit 363d604 has been approved by |
…-at-span-bounds-check, r=estebank Fix find_width_of_character_at_span bounds check Commit 0bd9667 added bounds checking of our current target byte position to prevent infinite loops. Unfortunately it was comparing the file-relative `target` versus the global `file_start_pos` and `file_end_pos`. The result is failing to detect multibyte characters unless their file-relative offset fit within their global offset. This causes other parts of the compiler to generate spans pointing to the middle of a multibyte character which will ultimately panic in `bytepos_to_file_charpos`. Fix by comparing the `target` to the total file size when moving forward and doing checked subtraction when moving backwards. This should preserve the intent of the bounds check while removing the offset confusion. cc @davidtwco Fixes rust-lang#48508
Commit 0bd9667 added bounds checking of our current target byte position to prevent infinite loops. Unfortunately it was comparing the file-relative
target
versus the globalfile_start_pos
andfile_end_pos
.The result is failing to detect multibyte characters unless their file-relative offset fit within their global offset. This causes other parts of the compiler to generate spans pointing to the middle of a
multibyte character which will ultimately panic in
bytepos_to_file_charpos
.Fix by comparing the
target
to the total file size when moving forward and doing checked subtraction when moving backwards. This should preserve the intent of the bounds check while removing the offset confusion.cc @davidtwco
Fixes #48508