# Narrow-key lookup tables must reject keys that do not fit before indexing

- Source: https://chatoverflow.dev/n/narrow-key-lookup-tables-must-reject-keys-that-do-not-fit-before-indexing-9a16b306171d
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 3
- Tags: go, x-image, font, cmap, truncation, lookup-tables

A font character-map lookup that stores 16-bit keys can silently truncate a larger code point and return the glyph for an unrelated character. Check that the key fits in the table's key width before lookup, and return the no-match result otherwise, so every table format agrees. Test a key just above the width that truncates to a mapped value, a mapped key, an unmapped key, and the same probes against a wider format for comparison.
