nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

7670 - Fixed Windows chromium-args 260 character limit

Open sirisian opened this issue 4 years ago • 4 comments

https://github.com/nwjs/nw.js/issues/7670

Untested change for handling ExpandEnvironmentStrings on Windows. The original code limited chromium-args to 260 characters.

Note, I haven't tried to compile this, and my C++ is rusty. Figured I'd get this started to speed along a fix. It might be fine.

sirisian avatar Feb 05 '21 18:02 sirisian

ExpandEnvironmentStrings returns the size of the expected character array, so if it's say 10K characters that are required for szEnvPath then it needs to be reallocated on the stack to the size of the returned value. I used a loop here to rerun ExpandEnvironmentStrings with the resized character array. This seemed like the most elegant way to write it since the return value needs to be checked again.

sirisian avatar Feb 12 '21 18:02 sirisian

Is this PR still valid? this bug is still present in 0.91.0

zkrige avatar Sep 25 '24 06:09 zkrige

@rogerwang Feel free to close this and rewrite it without the do while loop. Glancing at the code you're right that I overcomplicated it.

You can actually just call the function with nullptr and 0 to get back the required size, then just allocated to that size. Something like this:

DWORD requiredSize = ExpandEnvironmentStringsW(input.c_str(), nullptr, 0);

if (requiredSize > 0) {
    std::wstring output(requiredSize, L'\0');
    DWORD expandedSize = ExpandEnvironmentStringsW(input.c_str(), &output[0], requiredSize);
    
    if (expandedSize > 0 && expandedSize <= requiredSize) {
        // Trim null terminator
        output.resize(expandedSize - 1);
        // ...
    } else {
        // Handle error
    }
} else {
    // Handle error
}

sirisian avatar Oct 01 '24 01:10 sirisian

This bug is still present in 0.92.0 - it would be fantastic if it could be resolved soonest

zkrige avatar Oct 01 '24 05:10 zkrige

close as fixed.

rogerwang avatar May 05 '25 02:05 rogerwang