-
Notifications
You must be signed in to change notification settings - Fork 255
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
test: remove some useless cases in the test #1485
Conversation
accounts-db/src/append_vec.rs
Outdated
|
||
// we can observe crafted value by ref | ||
{ | ||
let executable_bool: &bool = &account.account_meta.executable; | ||
// Depending on use, *executable_bool can be truthy or falsy due to direct memory manipulation | ||
// assert_eq! thinks *executable_bool is equal to false but the if condition thinks it's not, contradictorily. | ||
assert!(!*executable_bool); | ||
#[cfg(not(target_arch = "aarch64"))] | ||
{ | ||
const FALSE: bool = false; // keep clippy happy | ||
if *executable_bool == FALSE { | ||
panic!("This didn't occur if this test passed."); | ||
} | ||
} | ||
assert_eq!(*account.ref_executable_byte(), crafted_executable); | ||
} | ||
|
||
// we can NOT observe crafted value by value | ||
{ | ||
let executable_bool: bool = account.executable(); | ||
assert!(!executable_bool); | ||
assert_eq!(account.get_executable_byte(), 0); // Wow, not crafted_executable! | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should remove this whole thing. At most, only the part that's protected by the target_arch:
#[cfg(not(target_arch = "aarch64"))]
{
const FALSE: bool = false; // keep clippy happy
if *executable_bool == FALSE {
panic!("This didn't occur if this test passed.");
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I understand correctly, the executable_bool
has been corrupted because we forcibly write a byte into a bool. If we can catch it by sanitize_executable
, I guess we don't need to care about the value 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe, let me explain the motive of these seemingly meaningless assertions.
Firstly, this is added here by me: solana-labs#7464 (comment) note that sanitization is run inside the following code (av.set_file(path);
).
so, from very the start, these assertions are worthless in strict sense as @yihau pointed out. The reason i added them is that i hoped i can detect UB behavior changes in the distant future for my pure curiosity.
so the dream has come true today after 4.5 years.
it was kind of fun to conclude to this: #1485 (comment) it was a good exercise for me to hunt down to the specific rust commit.
and the result of investigation indicates there's no way to observe this specifc UB anymore. so, I'd prefer removing the specific part @brooksprumo has narrowed down.
i'd like to see more ub changes in yet distant future and to dig in by leaving the others as-is as much as possible. thanks for understanding. :)
It probably would be good to root-cause what happened with |
ah! sorry, the first error version is |
I'll look around this today. so, this test is failing only in coverage with recent nightly as seen at #1309 |
never mind, i remember nightly is used only for coverage, not other ci steps... |
thanks for bisecting.
... so, this is the commit range of the nightly: |
I'm now pretty sure this is the commit which changed this test behavior: rust-lang/rust#122849 |
the pr started to omit emitting and lack of the attribute inhibits optimizations based on the assumption that there should be no undefined values https://llvm.org/docs/LangRef.html#parameter-attributes:
https://llvm.org/docs/LangRef.html#undefined-values:
i haven't actually dumped llvm ir but I think With this all background info, the conclusion is that: the test has been testing the existence of UB. And that UB was caused by optimizations leveraging |
Thanks for root-causing this, @ryoqun! |
okay! thank you! I just pushed a new update. only removed the platform specific part 🫡 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
Problem
some changes for bumping Rust version: #1309
test_new_from_file_crafted_executable
is failed onnightly-2024-05-02
(run on linux). I have bisected it. it looks like everything works fine beforenightly-2024-03-27
.the reproducible command is:
the error I got:
Summary of Changes
if I understand correctly, we tried to convert a byte to bool here. I think
assert!(!account.sanitize_executable());
has already covered the case and catch it. do we want to keep those undefined behaviors checking? I lean to remove them if we don't have similar use cases in the real world. (or maybe get them like a doc and don't need to run them)(thanks @brooksprumo for sharing the original issue solana-labs#26009)