File: fast_obj_fuzzer.cpp

package info (click to toggle)
fastobj 1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 252 kB
  • sloc: cpp: 2,152; ansic: 1,126; makefile: 9
file content (27 lines) | stat: -rw-r--r-- 524 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#define FAST_OBJ_IMPLEMENTATION
#include "fast_obj.h"

#include <string>
#include <sys/types.h>
#include <unistd.h>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  char filename[256];
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());

  FILE *fp = fopen(filename, "wb");
  if (!fp)
    return 0;
  fwrite(data, size, 1, fp);
  fclose(fp);

  fastObjMesh *m = fast_obj_read(filename);
  if (!m) {
    unlink(filename);
    return 0;
  }

  fast_obj_destroy(m);
  unlink(filename);
  return 0;
}