Skip to content

Commit d0a4f70

Browse files
committed
HACK: windows: Work around broken AssocQueryStringW() not returning actual string length
Wine has a bug where calling `AssocQueryStringW()` with a buffer doesn't actually update `line_len` to the actual number of bytes returned, resulting in `webbrowser` failing on seeing a bunch of unexpected `nul` bytes in the array: Error { kind: InvalidInput, message: "nul byte found in provided data" } This is reported and fixed upstream via: https://bugs.winehq.org/show_bug.cgi?id=59402 https://gitlab.winehq.org/wine/wine/-/merge_requests/10072 I still need to write tests to get it merged, and even then it might take a while to trickle down into releases and ultimately Steam Proton. Hence have this ugly workaround to catch cases where `nul` characters end up in the output and reduce the string length by hand.
1 parent 94baf04 commit d0a4f70

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/windows.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,22 @@ pub(super) fn open_browser_internal(
5757
));
5858
}
5959

60+
let mut line_len = line_len as usize;
61+
62+
// If line_len wasn't updated, this might be a broken AssocQueryStringW() implementation in wine:
63+
// https://bugs.winehq.org/show_bug.cgi?id=59402
64+
// In that case, find the NUL terminator ourselves.
65+
if line_len == BUF_SIZE {
66+
if let Some(found_nul) = cmdline_u16.iter().position(|&c| c == 0) {
67+
trace!(
68+
"Broken AssocQueryStringW(), manually string length determined at {found_nul}"
69+
);
70+
line_len = found_nul + 1;
71+
}
72+
}
73+
6074
use std::os::windows::ffi::OsStringExt;
61-
std::ffi::OsString::from_wide(&cmdline_u16[..(line_len - 1) as usize])
75+
std::ffi::OsString::from_wide(&cmdline_u16[..(line_len - 1)])
6276
.into_string()
6377
.map_err(|_err| {
6478
Error::new(

0 commit comments

Comments
 (0)