Files
mruby-mruby/oss-fuzz/mruby_pack_fuzzer.c
T
David Korczynski 923c2e6a73 Add new fuzzing harness to be consumed by OSS-Fuzz
Adds 6 new fuzzing harnesses to be consumed by OSS-Fuzz. Have confirmed
locally this results in significant coverage gains relative to the
current code coverage in OSS-Fuzz:
https://storage.googleapis.com/oss-fuzz-coverage/mruby/reports/20260427/linux/src/report.html

Signed-off-by: David Korczynski <david@adalogics.com>
2026-04-29 06:49:03 -07:00

38 lines
1013 B
C

#include <stdlib.h>
#include <string.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/string.h>
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t size) {
if (size < 2) {
return 0;
}
mrb_state *mrb = mrb_open();
if (!mrb) {
return 0;
}
uint8_t fmt_len = Data[0];
if (fmt_len > size - 1) {
fmt_len = size - 1;
}
mrb_value fmt = mrb_str_new(mrb, (const char *)(Data + 1), fmt_len);
mrb_value str = mrb_str_new(mrb, (const char *)(Data + 1 + fmt_len), size - 1 - fmt_len);
/* Target String#unpack */
mrb_funcall(mrb, str, "unpack", 1, fmt);
/* Target Array#pack (using the result of unpack if it's an array) */
/* Or just pack the original string as an array of bytes */
mrb_value ary = mrb_ary_new_capa(mrb, size);
for (size_t i = 0; i < size; i++) {
mrb_ary_push(mrb, ary, mrb_fixnum_value(Data[i]));
}
mrb_funcall(mrb, ary, "pack", 1, fmt);
mrb_close(mrb);
return 0;
}