Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Implement fd_filestat_set_size using libstd #47

Merged
merged 2 commits into from
Aug 8, 2019

Conversation

marmistrz
Copy link
Member

This PR bases on #42 & #46.

@@ -766,11 +766,7 @@ pub(crate) fn fd_filestat_set_size(
.and_then(|fe| fe.fd_object.descriptor.as_file())?;

let st_size = dec_filesize(st_size);
if st_size > i64::max_value() as u64 {
return Err(host::__WASI_E2BIG);
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, are you sure it is wise to remove this check? At a quick glance, std::fs::File::set_len which internally calls std::sys::*::fs::File::truncate does not perform this check. I might be mistaken here though! Please correct me if that's the case. If I'm right, however, I think we should leave this check in the code for better error signalling to the Wasm app. @sunfishcode @alexcrichton thoughts?

Copy link
Member Author

@marmistrz marmistrz Aug 5, 2019

Choose a reason for hiding this comment

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

You're right: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/fs.rs#L552-L559
But isn't it a bug in libstd that a silent overflow occurs instead of an error being reported? (off64_t is int64_t on my system)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes if libstd isn't doing a proper cast check then libstd should be where this error is generated for sure, sounds like a bug!

Copy link
Member

Choose a reason for hiding this comment

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

Could we then leave the check as is for now and in the meantime, submit a bug and a patch to libstd? Sounds like the best option to me in the short term :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll submit the bug and make the patch to libstd tomorrow :)

Copy link
Member

Choose a reason for hiding this comment

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

Awesome, thanks! :-)

Copy link
Member

Choose a reason for hiding this comment

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

@marmistrz after you submit the patch and bring back the check in wasi-common, could you add a comment with a link to the libstd’s patch explaining that when it lands and stabilises we’ll remove it altogether?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@marmistrz
Copy link
Member Author

I rebased the change upon the new revision of #46.

@kubkon
Copy link
Member

kubkon commented Aug 8, 2019

Could you rebase onto master? Otherwise, the commit this PR is based on will be repeated again after we merge it seems :-)

@marmistrz
Copy link
Member Author

Done.

@kubkon
Copy link
Member

kubkon commented Aug 8, 2019

LGTM!

@kubkon kubkon merged commit 4c9be59 into CraneStation:master Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants