W343-3

W343-3 designates a bug that affects the Microsoft Windows version of NetHack 3.4.3. The DevTeam lists the status of this bug as "Help", meaning they do not know the cause. It is unclear why: they have been notified, and a patch is available.

Nature of the bug
The bug has been reported on Polish and Russian editions of Windows 2000 and on a Czech version of Windows XP. It has been duplicated on an American Windows XP by changing a language setting. A screenshot is available.

Bug W343-3 really comprises two distinct and unrelated bugs. One is a simple character set issue: many non-USA PCs are configured with different character sets, and seven symbols may look different. This issue is more fully detailed in the IBMgraphics article.

The more serious bug is that some characters appear as strange symbols or blank squares. This is not actually a bug in NetHack, but in Windows. The rest of this article will deal with this bug.

Cause of the bug
The bug is a flaw in the Windows WriteConsoleOutputCharacterA API. When its configured code page is other than 437 or 850, many non-ASCII characters can show up incorrectly.

The bug occurs when four conditions are met:


 * The version of Windows is Windows NT or one of its descendants.
 * A bitmap font, rather than Lucida Console, is selected.
 * The command shell is running in a window, rather than full screen.
 * The language for non-Unicode programs is set to one whose OEM code page is anything other than 437 or 850.  Basically this means any East European language, whether it uses Greek, Cyrillic or Latin writing.

No API other than WriteConsoleOutputCharacterA is known to be affected. In particular, the Unicode variant WriteConsoleOutputCharacterW works correctly.

Versions affected
NetHack 3.4.3 is known to have this bug. Because NetHack 3.1.1 through 3.1.3 also use the flawed API, it is likely that they have it as well. NetHack 3.2.0 through 3.4.2 use different APIs, and do not have this bug.

Patch
A patch is available to fix this bug; but no binaries or variants other than Spanish NetHack are known to incorporate it.

The patch fixes the API issue by detecting when it is running on an NT-based version of Windows, and using the Unicode API instead, avoiding the Windows bug. It fixes the character set issue as well (see IBMgraphics) by allowing less-extensive variants of IBMgraphics to be set, avoiding the characters that can vary among code pages.

The patch was posted to rec.games.roguelike.nethack as four articles:


 * Part 1 describes the API issue and provides detailed instructions to duplicate it, and a small test program to demonstrate the bug.
 * Part 2 describes the character set issue.
 * Part 3 contains the patch itself.
 * Part 4 is a description of each change the patch makes.