MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / LLVMFuzzerTestOneInput

Function LLVMFuzzerTestOneInput

tools/target_enc_fuzzer.c:73–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
74 uint64_t maxpixels_per_frame = 512 * 512;
75 uint64_t maxpixels;
76
77 const uint8_t *end = data + size;
78 uint32_t it = 0;
79 uint64_t nb_samples = 0;
80 AVDictionary *opts = NULL;
81 uint64_t ec_pixels = 0;
82
83 if (!c) {
84#define ENCODER_SYMBOL0(CODEC) ff_##CODEC##_encoder
85#define ENCODER_SYMBOL(CODEC) ENCODER_SYMBOL0(CODEC)
86 extern FFCodec ENCODER_SYMBOL(FFMPEG_ENCODER);
87 codec_list[0] = &ENCODER_SYMBOL(FFMPEG_ENCODER);
88
89 c = &ENCODER_SYMBOL(FFMPEG_ENCODER);
90 av_log_set_level(AV_LOG_PANIC);
91 }
92
93 if (c->p.type != AVMEDIA_TYPE_VIDEO)
94 return 0;
95
96 maxpixels = maxpixels_per_frame * maxiteration;
97 switch (c->p.id) {
98 case AV_CODEC_ID_A64_MULTI: maxpixels /= 65536; break;
99 case AV_CODEC_ID_A64_MULTI5: maxpixels /= 65536; break;
100 }
101
102 maxpixels_per_frame = FFMIN(maxpixels_per_frame , maxpixels);
103
104 AVCodecContext* ctx = avcodec_alloc_context3(&c->p);
105 if (!ctx)
106 error("Failed memory allocation");
107
108 if (ctx->max_pixels == 0 || ctx->max_pixels > maxpixels_per_frame)
109 ctx->max_pixels = maxpixels_per_frame; //To reduce false positive OOM and hangs
110
111 ctx->pix_fmt = AV_PIX_FMT_YUV420P;
112 if (size > 1024) {
113 GetByteContext gbc;
114 int flags;
115 int64_t flags64;
116
117 size -= 1024;
118 bytestream2_init(&gbc, data + size, 1024);
119 ctx->width = bytestream2_get_le32(&gbc) & 0xFFFF;
120 ctx->height = bytestream2_get_le32(&gbc) & 0xFFFF;
121 ctx->bit_rate = bytestream2_get_le64(&gbc);
122 ctx->gop_size = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
123 ctx->max_b_frames = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
124 ctx->time_base.num = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
125 ctx->time_base.den = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
126 ctx->framerate.num = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
127 ctx->framerate.den = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
128
129 flags = bytestream2_get_byte(&gbc);
130 if (flags & 2)

Callers

nothing calls this directly

Calls 15

av_log_set_levelFunction · 0.85
avcodec_alloc_context3Function · 0.85
bytestream2_initFunction · 0.85
av_force_cpu_flagsFunction · 0.85
av_dict_set_intFunction · 0.85
av_image_check_sizeFunction · 0.85
avcodec_open2Function · 0.85
avcodec_free_contextFunction · 0.85
av_dict_freeFunction · 0.85
av_frame_allocFunction · 0.85
av_packet_allocFunction · 0.85
av_frame_get_bufferFunction · 0.85

Tested by

no test coverage detected