-
Notifications
You must be signed in to change notification settings - Fork 113
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
bitvec
contains unsound global state
#229
Comments
did you manage to reproduce this in a minimal repro? |
Unfortunately I don't have the time to create minimal reproductions. |
I have checked out librasn/rasn@5820db2, fixed the Cargo.toml (hopefully with no side effects): --- a/Cargo.toml
+++ b/Cargo.toml
@@ -45,7 +45,7 @@ bitvec = { version = "1.0.1", default-features = false, features = ["alloc"] }
rasn-derive = { version = "0.6.0", path = "macros", optional = true }
chrono = { version = "0.4.19", default-features = false, features = ["alloc"] }
konst = { version = "0.2.13", default-features = false }
-nom-bitvec = { package = "bitvec-nom", version = "0.2.0", git = "https://github.com/XAMPPRocky/nom-bitvec.git" }
+nom-bitvec = { package = "bitvec-nom2", version = "0.2.0", git = "https://github.com/XAMPPRocky/nom-bitvec.git" }
arrayvec = { version = "0.7.2", default-features = false }
either = { version = "1.8.0", default-features = false }
once_cell = { version = "1.16.0", default-features = false, features = ["race", "alloc"] } and was able to reproduce the failing tests. Then I threw out tests until I was down to two candidates where one would fail if both were active: To avoid missunderstandings with your test macro, I also rolled out the content: #[test]
fn test() {
unconstrained_aper();
ax_uper();
}
fn unconstrained_aper() {
println!("unconstrained_aper");
const EXPECTED: &[u8] = &[
0x82, 0x4A, 0xDF, 0xA3, 0x70, 0x0D, 0x00, 0x5A, 0x7B, 0x74, 0xF4, 0xD0,
0x02, 0x66, 0x11, 0x13, 0x4F, 0x2C, 0xB8, 0xFA, 0x6F, 0xE4, 0x10, 0xC5,
0xCB, 0x76, 0x2C, 0x1C, 0xB1, 0x6E, 0x09, 0x37, 0x0F, 0x2F, 0x20, 0x35,
0x01, 0x69, 0xED, 0xD3, 0xD3, 0x40, 0x10, 0x2D, 0x2C, 0x3B, 0x38, 0x68,
0x01, 0xA8, 0x0B, 0x4F, 0x6E, 0x9E, 0x9A, 0x02, 0x18, 0xB9, 0x6A, 0xDD,
0x8B, 0x16, 0x2C, 0x41, 0x69, 0xF5, 0xE7, 0x87, 0x70, 0x0C, 0x20, 0x59,
0x5B, 0xF7, 0x65, 0xE6, 0x10, 0xC5, 0xCB, 0x57, 0x2C, 0x1B, 0xB1, 0x6E,
];
let default: PersonnelRecord = PersonnelRecord::default();
assert_eq!(
EXPECTED,
rasn::uper::encode(&default).unwrap()
);
}
fn ax_uper() {
println!("ax_uper");
const EXPECTED: &[u8] = &[0x9e, 0x00, 0x06, 0x00, 0x04, 0x0a, 0x46, 0x90];
let default: Ax = Ax::default();
assert_eq!(
EXPECTED,
rasn::uper::encode(&default).unwrap()
);
} Now this is where things get interesting:
I had a brief look at your code and your index_map function looks broken: fn index_map() -> &'static alloc::collections::BTreeMap<u32, u32> {
static MAP: OnceBox<BTreeMap<u32, u32>> = OnceBox::new();
MAP.get_or_init(|| {
Box::new(
Self::CHARACTER_SET
.into_iter()
.copied()
.enumerate()
.map(|(i, e)| (e, i as u32))
.collect(),
)
})
} While
|
Thank you for investigating, we can close this and continue on the rasn repo. |
Similar to #228, I've noticed that I've been getting different results from bitvec depending on whether other code has run or not. For example if you clone librasn/rasn@5820db2 and run the following invocation it will pass, where as if you run the invocation below it,
ax_uper
will fail with a different encoding result. There's zero mutable static state in my crate and the only part that is getting corrupted is the encoding of the strings, which leads me to believe thatbitvec
is behaving incredibly odd.The text was updated successfully, but these errors were encountered: