mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 22:41:10 +01:00
[fuzzing] Guard raster/vector create_or_fail results
The raster and vector fuzzers called create_or_fail() and then immediately dereferenced the returned pointers. Under CIFuzz's allocation-failure coverage, that turns a valid NULL return into a harness crash instead of treating it as an out-of-memory case. Return early after cleaning up when draw or paint context creation fails. This keeps the fuzzers aligned with the create_or_fail() contract and avoids null-deref crashes unrelated to library logic. Tested: - meson compile -C build hb-raster-fuzzer hb-vector-fuzzer - build/test/fuzzing/hb-vector-fuzzer test/fuzzing/fonts/TwemojiMozilla.subset.ttf - build/test/fuzzing/hb-raster-fuzzer test/fuzzing/fonts/TwemojiMozilla.subset.ttf Assisted-by: OpenAI Codex
This commit is contained in:
1 parent
3ec2c7c329
commit
47b0ce552d
2 files changed
+14
-2
No files matched your search
@@ -56,6 +56,13 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||
|
||||
hb_raster_draw_t *draw = hb_raster_draw_create_or_fail ();
|
||||
hb_raster_paint_t *paint = hb_raster_paint_create_or_fail ();
|
||||
if (!draw || !paint)
|
||||
{
|
||||
hb_raster_draw_destroy (draw);
|
||||
hb_raster_paint_destroy (paint);
|
||||
hb_buffer_destroy (buffer);
|
||||
return 0;
|
||||
}
|
||||
hb_raster_paint_set_foreground (paint, HB_COLOR (0, 0, 0, 255));
|
||||
|
||||
draw_shaped_text (input.font, buffer, draw, paint);
|
||||
@@ -101,4 +108,3 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||
hb_buffer_destroy (buffer);
|
||||
return counter ? 0 : 0;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,13 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||
|
||||
hb_vector_draw_t *draw = hb_vector_draw_create_or_fail (HB_VECTOR_FORMAT_SVG);
|
||||
hb_vector_paint_t *paint = hb_vector_paint_create_or_fail (HB_VECTOR_FORMAT_SVG);
|
||||
if (!draw || !paint)
|
||||
{
|
||||
hb_vector_draw_destroy (draw);
|
||||
hb_vector_paint_destroy (paint);
|
||||
hb_buffer_destroy (buffer);
|
||||
return 0;
|
||||
}
|
||||
hb_vector_paint_set_foreground (paint, HB_COLOR (0, 0, 0, 255));
|
||||
|
||||
unsigned precision = size ? data[size - 1] % 5 : 0;
|
||||
@@ -105,4 +112,3 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
||||
hb_buffer_destroy (buffer);
|
||||
return counter ? 0 : 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user