Skip to content

install.ps1 crashes with Substring ArgumentOutOfRangeException on non-English Windows locale (Remove-IndexUrlCredentials) #7279

Closed

Description

@akkanee-chatanavin

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

  1. Set Windows system locale/region to Thai (or any non-English locale using
    linguistic/culture-aware string collation)
  2. Run: irm https://raw.githubusercontent.com/unslothai/unsloth/main/install.ps1 | iex
  3. Observe crash immediately after "gpu NVIDIA GPU detected", before PyTorch
    install begins

Activity

  1. added a commit that references this issue on Jul 22, 2026
    5308c24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions