Every hb_buffer_set_*() is meant to be a no-op on an immutable
buffer, which is what keeps the static _hb_Null_hb_buffer_t
(returned by hb_buffer_get_empty(), and by hb_buffer_create() on
allocation failure) inert. Three entry points skipped that guard:
- hb_buffer_set_not_found_variation_selector_glyph() stored into
the singleton;
- hb_buffer_guess_segment_properties() wrote direction and
language into it;
- hb_buffer_create_similar() called similar() on the singleton
when its internal hb_buffer_create() failed, copying the source
buffer's settings onto the shared empty buffer and leaking a
reference to its unicode funcs.
Add the same hb_object_is_immutable() early return the sibling
setters use, and guard the create_similar() allocation-failure path
the way hb_font_create_sub_font() already does. No other public
setter in hb-buffer.cc lacks the check. No API/ABI change; the
only behaviour change is that these calls on the empty buffer now
do nothing, as the documented object model promises.
A regression check is appended to test_buffer_empty().
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-RNK5DQFY.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>