keyring-rs icon indicating copy to clipboard operation
keyring-rs copied to clipboard

Error code 1783 on Windows

Open NEO97online opened this issue 2 years ago • 1 comments

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.

NEO97online avatar May 26 '22 15:05 NEO97online

@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.

brotskydotcom avatar Aug 07 '22 06:08 brotskydotcom

@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.

brotskydotcom avatar Sep 06 '22 16:09 brotskydotcom

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 💥

Alexei-Barnes avatar Jan 16 '23 16:01 Alexei-Barnes

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.

brotskydotcom avatar Jan 16 '23 16:01 brotskydotcom

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.

Alexei-Barnes avatar Jan 16 '23 16:01 Alexei-Barnes

I'll investigate a bit and create a PR.

Alexei-Barnes avatar Jan 16 '23 16:01 Alexei-Barnes

I appreciate your looking at this!

brotskydotcom avatar Jan 16 '23 16:01 brotskydotcom

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.

Alexei-Barnes avatar Jan 16 '23 16:01 Alexei-Barnes

PR open.

Alexei-Barnes avatar Jan 16 '23 16:01 Alexei-Barnes