Skip to content

fix(nsi): mask LANGID to 16-bit for reliable auto-detection - #4513

Merged
stweil merged 1 commit into
tesseract-ocr:mainfrom
eduardomozart:patch-2
Feb 21, 2026
Merged

stweil merged 1 commit into
tesseract-ocr:mainfrom
eduardomozart:patch-2

Conversation

@eduardomozart

Copy link
Copy Markdown
Contributor

Description

This PR fixes a bug in the NSIS installer where system language auto-detection fails on certain Windows environments.

The Problem

The current script calls kernel32::GetSystemDefaultLangID(). While a LANGID is technically a 16-bit value (short), the NSIS System::Call plugin can return it as a 32-bit integer.

In many cases, the upper bytes of the register contain "garbage" data (e.g., a return value of 1508361 instead of 1033). This causes all subsequent StrCmp checks to fail because the string comparison expects the exact 4-digit ID, resulting in no language being pre-selected during installation.

The Solution

I have added a bitwise AND operation (IntOp $0 $0 & 0xFFFF) immediately after the system call. This masks the value to 16 bits, discarding any high-byte noise and ensuring that $0 contains only the valid LANGID.

Changes

  • Modified .onInit in tesseract.nsi to include the bitwise mask.

Additional Information

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes NSIS installer language auto-detection on some Windows environments by ensuring the LANGID returned from GetSystemDefaultLangID() is treated as a 16-bit value before running StrCmp-based language selection.

Changes:

  • Mask the GetSystemDefaultLangID() result to 16 bits (& 0xFFFF) during .onInit to prevent high-byte noise from breaking language matching.

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

@stweil stweil 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.

Thank you.

@stweil
stweil merged commit bd0412c into tesseract-ocr:main Feb 21, 2026
5 checks passed
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
tesseract 5.5.3

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.

- [ ] `resource` blocks have been checked for updates.
<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* Fix typos by @szepeviktor in tesseract-ocr/tesseract#4497
* Fix missing closing tags in multi-page PAGE XML output by @stweil with @Copilot in tesseract-ocr/tesseract#4506
* Fix Apple CMAKE_SYSTEM_PROCESSOR not set when crosscompiling by @ppavacic in tesseract-ocr/tesseract#4503
* Remove outdated docker-compose.yml (Fixes #4492) by @Mohataseem89 in tesseract-ocr/tesseract#4509
* docs: document memory ownership and lifecycle in C-API by @markbus-ai in tesseract-ocr/tesseract#4511
* Add Portuguese language support and section descriptions (Windows installer) by @eduardomozart in tesseract-ocr/tesseract#4516
* Update Slovak language string in tesseract.nsi by @eduardomozart in tesseract-ocr/tesseract#4518
* fix(nsi): mask LANGID to 16-bit for reliable auto-detection by @eduardomozart in tesseract-ocr/tesseract#4513
* Add GitHub Copilot instructions by @stweil with @Copilot in tesseract-ocr/tesseract#4508
* Correct mutex call to prevent multiple instances by @eduardomozart in tesseract-ocr/tesseract#4517
* Update versions of GitHub actions by @stweil in tesseract-ocr/tesseract#4522
* Bump microsoft/setup-msbuild from 2 to 3 by @dependabot[bot] in tesseract-ocr/tesseract#4533
* Use asciidoctor instead of asciidoc-py for manpage generation by @amitdo with @Copilot in tesseract-ocr/tesseract#4534
* Bump actions/upload-artifact from 4 to 7 by @dependabot[bot] in tesseract-ocr/tesseract#4545
* autotools: Fix linker warning on macOS by @stweil in tesseract-ocr/tesseract#4559
* Fix compiler warning on macOS by @stweil in tesseract-ocr/tesseract#4558
* Cmake cleanup by @zdenop in tesseract-ocr/tesseract#4562
* Remove SW_BUILD option from CMake and CI by @amitdo with @Copilot in tesseract-ocr/tesseract#4566
* Modernize code by @stweil in tesseract-ocr/tesseract#4561
* Remove some files by @stweil in tesseract-ocr/tesseract#4569
* Modernize more code by @stweil in tesseract-ocr/tesseract#4568
* Fix compiler warnings (-Wold-style-cast)  by @stweil in tesseract-ocr/tesseract#4571
* Fix some compiler warnings (-Wunused-parameter) by @stweil in tesseract-ocr/tesseract#4570
* ci: Improve installer for windows by @stweil in tesseract-ocr/tesseract#4572
* Fix several issues reported by Codacy (including real bugs) by @stweil in tesseract-ocr/tesseract#4573
* Bump actions/checkout from 6 to 7 by @dependabot[bot] in tesseract-ocr/tesseract#4574
* Fix crash when LSTM is missing in disabled-legacy build (#4448) by @gaurav0107 in tesseract-ocr/tesseract#4563
* ci: Remove unused ilammy/setup-nasm by @stweil in tesseract-ocr/tesseract#4575
* autotools: Simplify Makefile rules by @stweil in tesseract-ocr/tesseract#4579
* Fix memory-safety issues in .traineddata deserialization by @stweil in tesseract-ocr/tesseract#4581
* Handle send() failures in SVNetwork::Flush by @Ramya-9353 in tesseract-ocr/tesseract#4576
* Small code improvements by @stweil in tesseract-ocr/tesseract#4585
* doc: Add comprehensive PARAMETERS section to the tesseract man page by @stweil with @Copilot in tesseract-ocr/tesseract#4526
* Fix integer overflow in LSTM Convolve and Reconfig deserialization by @stweil in tesseract-ocr/tesseract#4588

## New Contributors
* @szepeviktor made their first contribution in tesseract-ocr/tesseract#4497
* @ppavacic made their first contribution in tesseract-ocr/tesseract#4503
* @Mohataseem89 made their first contribution in tesseract-ocr/tesseract#4509
* @markbus-ai made their first contribution in tesseract-ocr/tesseract#4511
* @eduardomozart made their first contribution in tesseract-ocr/tesseract#4516
* @gaurav0107 made their first contribution in tesseract-ocr/tesseract#4563
* @Ramya-9353 made their first contribution in tesseract-ocr/tesseract#4576

**Full Changelog**: https://github.com/tesseract-ocr/tesseract/compare/5.5.2...5.5.3</pre>
  <p>View the full release notes at <a href="https://github.com/tesseract-ocr/tesseract/releases/tag/5.5.3">https://github.com/tesseract-ocr/tesseract/releases/tag/5.5.3</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!15091
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