Skip to content

Fix off-by-one in expandShortPathNative truncating last path character on Windows#4359

Merged
cklin merged 1 commit intodependabot/npm_and_yarn/extensions/ql-vscode/koffi-2.15.2from
copilot/fix-unit-test-errors-koffy-upgrade
Apr 7, 2026
Merged

Fix off-by-one in expandShortPathNative truncating last path character on Windows#4359
cklin merged 1 commit intodependabot/npm_and_yarn/extensions/ql-vscode/koffi-2.15.2from
copilot/fix-unit-test-errors-koffy-upgrade

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

GetLongPathNameW returns the output string length excluding the null terminator, but the buffer slice used (result - 1) * 2, silently dropping the last character of every expanded path (e.g. textfile-with~tilde.txttextfile-with~tilde.tx).

This bug was latent until koffi 2.15.2 fixed its install script (18467bcc): -p/-d flags in the packaged install script were changed to the correct -P/-D, so the prebuilt native addon is now properly installed and koffi/indirect loads successfully. In 2.15.1, koffi/indirect failed to load (caught silently), masking the bug.

Fix:

- const longPath = buffer.toString("utf16le", 0, (result - 1) * 2);
+ const longPath = buffer.toString("utf16le", 0, result * 2);

@cklin cklin marked this pull request as ready for review April 7, 2026 18:47
@cklin cklin requested a review from a team as a code owner April 7, 2026 18:47
Copilot AI review requested due to automatic review settings April 7, 2026 18:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Windows-specific path expansion bug in expandShortPathNative where the last character of the expanded path was being truncated due to an off-by-one error when converting the UTF-16 buffer returned by GetLongPathNameW.

Changes:

  • Correct the buffer slice length used when decoding the GetLongPathNameW result (length excludes the null terminator, so no - 1 is needed).
Show a summary per file
File Description
extensions/ql-vscode/src/common/short-paths.ts Fixes UTF-16 buffer decoding length to avoid truncating the last character of expanded Windows paths.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@cklin cklin merged commit a0e327b into dependabot/npm_and_yarn/extensions/ql-vscode/koffi-2.15.2 Apr 7, 2026
33 checks passed
@cklin cklin deleted the copilot/fix-unit-test-errors-koffy-upgrade branch April 7, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants