1. Documentation
  2. Advanced Techniques

Fuzzing File Input

How to Write a Fuzz Target for a Function That Reads Input From a File

Header File

#include <file_input.h>

Passing File Name

First, create a fuzzing input file object:

auto ci_file_input = ci::input_file{Data, Size};

You can pass it to your function as a file name:

auto out = your_function(ci_file_input.name(), other arguments);

return type of the name() method: const char *

file is valid until this object goes out of scope.

Other Methods of the input_file Class

Return a file descriptor for the temporary file, opened for reading. The
descriptor will be cleaned up automatically when this object goes out of
 scope. Calling the function repeatedly will return the same descriptor
each time.

int fd() const;

Return a C file stream for the temporary file, opened for reading. The
file will be closed automatically when this object goes out of scope.
Calling the function repeatedly will return the same file stream each
time.

FILE *c_file() const;