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

std: Fix a bug on the wasm32-wasi target opening files #82804

Merged
merged 1 commit into from
Mar 14, 2021

Conversation

alexcrichton
Copy link
Member

This commit fixes an issue pointed out in #82758 where LTO changed the
behavior of a program. It turns out that LTO was not at fault here, it
simply uncovered an existing bug. The bindings to
__wasilibc_find_relpath assumed that the relative portion of the path
returned was always contained within thee input buf we passed in. This
isn't actually the case, however, and sometimes the relative portion of
the path may reference a sub-portion of the input string itself.

The fix here is to use the relative path pointer coming out of
__wasilibc_find_relpath as the source of truth. The buf used for
local storage is discarded in this function and the relative path is
copied out unconditionally. We might be able to get away with some
Cow-like business or such to avoid the extra allocation, but for now
this is probably the easiest patch to fix the original issue.

This commit fixes an issue pointed out in rust-lang#82758 where LTO changed the
behavior of a program. It turns out that LTO was not at fault here, it
simply uncovered an existing bug. The bindings to
`__wasilibc_find_relpath` assumed that the relative portion of the path
returned was always contained within thee input `buf` we passed in. This
isn't actually the case, however, and sometimes the relative portion of
the path may reference a sub-portion of the input string itself.

The fix here is to use the relative path pointer coming out of
`__wasilibc_find_relpath` as the source of truth. The `buf` used for
local storage is discarded in this function and the relative path is
copied out unconditionally. We might be able to get away with some
`Cow`-like business or such to avoid the extra allocation, but for now
this is probably the easiest patch to fix the original issue.
@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(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 Mar 5, 2021
@alexcrichton
Copy link
Member Author

Also, if possible, I'd like to nominate this for beta inclusion since this is a relatively serious bug for the wasi target

@LeSeulArtichaut LeSeulArtichaut added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Mar 5, 2021
@rustbot rustbot added the P-high High priority label Mar 10, 2021
@apiraino apiraino added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed P-high High priority labels Mar 10, 2021
@pnkfelix
Copy link
Member

pnkfelix commented Mar 11, 2021

Reviewed in T-compiler meeting.

@bors r+

@bors
Copy link
Contributor

bors commented Mar 11, 2021

📌 Commit d6b06b8 has been approved by pnkfelix

@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 Mar 11, 2021
@apiraino
Copy link
Contributor

beta backport discussed and delegated to T-libs-impl call on this. Approved for nightly.

(compiler meeting on Zulip).

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 11, 2021
std: Fix a bug on the wasm32-wasi target opening files

This commit fixes an issue pointed out in rust-lang#82758 where LTO changed the
behavior of a program. It turns out that LTO was not at fault here, it
simply uncovered an existing bug. The bindings to
`__wasilibc_find_relpath` assumed that the relative portion of the path
returned was always contained within thee input `buf` we passed in. This
isn't actually the case, however, and sometimes the relative portion of
the path may reference a sub-portion of the input string itself.

The fix here is to use the relative path pointer coming out of
`__wasilibc_find_relpath` as the source of truth. The `buf` used for
local storage is discarded in this function and the relative path is
copied out unconditionally. We might be able to get away with some
`Cow`-like business or such to avoid the extra allocation, but for now
this is probably the easiest patch to fix the original issue.
@bors
Copy link
Contributor

bors commented Mar 12, 2021

⌛ Testing commit d6b06b8 with merge 9e7307ab7817bc4fe561e6d0132326b035530137...

@bors
Copy link
Contributor

bors commented Mar 12, 2021

💥 Test timed out

@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 Mar 12, 2021
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@m-ou-se
Copy link
Member

m-ou-se commented Mar 13, 2021

@bors retry

@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 Mar 13, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 13, 2021
std: Fix a bug on the wasm32-wasi target opening files

This commit fixes an issue pointed out in rust-lang#82758 where LTO changed the
behavior of a program. It turns out that LTO was not at fault here, it
simply uncovered an existing bug. The bindings to
`__wasilibc_find_relpath` assumed that the relative portion of the path
returned was always contained within thee input `buf` we passed in. This
isn't actually the case, however, and sometimes the relative portion of
the path may reference a sub-portion of the input string itself.

The fix here is to use the relative path pointer coming out of
`__wasilibc_find_relpath` as the source of truth. The `buf` used for
local storage is discarded in this function and the relative path is
copied out unconditionally. We might be able to get away with some
`Cow`-like business or such to avoid the extra allocation, but for now
this is probably the easiest patch to fix the original issue.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 14, 2021
Rollup of 10 pull requests

Successful merges:

 - rust-lang#81465 (Add documentation about formatting `Duration` values)
 - rust-lang#82121 (Implement Extend and FromIterator for OsString)
 - rust-lang#82617 (Document `everybody_loops`)
 - rust-lang#82789 (Get with field index from pattern slice instead of directly indexing)
 - rust-lang#82798 (Rename `rustdoc` to `rustdoc::all`)
 - rust-lang#82804 (std: Fix a bug on the wasm32-wasi target opening files)
 - rust-lang#82943 (Demonstrate best practice for feeding stdin of a child processes)
 - rust-lang#83066 (Add `reverse` search alias for Iterator::rev())
 - rust-lang#83070 (Update cargo)
 - rust-lang#83081 (Fix panic message of `assert_failed_inner`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9ce0820 into rust-lang:master Mar 14, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 14, 2021
@pnkfelix
Copy link
Member

Discussed in this week's T-compiler triage meeting. Beta backport approved.

@pnkfelix pnkfelix added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Mar 18, 2021
@Mark-Simulacrum Mark-Simulacrum removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Mar 22, 2021
@Mark-Simulacrum Mark-Simulacrum modified the milestones: 1.52.0, 1.51.0 Mar 22, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 22, 2021
…imulacrum

[stable] 1.51.0 release

Also includes backports of the release notes, as well as:

*  SplitInclusive is public API rust-lang#83372
*  std: Fix a bug on the wasm32-wasi target opening files rust-lang#82804
*  Fix io::copy specialization using copy_file_range when writer was opened with O_APPEND rust-lang#82417

r? `@Mark-Simulacrum`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. 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.

10 participants