Skip to content

Automatically determine the currect download URL also in Firefox again - #95

Merged
dscho merged 1 commit into
mainfrom
detect-cpu-arch-for-download-link-also-in-firefox
Sep 1, 2026
Merged

dscho merged 1 commit into
mainfrom
detect-cpu-arch-for-download-link-also-in-firefox

Conversation

@dscho

@dscho dscho commented Aug 29, 2026

Copy link
Copy Markdown
Member

When Git for Windows started to distribute ARM64 binaries along the x86 and x64 ones, the logic to choose the appropriate download URL on Git for Windows' home page was adjusted in 607efe1 to detect when running on Windows/ARM64.

Sadly, this new logic does not work on Firefox, and while the commit message of above-mentioned commit omits mentioning it, this was immediately spotted as a problem and there was an extensive discussion revolving around it, with the sad outcome that the download button does not link directly to the installer in Firefox, see #61.

In the meantime, I stumbled across a neat trick to determine the CPU architecture that is used in the WebAssembly version of TensorFlow, which I traced all the way back to google/XNNPACK@466b52379d.

Technically, it does not allow us to determine whether the CPU architecture is ARM64 (but only if it is not x86). For our purposes, this is enough for now: At present, Windows only supports Intel-compatible CPU architectures and ARM64. Let's use this trick as a fallback on Firefox (and really, any browser that isn't (based on) Chrome).

When Git for Windows started to distribute ARM64 binaries along the
x86 and x64 ones, the logic to choose the appropriate download URL on
Git for Windows' home page was adjusted in 607efe1 (Drop 32-bit and add
ARM64 architecture check, 2025-04-26) to detect when running on
Windows/ARM64.

Sadly, this new logic does not work on Firefox, and while the commit
message of above-mentioned commit omits mentioning it, this was
immediately spotted as a problem and there was an extensive discussion
revolving around it, with the sad outcome that the download button does
not link directly to the installer in Firefox, see
#61.

In the meantime, I stumbled across a neat trick to determine the CPU
architecture that is used in the WebAssembly version of TensorFlow,
which I traced all the way back to this commit:
google/XNNPACK@466b52379d (Use GEMM/IGEMM
micro-kernels with Swizzle on WAsm SIMD, 2019-10-09).

Technically, it does not allow us to determine whether the CPU
architecture is ARM64 (but only if it is not x86). For our purposes,
this is enough for now: At present, Windows only supports
Intel-compatible CPU architectures and ARM64. Let's use this trick as a
fallback on Firefox (and really, any browser that isn't (based on)
Chrome).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
dscho requested a review from dennisameling August 29, 2026 18:28
@dscho dscho self-assigned this Aug 29, 2026

@dennisameling dennisameling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, thanks! Regarding Firefox, I think there's some privacy concerns around the navigator.userAgentData API: https://bugzilla.mozilla.org/show_bug.cgi?id=1750143.

The XNNPACK workaround is very creative for sure 👀 Confirming that it works correctly on Firefox arm64:

Image

@dscho
dscho merged commit 62f1966 into main Sep 1, 2026
1 check passed
@dscho
dscho deleted the detect-cpu-arch-for-download-link-also-in-firefox branch September 1, 2026 05:35
@cremor

cremor commented Sep 9, 2026

Copy link
Copy Markdown

edit: Sorry, it look like this change isn't live yet? Then I don't understand why the download is suddenly broken on Firefox (it worked fine a few weeks ago). When will this be deployed?

@dscho It looks like this isn't working. The download button on the homepage now downloads the ARM version of Git for me when using Firefox, even though I'm on x64.

Edge still correctly downloads the x64 version.

Firefox 155.0.1 (64-Bit)
Windows 11 Enterprise 25H2
12th Gen Intel(R) Core(TM) i7-12700H (2.30 GHz)

@dscho

dscho commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

edit: Sorry, it look like this change isn't live yet? Then I don't understand why the download is suddenly broken on Firefox (it worked fine a few weeks ago). When will this be deployed?

No, this is deployed. And I see the same behavior, it also suggests for me to download the ARM64 version, whether I am on ARM64 or not. Will investigate.

@dscho It looks like this isn't working. The download button on the homepage now downloads the ARM version of Git for me when using Firefox, even though I'm on x64.

Edge still correctly downloads the x64 version.

Firefox 155.0.1 (64-Bit) Windows 11 Enterprise 25H2 12th Gen Intel(R) Core(TM) i7-12700H (2.30 GHz)

@dscho

dscho commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

Aha! Running hugo --minify turns Infinity to 1/0 in JavaScript code. However, Infinity - Infinity is what we need here, not 1/0 - 1/0 (yes, the result is different, crucially so)!

dscho added a commit that referenced this pull request Sep 9, 2026
Running `hugo --minify`, as the regular deployment workflow does,
replaces `Infinity` with the shorter `1/0`.

This transformation is correct in general, but we just introduced logic
that exploits undefined behavior that is different between x64 and
ARM64, i.e. the exact outcome of `Infinity - Infinity`, which is
_different_ on these CPU architectures, whereas `1/0 - 1/0` is _not_.

As a consequence, the logic failed in the deployed website, and _all_
users, even those with a x64 OS were offered the ARM64 version, see
#95 (comment)

Fix this by switching to `window.Infinity`, which `--minify` leaves
alone, and which still exposes the same behavioral difference between
these CPU architectures that we want to use as a tell-tale.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho

dscho commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@cremor I deployed a fix; It should work now!

@cremor

cremor commented Sep 9, 2026

Copy link
Copy Markdown

I can confirm the fix, thanks!

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