Skip to content

Conversation

@xezon
Copy link

@xezon xezon commented Nov 7, 2025

FontLibrary::getFont allows creating fonts with 0 size, but they will be malformed and crash on use.

This happens because FontCharsClass::Create_GDI_Font will create a null GDIBitmap when the font size is zero.

 >	generalszh.exe!FontCharsClass::Store_GDI_Char(wchar_t ch) Line 1391	C++
 	generalszh.exe!FontCharsClass::Get_Char_Data(wchar_t ch) Line 1256	C++
 	generalszh.exe!FontCharsClass::Get_Char_Spacing(wchar_t ch) Line 1289	C++
 	generalszh.exe!Render2DSentenceClass::Allocate_New_Surface(const wchar_t * text, bool justCalcExtents) Line 645	C++
 	generalszh.exe!Render2DSentenceClass::Build_Sentence_Not_Centered(const wchar_t * text, int * hkX, int * hkY, bool justCalcExtents) Line 1005	C++
 	generalszh.exe!Render2DSentenceClass::Get_Formatted_Text_Extents(const wchar_t * text) Line 289	C++
 	generalszh.exe!W3DDisplayString::computeExtents() Line 362	C++
 	generalszh.exe!W3DDisplayString::setFont(GameFont * font) Line 308	C++
 	generalszh.exe!InGameUI::refreshRenderFpsResources() Line 5947	C++
 	generalszh.exe!InGameUI::refreshCustomUiResources() Line 5909	C++
 	generalszh.exe!InGameUI::reset() Line 2071	C++
 	generalszh.exe!W3DInGameUI::reset() Line 381	C++
 	generalszh.exe!GameClient::reset() Line 457	C++
 	generalszh.exe!W3DGameClient::reset() Line 106	C++
 	generalszh.exe!SubsystemInterfaceList::resetAll() Line 183	C++
 	generalszh.exe!GameEngine::resetSubsystems() Line 812	C++
 	generalszh.exe!GameEngine::init() Line 769	C++
 	generalszh.exe!Win32GameEngine::init() Line 66	C++
 	generalszh.exe!GameMain() Line 46	C++
 	generalszh.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 903	C++
 	[External Code]	
 	[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]	

TODO

  • Replicate in Generals

@xezon xezon added this to the Stability fixes milestone Nov 7, 2025
@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker System Is Systems related Fix Is fixing something, but is not user facing labels Nov 7, 2025
if( font == NULL )
return FALSE;

if ((UnsignedInt)font->pointSize > 100) //sanity check the size - anything over 100 is probably wrong. -MW
Copy link
Author

Choose a reason for hiding this comment

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

I put this test higher up the call chain for simplicity. getFont is the only caller of loadFontData.

@xezon xezon added the Stability Concerns stability of the runtime label Nov 8, 2025
@xezon xezon force-pushed the xezon/fix-font-with-zero-size branch from b232a6a to ae98250 Compare November 8, 2025 18:11
@xezon xezon changed the title fix(font): Prevent possibility of creating invalid fonts with zero size fix(font): Handle malformed fonts without crashing the game Nov 8, 2025
@xezon xezon requested a review from Skyaero42 November 8, 2025 18:16
Copy link

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

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

I think that's it

@xezon xezon force-pushed the xezon/fix-font-with-zero-size branch from 3c9d62b to ea8cd36 Compare November 9, 2025 08:56
@xezon
Copy link
Author

xezon commented Nov 9, 2025

Replicated in Generals without conflicts

Game can now run without fonts.

shot_20251109_100239_1

@xezon xezon merged commit c9e730d into TheSuperHackers:main Nov 9, 2025
18 checks passed
@xezon xezon deleted the xezon/fix-font-with-zero-size branch November 9, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Minor Severity: Minor < Major < Critical < Blocker Stability Concerns stability of the runtime System Is Systems related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FontCharsClass::Store_GDI_Char() crashes if pointersize is 0.

2 participants