Skip to content

Commit c15b0e4

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 c15b0e4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/windows.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::common::{for_each_token, run_command};
22
use crate::{Browser, BrowserOptions, Error, ErrorKind, Result, TargetType};
3-
use log::trace;
3+
use log::{error, trace};
44
use std::path::Path;
55
use std::process::Command;
66

@@ -57,8 +57,19 @@ pub(super) fn open_browser_internal(
5757
));
5858
}
5959

60+
let found_nul = cmdline_u16
61+
.iter()
62+
.position(|&c| c == 0)
63+
.unwrap_or(BUF_SIZE - 1);
64+
65+
let mut line_len = line_len as usize;
66+
if found_nul < line_len {
67+
error!("Broken AssocQueryStringW(), {found_nul} < {line_len} == {BUF_SIZE}");
68+
line_len = found_nul;
69+
}
70+
6071
use std::os::windows::ffi::OsStringExt;
61-
std::ffi::OsString::from_wide(&cmdline_u16[..(line_len - 1) as usize])
72+
std::ffi::OsString::from_wide(&cmdline_u16[..(line_len - 1)])
6273
.into_string()
6374
.map_err(|_err| {
6475
Error::new(

0 commit comments

Comments
 (0)