Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Conversation

@pepyakin
Copy link
Contributor

I don't think this is particularly important, but shouldn't harm either.

I don't think this is particularly important, but shouldn't harm either.
@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Nov 11, 2020
@pepyakin pepyakin added A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. and removed A0-please_review Pull request needs code review. labels Nov 11, 2020
@pepyakin pepyakin mentioned this pull request Nov 11, 2020
3 tasks
#[no_mangle]
pub extern "C" fn validate_block(params: *const u8, len: u32) -> u64 {
let params = unsafe { parachain::load_params(params, len) };
let params = unsafe { parachain::load_params(params, len as u32) };
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the motivation here if len is already u32 per the function definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, I meant to cast it by usize 🙈 , I need to devote more attention to this PR.

@pepyakin
Copy link
Contributor Author

Hold on guys, the third time is the charm

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

If you want to do this correctly, please change the `load_params' function ;)

Otherwise this pr doesn't bring any value.

@pepyakin
Copy link
Contributor Author

Ok, I see your concern, had the same one. I chose the presented solution because the body of load_params requires usize anyway. So this would just move the cast down.

Also note, that this is not a destructive cast, since we never assume that the word size is below 32 bits. But if it were, then moving the cast won't help either, we would need to panic to somehow signal this destruction.

And finally, I would have argued that this PR has some value, something along the lines that the risk of UB coming from a broken signature is worse than potential trimming problems in 16 bits platforms yadyadyadya (🙈), but I am not myself completely sure that the root problem is a sufficiently realistic scenario.

So I am not sure if I am going to persue this PR. Feel free to close it.

@pepyakin
Copy link
Contributor Author

Oh, and look, the CI has passed xD

@pepyakin
Copy link
Contributor Author

Ok, Basti showed me another example where usize is used and I also found one in substrate and perhaps there are more.

I am closing this, but if anybody feels motivated enough to pick up, feel free to reopen or open another PR

@pepyakin pepyakin closed this Nov 11, 2020
@pepyakin pepyakin deleted the ser-beartrap branch November 11, 2020 11:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants