Environment
Bug
On a Windows machine with a non-English system locale/region (Thai, in my case),
install.ps1 crashes immediately after GPU detection, before the PyTorch install
step, with:
Exception calling "Substring" with "1" argument(s): "startIndex cannot be larger
than length of string. (Parameter 'startIndex')"
At install.ps1:2043 (or 2044 on latest main)
- …$host_ = if ($at -ge 0) { $authority.Substring($at + 1) } else …
Root cause
Remove-IndexUrlCredentials() computes:
$sep = $Url.IndexOf('://')
without specifying an ordinal string comparison. On a non-English Windows
culture, [string]::IndexOf(string) uses culture-aware (linguistic) comparison
by default, which can return the wrong index for a punctuation-only substring
like "://" (punctuation/symbols are treated as low-weight/ignorable in some
non-English collations). This causes $sep to resolve incorrectly, which
corrupts $scheme / $rest / $authority downstream, and $authority ends up empty
while $at (LastIndexOf('@')) still returns a stale/incorrect index, causing
Substring($at + 1) to exceed the (now-empty) string length.
Debug output confirms this:
[DEBUG] Url=[https://download.pytorch.org/whl/cu130] authority=[] at=[0]
scheme=[] rest=[ps://download.pytorch.org/whl/cu130]
Note "rest" is missing the leading "htt" — $Url.IndexOf('://') returned 0
instead of the correct value (5) for a plain https:// URL.
Fix
Use ordinal (not culture-aware) string operations in
Remove-IndexUrlCredentials, e.g.:
$sep = $Url.IndexOf('://', [System.StringComparison]::Ordinal)
and likewise for any other .IndexOf / .LastIndexOf calls on URLs in
install.ps1 that don't already specify StringComparison.Ordinal.
Workaround
Setting the current thread culture to Invariant before running the installer
avoids the crash:
[System.Threading.Thread]::CurrentThread.CurrentCulture =
[System.Globalization.CultureInfo]::InvariantCulture
[System.Threading.Thread]::CurrentThread.CurrentUICulture =
[System.Globalization.CultureInfo]::InvariantCulture
Steps to reproduce
- Set Windows system locale/region to Thai (or any non-English locale using
linguistic/culture-aware string collation)
- Run: irm https://raw.githubusercontent.com/unslothai/unsloth/main/install.ps1 | iex
- Observe crash immediately after "gpu NVIDIA GPU detected", before PyTorch
install begins
Environment
(also reproduced with
.\install.ps1 --localaftergit clone)Bug
On a Windows machine with a non-English system locale/region (Thai, in my case),
install.ps1 crashes immediately after GPU detection, before the PyTorch install
step, with:
Exception calling "Substring" with "1" argument(s): "startIndex cannot be larger
than length of string. (Parameter 'startIndex')"
At install.ps1:2043 (or 2044 on latest main)
Root cause
Remove-IndexUrlCredentials() computes:
without specifying an ordinal string comparison. On a non-English Windows
culture, [string]::IndexOf(string) uses culture-aware (linguistic) comparison
by default, which can return the wrong index for a punctuation-only substring
like "://" (punctuation/symbols are treated as low-weight/ignorable in some
non-English collations). This causes $sep to resolve incorrectly, which
corrupts $scheme / $rest / $authority downstream, and $authority ends up empty
while $at (LastIndexOf('@')) still returns a stale/incorrect index, causing
Substring($at + 1) to exceed the (now-empty) string length.
Debug output confirms this:
Note "rest" is missing the leading "htt" — $Url.IndexOf('://') returned 0
instead of the correct value (5) for a plain https:// URL.
Fix
Use ordinal (not culture-aware) string operations in
Remove-IndexUrlCredentials, e.g.:
and likewise for any other .IndexOf / .LastIndexOf calls on URLs in
install.ps1 that don't already specify StringComparison.Ordinal.
Workaround
Setting the current thread culture to Invariant before running the installer
avoids the crash:
Steps to reproduce
linguistic/culture-aware string collation)
install begins