44 Commits
Author SHA1 Message Date
Eugenio Depalo 2db1b3ab9d [buffer] Add deserializers with byte offsets (#6552)
* [buffer] Add deserializers with byte offsets

Buffer deserializers return a pointer into caller-owned input. GIR
describes it as an owned UTF-8 string, so bindings can free an
interior pointer or read beyond explicitly sized input.

Add _with_offset variants with bounded byte-array inputs and optional
byte counts. Preserve the existing return values and partial buffer
contents, including on failure. Cross-check both variants against the
existing deserializers in the buffer API tests.

Testing: full Meson suite, buffer tests under Valgrind, and GIR and
PyGObject checks.

Fixes: #6446
Assisted-by: OpenAI Codex

* [buffer] Rename new deserializers to use 2 suffix

Use the established 2 suffix for the new buffer deserializers,
following hb_shape_plan_create2(). Update API docs, NEWS, and tests.

Testing: full Meson suite, generated GIR, and PyGObject checks.

Assisted-by: OpenAI Codex
2026-11-04 12:05:35 -06:00
Behdad EsfahbodandClaude Opus 4.8 6620feeae2 [buffer] Add missing immutable checks to two setters and create_similar
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>
2026-10-30 15:21:14 -06:00
Behdad Esfahbod 199cae8b28 [buffer] Document message callback lifetime across reset (#6354)
Buffer reset has retained message callbacks since their introduction,
although its documentation promised a freshly created buffer state.
Clarify that callbacks, their associated data, and attached user data
survive reset. Document explicit callback removal and destruction.

Add a regression test for callback-directed lookup skipping after
clear/reset, restoration of ligatures after removal, and exactly-once
destruction on replacement, removal, and final buffer destruction.

Tested with meson test -C build: 287 passed, 1 skipped, 0 failed.
The API test also compiles without buffer messages or OT shaping.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6341
Assisted-by: OpenAI Codex
2026-10-10 16:58:18 -06:00
Behdad Esfahbod 886fc1e645 Merge pull request #6154 from harfbuzz/fix/saturating-position-math
[position] Saturate position arithmetic
2026-08-16 13:19:21 -06:00
Behdad Esfahbod 87440579f9 Fix a couple of warnings 2026-08-13 08:43:50 -06:00
Behdad Esfahbod 00bfc56167 [buffer] Compare full-range positions safely
Widen position differences before taking their absolute value.  This
avoids signed overflow when hb_buffer_diff() compares positions near
opposite ends of the hb_position_t range.

Add an API regression covering INT32_MIN versus INT32_MAX.

Tested with: meson test -C build --print-errorlogs

Assisted-by: OpenAI Codex
2026-08-12 18:39:17 -06:00
parasol-aserandjeffhuang da577bc545 test: strengthen buffer and map API coverage (#5979)
Add focused API tests for hb_buffer_create_similar() and buffer
configuration persistence across clear/reset. Also exercise public hb_map
copy, equality, hash, update, iteration, keys, and values paths with
order-independent assertions.

Validation:
meson test -C build-tgl-precheck --print-errorlogs --suite api test-buffer
meson test -C build-tgl-precheck --print-errorlogs --suite api test-map
meson test -C build-tgl-precheck --print-errorlogs --suite api test-buffer test-map

Assisted-by: OpenAI Codex <codex@openai.com>

Co-authored-by: jeffhuang <jeff@docker.xydrsucermoubd24xgo33yhsgd.bx.internal.cloudapp.net>
2026-05-06 17:27:10 -06:00
Khaled Hosny c763763662 [buffer-serialize] Fix calculating absolute offsets with partial range
Fixes https://github.com/harfbuzz/harfbuzz/issues/5743
2026-02-15 17:30:16 +02:00
Behdad Esfahbod fb04a306fc [test/api] Fix a few ubsan issues 2025-04-06 18:08:50 -06:00
Behdad Esfahbod 155e1e633b [test/api] Use g_assert_true instead of g_assert
The latter terminates the program. The former marks the test
as failing.
2025-04-06 03:49:15 -06:00
Behdad Esfahbod 7a912c4746 [buffer-deserialize] Fix return value and parsing
I think I got it right.

Alternative to https://github.com/harfbuzz/harfbuzz/pull/5028
2025-03-10 16:20:16 -06:00
Behdad Esfahbod 7f5fac7c87 [test-buffer] Fix unintionally merged change 2025-02-04 23:35:34 +00:00
Behdad Esfahbod f0ead85283 [aat] Implement set filtering for Noncontextual chains as well 2025-02-04 23:30:30 +00:00
Behdad Esfahbod b394ab39e9 [test-buffer] Add code for testing end_ptr 2025-02-01 14:26:32 +00:00
ssmid 8de7e9fdb1 deprecation cleanup: HB_BUFFER_FLAGS_DEFAULT removed 2024-06-20 09:11:12 -07:00
Behdad Esfahbod 1c693e8c28 [test] Fix unused-var warning 2021-02-22 17:11:36 -07:00
Khaled Hosny c2cdcd4901 [tests] warning: unused variable 'num_glyphs' 2020-10-17 21:57:27 +02:00
Khaled Hosny fa771a7f85 [tests] Fix memory leak in test
To make valgrind bot happy.
2020-10-11 13:15:39 -07:00
Behdad Esfahbod 540d2cdddb [tests/buffer] Revert unintended whitespace changes
From 9e5538d6a3d6f1ffbee7fad3c821621f17d61494

Tried squashing into, but too much merge conflict.
2020-10-09 22:27:55 -06:00
Behdad Esfahbod 04658ec48f [tests/buffer] Update tests for previous commit 2020-10-09 22:27:55 -06:00
Simon Cozens 7c0bc0bb92 Serialize invalid buffer to !! (text) or [] (json)
There is no generic deserialize - you have to choose glyphs or unicode - so there is no way to deserialize this buffer.
2020-10-09 22:27:55 -06:00
Simon Cozens 150f391438 Prohibit mixed glyphs/unicode buffers in deserialization 2020-10-09 22:27:55 -06:00
Simon Cozens 3d3c87e7e7 Put the flags back in and serialize clusters.
Note that now JSON glyph buffers and Unicode buffers look very similar, except for the g/u property difference.
2020-10-09 22:27:55 -06:00
Simon Cozens 432a05b2af (Simple) tests for Unicode serialization/deserialization 2020-10-09 22:27:55 -06:00
Ebrahim Byagowi a0b4ac4dce Turn 8 spaces to tab across the project
According to the current code style of the project
2019-08-27 02:40:41 +04:30
Behdad Esfahbod 831ba74382 Fix Codacy "issues" 2018-11-20 01:16:08 -05:00
Ebrahim Byagowi bf5088b3dc Minor, fix -Weverthing bot warnings (#1210) 2018-10-02 11:07:06 +03:30
Ebrahim Byagowi f24b0b9728 Update the links and revive the dead ones 2018-04-12 13:44:32 +04:30
Behdad Esfahbod d33ba16361 Fix more warnings 2018-02-11 18:26:41 -08:00
Behdad Esfahbod 6c1848b1e3 Misc warning fixes 2018-02-10 15:52:35 -06:00
Behdad Esfahbod c4712f8e37 Fix test 2017-08-10 20:27:21 -07:00
Behdad Esfahbod b5fbc3b8f5 API: Do not clear buffer-flags in hb_buffer_clear_contents()
After 763e5466c0, one doesn't
need to set flags for different pieces of text.  The flags now
are something the client sets up once, depending on how it
actually uses the buffer.  As such, don't clear it in
clear_contents().

Tests updated.
2014-08-11 18:40:01 -04:00
Behdad Esfahbod 976c8f4552 New API: hb_buffer_[sg]et_replacement_codepoint()
With this change, we now by default replace broken UTF-8/16/32 bits
with U+FFFD.  This can be changed by calling new API on the buffer.
Previously the replacement value used to be (hb_codepoint_t)-1.

Note that hb_buffer_clear_contents() does NOT reset the replacement
character.

See discussion here:

https://github.com/behdad/harfbuzz/commit/6f13b6d62daae4989e3cc2fe4b168e5c59650964

New API:

  hb_buffer_set_replacement_codepoint()
  hb_buffer_get_replacement_codepoint()
2014-07-16 15:34:20 -04:00
Behdad Esfahbod e634fed428 [buffer] Validate UTF-32 input
Same as what we do for UTF-8 and UTF-16.
2014-07-16 14:17:26 -04:00
Behdad Esfahbod af2490c095 Only accept well-formed UTF-8 sequences
Enable tests that were disabled before, and adjust one test,
and add more tests.
2014-07-11 16:22:13 -04:00
Behdad Esfahbod 24b2ba9dfa [test-buffer] Add test for lonely low-surrogate
Currenty fails.  Ouch!
2014-07-10 19:31:16 -04:00
Behdad Esfahbod 4dc798de19 Add hb-deprecated.h, and rename a couple enum values
Add deprecated alias for old name.
2013-08-27 11:46:08 -04:00
Behdad Esfahbod a4446b10bf Fix build for C89 compilers 2013-06-03 18:39:14 -04:00
Behdad Esfahbod 1172dc7362 Rename hb_buffer_clear() to hb_buffer_clear_contents()
The previous name was clashing with harfbuzz.old.  There are systems
that need to link both...

Clash-free now again.
2013-01-07 16:46:37 -06:00
Behdad Esfahbod d04b128531 Fix test 2012-11-14 10:53:10 -08:00
Behdad Esfahbod 0c7df22228 Add buffer flags
New API:

	hb_buffer_flags_t

	HB_BUFFER_FLAGS_DEFAULT
	HB_BUFFER_FLAG_BOT
	HB_BUFFER_FLAG_EOT
	HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES

	hb_buffer_set_flags()
	hb_buffer_get_flags()

We use the BOT flag to decide whether to insert dottedcircle if the
first char in the buffer is a combining mark.

The PRESERVE_DEFAULT_IGNORABLES flag prevents removal of characters like
ZWNJ/ZWJ/...
2012-11-13 14:42:35 -08:00
Behdad Esfahbod 82ecaff736 Add hb_buffer_clear()
Which is like _reset(), but does NOT clear unicode-funcs.
2012-11-13 14:10:00 -08:00
Behdad Esfahbod a18280a8ce Fix warnings produced by clang analyzer 2012-06-07 15:44:12 -04:00
Behdad Esfahbod 4d6dafd47f Rename test/ to test/api/ 2012-01-19 14:52:02 -05:00