fuzzer-exif.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Stanislav Malyshev <stas@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #include "fuzzer.h"
  17. #include "Zend/zend.h"
  18. #include "main/php_config.h"
  19. #include "main/php_main.h"
  20. #include "ext/standard/php_var.h"
  21. #include <stdio.h>
  22. #include <stdint.h>
  23. #include <stdlib.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <fcntl.h>
  27. #include "fuzzer-sapi.h"
  28. int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  29. #if HAVE_EXIF
  30. php_stream *stream;
  31. zval stream_zv;
  32. if (Size > 256 * 1024) {
  33. /* Large inputs have a large impact on fuzzer performance,
  34. * but are unlikely to be necessary to reach new codepaths. */
  35. return 0;
  36. }
  37. if (fuzzer_request_startup() == FAILURE) {
  38. return 0;
  39. }
  40. stream = php_stream_memory_create(TEMP_STREAM_DEFAULT);
  41. php_stream_write(stream, (const char *) Data, Size);
  42. php_stream_to_zval(stream, &stream_zv);
  43. fuzzer_call_php_func_zval("exif_read_data", 1, &stream_zv);
  44. zval_ptr_dtor(&stream_zv);
  45. /* cleanup */
  46. php_request_shutdown(NULL);
  47. return 0;
  48. #else
  49. fprintf(stderr, "\n\nERROR:\nPHP built without EXIF, recompile with --enable-exif to use this fuzzer\n");
  50. exit(1);
  51. #endif
  52. }
  53. int LLVMFuzzerInitialize(int *argc, char ***argv) {
  54. fuzzer_init_php();
  55. /* fuzzer_shutdown_php(); */
  56. return 0;
  57. }