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: throw error when asset is empty #3379

Merged
merged 7 commits into from
Dec 17, 2024
Merged

Conversation

jkelleyrtp
Copy link
Member

While working on the docsite I found that if you passed asset!("") on accident, then we'd end up copying the entire current directory over. This is not good. It also causes new dx serve to hang infinitely since we get stuck on clearing the assets dir.

This fixes that by throwing an error if the path is empty and ensuring the final path is a child of the crate.

@jkelleyrtp jkelleyrtp requested a review from ealmloff December 17, 2024 21:59
@jkelleyrtp jkelleyrtp added the bug Something isn't working label Dec 17, 2024
path: input.clone(),
})
let path =
std::path::absolute(manifest_dir.join(raw.trim_start_matches('/'))).map_err(|err| {
Copy link
Member

Choose a reason for hiding this comment

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

std::path::absolute does not check if the path exists (unlike canonicalize) so this error does not trigger when the path doesn't exist


// 3. Ensure the path is not the current dir or exist outside the current dir
if path == manifest_dir || !path.starts_with(manifest_dir) || !path.exists() {
return Err(AssetParseError::InvalidPath { path });
Copy link
Member

Choose a reason for hiding this comment

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

Instead, this case triggers which gives the wrong error message

@ealmloff
Copy link
Member

Looks good overall once the error message is fixed. I don't think the first if statement to check if the path should change behavior because the other changes have more robust checks that thow errors for asset!(""), asset!("/../"), asset!("/"), etc

@jkelleyrtp jkelleyrtp merged commit 94b8647 into main Dec 17, 2024
15 of 17 checks passed
@jkelleyrtp jkelleyrtp deleted the jk/prevent-asset-full-dir branch December 17, 2024 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants