fuzz-vpx.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2023 Teluu Inc. (http://www.teluu.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <stdio.h>
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <pjlib.h>
  22. #include <pjmedia-codec/vpx_packetizer.h>
  23. #if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0)
  24. #define kMinInputLength 10
  25. #define kMaxInputLength 5120
  26. pj_pool_factory *mem;
  27. int vpx_unpacketizer(const uint8_t *data, size_t size)
  28. {
  29. int ret = 0;
  30. pj_pool_t *pool;
  31. pj_status_t status;
  32. pjmedia_vpx_packetizer_cfg cfg;
  33. pjmedia_vpx_packetizer *pktz;
  34. unsigned desc_len = 0;
  35. pool = pj_pool_create(mem, "vpx_test", 1000, 1000, NULL);
  36. pj_bzero(&cfg, sizeof(cfg));
  37. status = pjmedia_vpx_packetizer_create(pool, &cfg, &pktz);
  38. if (status == PJ_SUCCESS) {
  39. status = pjmedia_vpx_unpacketize(pktz, data, size, &desc_len);
  40. }
  41. pj_pool_release(pool);
  42. return ret;
  43. }
  44. extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
  45. {
  46. int ret = 0;
  47. uint8_t *data;
  48. pj_caching_pool caching_pool;
  49. if (Size < kMinInputLength || Size > kMaxInputLength) {
  50. return 1;
  51. }
  52. /* Add null termination for the data */
  53. data = (uint8_t *)calloc((Size+1), sizeof(uint8_t));
  54. memcpy((void *)data, (void *)Data, Size);
  55. /* Init */
  56. pj_init();
  57. pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);
  58. pj_log_set_level(0);
  59. mem = &caching_pool.factory;
  60. /* Fuzz */
  61. ret = vpx_unpacketizer(data, Size);
  62. free(data);
  63. pj_caching_pool_destroy(&caching_pool);
  64. return ret;
  65. }
  66. #else
  67. extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
  68. {
  69. PJ_UNUSED_ARG(Data);
  70. PJ_UNUSED_ARG(Size);
  71. return 0;
  72. }
  73. #endif