hb-fuzzer.hh 693 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <hb.h>
  2. #include <stddef.h>
  3. extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size);
  4. #if defined(__GNUC__) && (__GNUC__ >= 4) || (__clang__)
  5. #define HB_UNUSED __attribute__((unused))
  6. #else
  7. #define HB_UNUSED
  8. #endif
  9. #ifdef HB_IS_IN_FUZZER
  10. /* See src/failing-alloc.c */
  11. extern "C" int alloc_state;
  12. #else
  13. /* Just a dummy global variable */
  14. static int HB_UNUSED alloc_state = 0;
  15. #endif
  16. static inline int
  17. _fuzzing_alloc_state (const uint8_t *data, size_t size)
  18. {
  19. /* https://github.com/harfbuzz/harfbuzz/pull/2764#issuecomment-1172589849 */
  20. /* In 50% of the runs, don't fail the allocator. */
  21. if (size && data[size - 1] < 0x80)
  22. return 0;
  23. return size;
  24. }