keyring-rs
keyring-rs copied to clipboard
Error code 1783 on Windows
When trying to add a keyring entry on Windows, I get Error code 1783
which seems to correlate to RPC_X_BAD_STUB_DATA
in winapi.
@auderer Can you provide a minimal test program that reproduces this issue? I can't reproduce it with cli
example. Please be sure to provide the Win10 system details.
@auderer Since I haven't heard from you I'm going to close this issue. I will reopen it if you can provide a repro.
I've reproduced this by providing a password that was 1,461 characters long. The reason you get this is that the validation checks if the password is over the max size (512*5 bytes) by checking the length of the string in UTF-16, in characters. Later when we store the data, we then pay the 2:1 ratio of bytes:characters, which means we exceed the allowed storage length and 💥
Thanks very much, @Alexei-Barnes, for reproducing this, and even more for tracking down the logic error! I'll get this fixed in both v2 and the upcoming v3. Or feel free to submit a PR if you're so inclined.
Hurmm, though, actually, I'm unconvinced by my explanation now that I've provided it.
From &str
docs;
pub const fn [len](https://doc.rust-lang.org/std/primitive.str.html#method.len)(&self) -> [usize](https://doc.rust-lang.org/std/primitive.usize.html)
Returns the length of self.
This length is in bytes, not [char](https://doc.rust-lang.org/std/primitive.char.html)s or graphemes. In other words, it might not be what a human considers the length of the string.
I'll investigate a bit and create a PR.
I appreciate your looking at this!
OK password
in the context of the test is UTF-8, and then we serialize it as UTF-16, so that's the cause of the behaviour. Storing as UTF-16 is probably correct on Windows, so we simply need to check the size in bytes of the password encoded as UTF-16. * 2
won't work for wide characters, so .encode_utf16().count()
is probably right.
PR open.