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 panic in Path::strip_prefix #93675

Merged
merged 1 commit into from
May 8, 2022

Conversation

name1e5s
Copy link
Contributor

@name1e5s name1e5s commented Feb 5, 2022

close #93586

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(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 5, 2022
@Mark-Simulacrum
Copy link
Member

This looks like a correct fix, I think, but I think it would be worthwhile to remove prefix_len as a distinct thing from prefix_remaining entirely -- it seems like it's essentially not a good idea to use that function (unless you know the state is Prefix, but then they have identical behavior).

Would you be up for making that refactoring? It looks like there are not that many users that would need to change and all have a trivially known state, if I look locally.

@name1e5s
Copy link
Contributor Author

name1e5s commented Feb 8, 2022

This looks like a correct fix, I think, but I think it would be worthwhile to remove prefix_len as a distinct thing from prefix_remaining entirely -- it seems like it's essentially not a good idea to use that function (unless you know the state is Prefix, but then they have identical behavior).

Would you be up for making that refactoring? It looks like there are not that many users that would need to change and all have a trivially known state, if I look locally.

done

@Mark-Simulacrum
Copy link
Member

Thanks, that looks great!

@bors r+ rollup=never (potentially perf-sensitive)

@bors
Copy link
Contributor

bors commented Feb 9, 2022

📌 Commit 8ef9477eac8ccad15078b21d2004813c3f084f4c has been approved by Mark-Simulacrum

@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 9, 2022
@bors
Copy link
Contributor

bors commented Feb 12, 2022

⌛ Testing commit 8ef9477eac8ccad15078b21d2004813c3f084f4c with merge eb40a89684843ed08dc5bf766825533517238e56...

@bors
Copy link
Contributor

bors commented Feb 12, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 12, 2022
@rust-log-analyzer

This comment has been minimized.

@matthiaskrgr
Copy link
Member

@bors retry x86_64 msvc (probably) spurious failure:

[RUSTC-TIMING] unicode_width test:false 0.100
[RUSTC-TIMING] getopts test:false 3.213
[RUSTC-TIMING] proc_macro test:false 15.787
   Compiling test v0.0.0 (D:\a\rust\rust\library\test)
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX64\\x64\\link.exe" "/DEF:C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\rustcyYH2W9\\lib.def" "/NOLOGO" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\deps\\test-6464307edd00076d.test.06275a10-cgu.0.rcgu.o" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\deps\\test-6464307edd00076d.47fpacyqlqntgftt.rcgu.rmeta" "/LIBPATH:D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\deps" "/LIBPATH:D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\release\\deps" "/LIBPATH:D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\build\\compiler_builtins-d23c84560eca12a0\\out" "/LIBPATH:D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "kernel32.lib" "/WHOLEARCHIVE:\\\\?\\D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\deps\\libgetopts-04f14876bdd48cb7.rlib" "/WHOLEARCHIVE:\\\\?\\D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\deps\\libunicode_width-c74fe7d359ba4245.rlib" "/WHOLEARCHIVE:\\\\?\\D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\deps\\librustc_std_workspace_std-ac92d3dd0da3e4c2.rlib" "/LIBPATH:\\\\?\\D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\deps" "\\\\?\\D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\deps\\libcompiler_builtins-033009b95f350faf.rlib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "libcmt.lib" "/NXCOMPAT" "/LIBPATH:D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\deps\\test-6464307edd00076d.dll" "/OPT:REF,ICF" "/DLL" "/IMPLIB:D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage1-std\\x86_64-pc-windows-msvc\\release\\deps\\test-6464307edd00076d.dll.lib" "/DEBUG"
  = note: lib.def : error LNK2001: unresolved external symbol __rust_alloc

          lib.def : error LNK2001: unresolved external symbol __rust_alloc_zeroed

          lib.def : error LNK2001: unresolved external symbol __rust_dealloc

          lib.def : error LNK2001: unresolved external symbol __rust_realloc

          D:\a\rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps\test-6464307edd00076d.dll.lib : fatal error LNK1120: 4 unresolved externals
          

[RUSTC-TIMING] test test:false 17.556
error: could not compile `test` due to previous error

@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 12, 2022
@bors
Copy link
Contributor

bors commented Feb 12, 2022

⌛ Testing commit 8ef9477eac8ccad15078b21d2004813c3f084f4c with merge 25b8514be67192e2651807fc34bcbd353c3e31d3...

@bors
Copy link
Contributor

bors commented Feb 12, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 12, 2022
@rust-log-analyzer

This comment has been minimized.

@matthiaskrgr
Copy link
Member

ok might not be spurious after all 🤔

@Mark-Simulacrum
Copy link
Member

I have no sense of why this might be happening -- this particular patch seems like it should be near-identical in terms of functionality. Maybe we're no longer including some prefix due to the change in include_cur_dir, which is causing us to reference a different path in the link invocation somehow? That would be surprising to me, the behavior looks right I think with the new impl.

cc @the8472 since you've touched the path-related code recently and maybe can spot what I'm presumably overlooking here

@the8472
Copy link
Member

the8472 commented Feb 14, 2022

I see two potential problems

a) the new prefix_remaining() method only checks self.front == State::Prefix but not self.back which changes during backwards iteration and can also reach the prefix
b) len_before_body() wants to know the prefix length even when self.front != Prefix (or is this part of the fix? The PR doesn't explain)

#93586 (comment) mentions as_path panicking which calls trim_right() which in turn calls len_before_body so that may be worth looking into. Maybe try to reproduce it first with a stacktrace to check it's the right callsite.

@the8472
Copy link
Member

the8472 commented Feb 14, 2022

Btw, did you run stage0 std tests under windows locally? I guess CI didn't even get that far, but if the testsuite doesn't catch whatever is failing here then we need more coverge.

@ChrisDenton
Copy link
Member

I'm seeing these failures locally: x.py test library/std --test-args path::tests

---- path::tests::test_decompositions_windows stdout ----
thread 'path::tests::test_decompositions_windows' panicked at 'iter: Expected ["c:", "\\"], found ["\\", ":"]', library\std\src\path\tests.rs:523:5

---- path::tests::test_push stdout ----
thread 'path::tests::test_push' panicked at 'pushing "baz" onto "\\\\?\\foo\\bar": Expected "\\\\?\\foo\\bar\\baz", got "\\?\\foo\\bar\\baz"', library\std\src\path\tests.rs:1252:9

@Mark-Simulacrum Mark-Simulacrum removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 21, 2022
@bors
Copy link
Contributor

bors commented Mar 9, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 9, 2022
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 11, 2022
@name1e5s name1e5s force-pushed the fix/strip_prefix_panic branch 2 times, most recently from 9b061f5 to 9e07f54 Compare March 19, 2022 14:06
@name1e5s
Copy link
Contributor Author

After testing on my new device with windows 11 installed, I found the problem may belongs to the refactoring after the small fix. The fix itself is okay. I'll find out why the refactoring breaks 2 other tests.
Screenshot for testing on my branch:
90GWET4IMWQY8GRLKF%JE
The failing tests on my branch also failed on master, still investgating the reason.
Screenshot for testing on master:
SDON`GG_RO2LI65O{I~LONM

@ChrisDenton
Copy link
Member

test_windows_absolute should be fixed by #94650. I'd guess windows_exe_resolver is failing for you because you don't have developer mode enabled in the Windows settings? In either case they shouldn't block this PR. Btw, you can use the --test-args parameter to only run relevant tests.

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 11, 2022
@bors
Copy link
Contributor

bors commented Apr 23, 2022

☔ The latest upstream changes (presumably #94887) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon
Copy link
Member

Ping from triage:
@name1e5s #94650 has been merged - can you please post your status on this PR?

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 8, 2022
@name1e5s
Copy link
Contributor Author

name1e5s commented May 8, 2022

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 8, 2022
@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 8, 2022

📌 Commit b87dd75 has been approved by Mark-Simulacrum

@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 May 8, 2022
@bors
Copy link
Contributor

bors commented May 8, 2022

⌛ Testing commit b87dd75 with merge 83322c5...

@bors
Copy link
Contributor

bors commented May 8, 2022

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 83322c5 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 8, 2022
@bors bors merged commit 83322c5 into rust-lang:master May 8, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 8, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (83322c5): comparison url.

Summary: This benchmark run did not return any relevant results.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Path::strip_prefix may panic when a path consists only of a prefix component