Skip to content

[rtext] Fix BDF font loading crash (glyph pointer reset to NULL) - #6198

Merged
raysan5 merged 1 commit into
raysan5:masterfrom
antonsoo:fix/bdf-glyph-pointer
Sep 30, 2026
Merged

raysan5 merged 1 commit into
raysan5:masterfrom
antonsoo:fix/bdf-glyph-pointer

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

With SUPPORT_FILEFORMAT_BDF enabled, loading a BDF font crashes on 6.0 and master.

LoadFontDataBDF() used to fill each glyph through a separate charGlyphInfo pointer (as in 5.5). That pointer was merged into glyphs, so now every STARTCHAR and BITMAP line sets the glyph array itself to NULL, and the current glyph is computed as &glyphs[index] from that NULL. Any glyph after the first requested codepoint is written to address index*sizeof(GlyphInfo) (segfault), and the glyph array leaks.

This restores the separate per-glyph pointer. It also allocates requiredCodepoints after the fileData == NULL check and the default codepoint count, so it no longer leaks on that early return.

Tested with three sizes of the Spleen BDF font (5x8, 8x16, 12x24) through LoadFontEx(), with the default codepoints and with an explicit list including non-ASCII codepoints:

  • before: segfault in LoadFontDataBDF for all of them (release build and ASan);
  • after: loads with no ASan/UBSan/leak reports, and every glyph's value, size, offsets, advance and bitmap matches an independent parse of the BDF file.

rtext.c builds without new warnings on Linux (gcc) and cross-compiled for Windows (x86_64-windows-gnu), with BDF enabled and disabled.

LoadFontDataBDF() used to track the glyph being filled in a separate
charGlyphInfo pointer. Since that pointer was folded into `glyphs`, the
loader resets the glyph array itself to NULL at every STARTCHAR and
BITMAP line, then computes the current glyph as &glyphs[index] from NULL.
Any BDF font with a glyph past the first requested codepoint crashes, and
the glyph array leaks.

Restore the separate per-glyph pointer, and allocate requiredCodepoints
after the NULL check and the default codepoint count are applied.
Comment thread src/rtext.c Resolved
@raysan5
raysan5 merged commit 47dea9b into raysan5:master Sep 30, 2026
@raysan5

raysan5 commented Sep 30, 2026

Copy link
Copy Markdown
Owner

@antonsoo thanks for the review, BDF is barely tested, I think I never used it...

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.

2 participants