Skip to content

fix(cmap): bounds-check ArrayOfHexStrings index in bfrange lookup#478

Merged
J-F-Liu merged 1 commit intoJ-F-Liu:mainfrom
abimaelmartell:fix/cmap-array-bounds-check
Mar 14, 2026
Merged

fix(cmap): bounds-check ArrayOfHexStrings index in bfrange lookup#478
J-F-Liu merged 1 commit intoJ-F-Liu:mainfrom
abimaelmartell:fix/cmap-array-bounds-check

Conversation

@abimaelmartell
Copy link
Copy Markdown
Contributor

Summary

Malformed CMap bfrange entries can declare a source code range larger than their ArrayOfHexStrings array (e.g., range covers 5 codes but array has only 2 entries). When ToUnicodeCMap::get() looks up a code that falls past the end of the array, it panics with an index out of bounds.

Fix

Added a bounds check on the array index in the ArrayOfHexStrings match arm. When the index exceeds the array length, return U+FFFD (replacement character) instead of panicking. This is consistent with get_or_replacement_char(), which already uses U+FFFD as the fallback for missing mappings. The actual mapped entries are still returned correctly.

@J-F-Liu J-F-Liu merged commit 845cd3d into J-F-Liu:main Mar 14, 2026
10 checks passed
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