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

Fix find_width_of_character_at_span bounds check #48522

Merged
merged 3 commits into from
Mar 2, 2018
Merged

Fix find_width_of_character_at_span bounds check #48522

merged 3 commits into from
Mar 2, 2018

Conversation

etaoins
Copy link
Contributor

@etaoins etaoins commented Feb 25, 2018

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 #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 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
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 25, 2018
@estebank
Copy link
Contributor

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.
@etaoins
Copy link
Contributor Author

etaoins commented Feb 26, 2018

@estebank Added a new commit with a test

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 26, 2018

📌 Commit c237d4f has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 26, 2018
@nikomatsakis
Copy link
Contributor

r? @estebank

@Manishearth
Copy link
Member

Fails pretty:

[01:46:36] failures:
[01:46:36] 
[01:46:36] ---- [pretty] run-pass/issue-48508.rs stdout ----
[01:46:36] 	
[01:46:36] error: pretty-printed source does not typecheck
[01:46:36] status: exit code: 101
[01:46:36] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "-" "-Zno-trans" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/issue-48508.pretty-out" "--target=x86_64-unknown-linux-gnu" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/issue-48508.stage2-x86_64-unknown-linux-gnu.pretty.aux" "-Crpath" "-O" "-Zmiri" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-g"
[01:46:36] stdout:
[01:46:36] ------------------------------------------
[01:46:36] 
[01:46:36] ------------------------------------------
[01:46:36] stderr:
[01:46:36] ------------------------------------------
[01:46:36] error[E0425]: cannot find function `other` in module `other_file`
[01:46:36]   --> <anon>:25:25
[01:46:36]    |
[01:46:36] 25 | fn main() { other_file::other(); }
[01:46:36]    |                         ^^^^^ not found in `other_file`
[01:46:36] 
[01:46:36] error: aborting due to previous error
[01:46:36] 
[01:46:36] If you want more information on this error, try using "rustc --explain E0425"
[01:46:36] 
[01:46:36] ------------------------------------------
[01:46:36] 
[01:46:36] thread '[pretty] run-pass/issue-48508.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:2893:9
[01:46:36] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:46:36] 
[01:46:36] 
[01:46:36] failures:
[01:46:36]     [pretty] run-pass/issue-48508.rs
[01:46:36] 
[01:46:36] test result: �[31mFAILED�(B�[m. 2879 passed; 1 failed; 49 ignored; 0 measured; 0 filtered out
[01:46:36] 
[01:46:36] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:476:22

bors added a commit that referenced this pull request Feb 28, 2018
Rollup of 10 pull requests

- Successful merges: #48355, #48359, #48380, #48419, #48420, #48461, #48522, #48570, #48572, #48603
- Failed merges:
@etaoins
Copy link
Contributor Author

etaoins commented Feb 28, 2018

@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
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah, ok

@Manishearth
Copy link
Member

Perhaps. The path flag may not work if the pretty file is compiled elsewhere. ignore-pretty is an acceptable fix

@etaoins
Copy link
Contributor Author

etaoins commented Mar 1, 2018

@Manishearth @estebank

Looks like this was triggering #37195. Pushed an ignore-pretty to work around it.

@Manishearth
Copy link
Member

@bors r=estebank

@bors
Copy link
Contributor

bors commented Mar 1, 2018

📌 Commit 363d604 has been approved by estebank

Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 1, 2018
…-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
@bors bors merged commit 363d604 into rust-lang:master Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants