Skip to content

Fix Windows argument encoding by fetching UTF-8 command line#2293

Open
alaotach wants to merge 1 commit into
CCExtractor:masterfrom
alaotach:fix-windows-utf8-argv
Open

Fix Windows argument encoding by fetching UTF-8 command line#2293
alaotach wants to merge 1 commit into
CCExtractor:masterfrom
alaotach:fix-windows-utf8-argv

Conversation

@alaotach

@alaotach alaotach commented Jul 8, 2026

Copy link
Copy Markdown

[FIX] Resolve Windows ANSI argument mangling for non-ASCII paths

In raising this pull request, I confirm the following (please check boxes):
Reason for this PR:

  • This PR adds new functionality.
  • This PR fixes a bug that I have personally experienced or that a real user has reported and for which a sample exists.
  • This PR is porting code from C to Rust.

Sanity check:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • If the PR adds new functionality, I've added it to the changelog. If it's just a bug fix, I have NOT added it to the changelog.
  • I am NOT adding new C code unless it's to fix an existing, reproducible bug.

Fixes

Closes #2284

Problem

On Windows, the standard main(int argc, char *argv[]) entry point receives arguments encoded in the system's local legacy ANSI code page (e.g., CP-1252), not UTF-8.
indows ANSI argument mangling for non-ASCII paths

In raising this pull request, I confirm the following (please check boxes):
Reason for this PR:

  • This PR adds new functionality.
  • This PR fixes a bug that I have personally experienced or that a real user has reported and for which a sample exists.
  • This PR is porting code from C to Rust.

Sanity check:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • If the PR adds new functionality, I've added it to the changelog. If it's just a bug fix, I have NOT added it to the changelog.
  • I am NOT adding new C code unless it's to fix an existing, reproducible bug.

Fixes

Closes #2284

Problem

On Windows, the standard main(int argc, char *argv[]) entry point receives arguments encoded in the system's local legacy ANSI code page (e.g., CP-1252), not UTF-8.

When these arguments are passed to the new Rust parameter parser (ccxr_parse_parameters), Rust strictly expects UTF-8 strings and attempts to parse them using to_string_lossy(). Because non-ASCII ANSI characters (like the £ symbol, which is 0xA3) are invalid UTF-8 byte sequences, they get gracefully replaced with the Unicode Replacement Character (U+FFFD). When printed back to the console, this manifests as mangled, permanently mangling the file path and preventing CCExtractor from opening the file.

Fix

Added a Windows-specific #ifdef _WIN32 block at the very top of main() in ccextractor.c to intercept and sanitize the arguments.

It uses the native Windows APIs GetCommandLineW() and CommandLineToArgvW() to fetch the raw UTF-16 Unicode command line, safely converts the wide strings to standard UTF-8 using WideCharToMultiByte(), and dynamically overrides the legacy argv array before it is passed to the rest of the application.

This perfectly preserves all non-ASCII characters without changing the Rust API, breaking backwards compatibility for libraries, or changing the main entry point signature.

Repro instructions

  1. On a standard Windows installation without global UTF-8 beta features enabled, rename any video file to include the £ symbol. Example: £5 Million Restoration.ts.
  2. Run CCExtractor against it: ccextractorwinfull.exe "£5 Million Restoration.ts".
  3. Before fix: CCExtractor fails with Error: Failed to open one of the input file(s): File does not exist. and prints the mangled input file name as �5 Million Restoration.ts.
  4. After fix: CCExtractor successfully parses the £ symbol, natively locates the file, and proceeds to extract the captions.

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.

Windows: Cannot open file - UNC path with Unicode character

1 participant