diff --git "a/devign/alpaca/devign_512-1024_validate.json" "b/devign/alpaca/devign_512-1024_validate.json" new file mode 100644--- /dev/null +++ "b/devign/alpaca/devign_512-1024_validate.json" @@ -0,0 +1,2720 @@ +[ + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int mpegps_read_packet(AVFormatContext *s,\n\n AVPacket *pkt)\n\n{\n\n AVStream *st;\n\n int len, startcode, i, type, codec_id;\n\n int64_t pts, dts;\n\n\n\n redo:\n\n len = mpegps_read_pes_header(s, NULL, &startcode, &pts, &dts, 1);\n\n if (len < 0)\n\n return len;\n\n \n\n /* now find stream */\n\n for(i=0;inb_streams;i++) {\n\n st = s->streams[i];\n\n if (st->id == startcode)\n\n goto found;\n\n }\n\n if (startcode >= 0x1e0 && startcode <= 0x1ef) {\n\n type = CODEC_TYPE_VIDEO;\n\n codec_id = CODEC_ID_MPEG1VIDEO;\n\n } else if (startcode >= 0x1c0 && startcode <= 0x1df) {\n\n type = CODEC_TYPE_AUDIO;\n\n codec_id = CODEC_ID_MP2;\n\n } else if (startcode >= 0x80 && startcode <= 0x9f) {\n\n type = CODEC_TYPE_AUDIO;\n\n codec_id = CODEC_ID_AC3;\n\n } else if (startcode >= 0xa0 && startcode <= 0xbf) {\n\n type = CODEC_TYPE_AUDIO;\n\n codec_id = CODEC_ID_PCM_S16BE;\n\n } else {\n\n skip:\n\n /* skip packet */\n\n url_fskip(&s->pb, len);\n\n goto redo;\n\n }\n\n /* no stream found: add a new stream */\n\n st = av_new_stream(s, startcode);\n\n if (!st) \n\n goto skip;\n\n st->codec.codec_type = type;\n\n st->codec.codec_id = codec_id;\n\n if (codec_id != CODEC_ID_PCM_S16BE)\n\n st->need_parsing = 1;\n\n found:\n\n if (startcode >= 0xa0 && startcode <= 0xbf) {\n\n int b1, freq;\n\n static const int lpcm_freq_tab[4] = { 48000, 96000, 44100, 32000 };\n\n\n\n /* for LPCM, we just skip the header and consider it is raw\n\n audio data */\n\n if (len <= 3)\n\n goto skip;\n\n get_byte(&s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */\n\n b1 = get_byte(&s->pb); /* quant (2), freq(2), reserved(1), channels(3) */\n\n get_byte(&s->pb); /* dynamic range control (0x80 = off) */\n\n len -= 3;\n\n freq = (b1 >> 4) & 3;\n\n st->codec.sample_rate = lpcm_freq_tab[freq];\n\n st->codec.channels = 1 + (b1 & 7);\n\n st->codec.bit_rate = st->codec.channels * st->codec.sample_rate * 2;\n\n }\n\n av_new_packet(pkt, len);\n\n get_buffer(&s->pb, pkt->data, pkt->size);\n\n pkt->pts = pts;\n\n pkt->dts = dts;\n\n pkt->stream_index = st->index;\n\n#if 0\n\n printf(\"%d: pts=%0.3f dts=%0.3f\\n\",\n\n pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0);\n\n#endif\n\n return 0;\n\n}\n", + "output": "1", + "index": 1776 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int fir_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)\n\n{\n\n AudioFIRContext *s = ctx->priv;\n\n const float *src = (const float *)s->in[0]->extended_data[ch];\n\n int index1 = (s->index + 1) % 3;\n\n int index2 = (s->index + 2) % 3;\n\n float *sum = s->sum[ch];\n\n AVFrame *out = arg;\n\n float *block;\n\n float *dst;\n\n int n, i, j;\n\n\n\n memset(sum, 0, sizeof(*sum) * s->fft_length);\n\n block = s->block[ch] + s->part_index * s->block_size;\n\n memset(block, 0, sizeof(*block) * s->fft_length);\n\n\n\n s->fdsp->vector_fmul_scalar(block + s->part_size, src, s->dry_gain, s->nb_samples);\n\n emms_c();\n\n\n\n av_rdft_calc(s->rdft[ch], block);\n\n block[2 * s->part_size] = block[1];\n\n block[1] = 0;\n\n\n\n j = s->part_index;\n\n\n\n for (i = 0; i < s->nb_partitions; i++) {\n\n const int coffset = i * s->coeff_size;\n\n const FFTComplex *coeff = s->coeff[ch * !s->one2many] + coffset;\n\n\n\n block = s->block[ch] + j * s->block_size;\n\n s->fcmul_add(sum, block, (const float *)coeff, s->part_size);\n\n\n\n if (j == 0)\n\n j = s->nb_partitions;\n\n j--;\n\n }\n\n\n\n sum[1] = sum[2 * s->part_size];\n\n av_rdft_calc(s->irdft[ch], sum);\n\n\n\n dst = (float *)s->buffer->extended_data[ch] + index1 * s->part_size;\n\n for (n = 0; n < s->part_size; n++) {\n\n dst[n] += sum[n];\n\n }\n\n\n\n dst = (float *)s->buffer->extended_data[ch] + index2 * s->part_size;\n\n\n\n memcpy(dst, sum + s->part_size, s->part_size * sizeof(*dst));\n\n\n\n dst = (float *)s->buffer->extended_data[ch] + s->index * s->part_size;\n\n\n\n if (out) {\n\n float *ptr = (float *)out->extended_data[ch];\n\n s->fdsp->vector_fmul_scalar(ptr, dst, s->gain * s->wet_gain, out->nb_samples);\n\n emms_c();\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 26084 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void sh_serial_write(void *opaque, hwaddr offs,\n\n uint64_t val, unsigned size)\n\n{\n\n sh_serial_state *s = opaque;\n\n unsigned char ch;\n\n\n\n#ifdef DEBUG_SERIAL\n\n printf(\"sh_serial: write offs=0x%02x val=0x%02x\\n\",\n\n\t offs, val);\n\n#endif\n\n switch(offs) {\n\n case 0x00: /* SMR */\n\n s->smr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0x7b : 0xff);\n\n return;\n\n case 0x04: /* BRR */\n\n s->brr = val;\n\n\treturn;\n\n case 0x08: /* SCR */\n\n /* TODO : For SH7751, SCIF mask should be 0xfb. */\n\n s->scr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0xfa : 0xff);\n\n if (!(val & (1 << 5)))\n\n s->flags |= SH_SERIAL_FLAG_TEND;\n\n if ((s->feat & SH_SERIAL_FEAT_SCIF) && s->txi) {\n\n\t qemu_set_irq(s->txi, val & (1 << 7));\n\n }\n\n if (!(val & (1 << 6))) {\n\n\t qemu_set_irq(s->rxi, 0);\n\n }\n\n return;\n\n case 0x0c: /* FTDR / TDR */\n\n if (s->chr) {\n\n ch = val;\n\n qemu_chr_fe_write(s->chr, &ch, 1);\n\n\t}\n\n\ts->dr = val;\n\n\ts->flags &= ~SH_SERIAL_FLAG_TDE;\n\n return;\n\n#if 0\n\n case 0x14: /* FRDR / RDR */\n\n ret = 0;\n\n break;\n\n#endif\n\n }\n\n if (s->feat & SH_SERIAL_FEAT_SCIF) {\n\n switch(offs) {\n\n case 0x10: /* FSR */\n\n if (!(val & (1 << 6)))\n\n s->flags &= ~SH_SERIAL_FLAG_TEND;\n\n if (!(val & (1 << 5)))\n\n s->flags &= ~SH_SERIAL_FLAG_TDE;\n\n if (!(val & (1 << 4)))\n\n s->flags &= ~SH_SERIAL_FLAG_BRK;\n\n if (!(val & (1 << 1)))\n\n s->flags &= ~SH_SERIAL_FLAG_RDF;\n\n if (!(val & (1 << 0)))\n\n s->flags &= ~SH_SERIAL_FLAG_DR;\n\n\n\n if (!(val & (1 << 1)) || !(val & (1 << 0))) {\n\n if (s->rxi) {\n\n qemu_set_irq(s->rxi, 0);\n\n }\n\n }\n\n return;\n\n case 0x18: /* FCR */\n\n s->fcr = val;\n\n switch ((val >> 6) & 3) {\n\n case 0:\n\n s->rtrg = 1;\n\n break;\n\n case 1:\n\n s->rtrg = 4;\n\n break;\n\n case 2:\n\n s->rtrg = 8;\n\n break;\n\n case 3:\n\n s->rtrg = 14;\n\n break;\n\n }\n\n if (val & (1 << 1)) {\n\n sh_serial_clear_fifo(s);\n\n s->sr &= ~(1 << 1);\n\n }\n\n\n\n return;\n\n case 0x20: /* SPTR */\n\n s->sptr = val & 0xf3;\n\n return;\n\n case 0x24: /* LSR */\n\n return;\n\n }\n\n }\n\n else {\n\n switch(offs) {\n\n#if 0\n\n case 0x0c:\n\n ret = s->dr;\n\n break;\n\n case 0x10:\n\n ret = 0;\n\n break;\n\n#endif\n\n case 0x1c:\n\n s->sptr = val & 0x8f;\n\n return;\n\n }\n\n }\n\n\n\n fprintf(stderr, \"sh_serial: unsupported write to 0x%02\"\n\n HWADDR_PRIx \"\\n\", offs);\n\n abort();\n\n}\n", + "output": "1", + "index": 11657 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold int aacPlus_encode_init(AVCodecContext *avctx)\n\n{\n\n aacPlusAudioContext *s = avctx->priv_data;\n\n aacplusEncConfiguration *aacplus_cfg;\n\n\n\n /* number of channels */\n\n if (avctx->channels < 1 || avctx->channels > 2) {\n\n av_log(avctx, AV_LOG_ERROR, \"encoding %d channel(s) is not allowed\\n\", avctx->channels);\n\n return AVERROR(EINVAL);\n\n\n\n\n if (avctx->profile != FF_PROFILE_AAC_LOW && avctx->profile != FF_PROFILE_UNKNOWN) {\n\n av_log(avctx, AV_LOG_ERROR, \"invalid AAC profile: %d, only LC supported\\n\", avctx->profile);\n\n return AVERROR(EINVAL);\n\n\n\n\n s->aacplus_handle = aacplusEncOpen(avctx->sample_rate, avctx->channels,\n\n &s->samples_input, &s->max_output_bytes);\n\n if (!s->aacplus_handle) {\n\n av_log(avctx, AV_LOG_ERROR, \"can't open encoder\\n\");\n\n return AVERROR(EINVAL);\n\n\n\n\n /* check aacplus version */\n\n aacplus_cfg = aacplusEncGetCurrentConfiguration(s->aacplus_handle);\n\n\n\n aacplus_cfg->bitRate = avctx->bit_rate;\n\n aacplus_cfg->bandWidth = avctx->cutoff;\n\n aacplus_cfg->outputFormat = !(avctx->flags & CODEC_FLAG_GLOBAL_HEADER);\n\n aacplus_cfg->inputFormat = avctx->sample_fmt == AV_SAMPLE_FMT_FLT ? AACPLUS_INPUT_FLOAT : AACPLUS_INPUT_16BIT;\n\n if (!aacplusEncSetConfiguration(s->aacplus_handle, aacplus_cfg)) {\n\n av_log(avctx, AV_LOG_ERROR, \"libaacplus doesn't support this output format!\\n\");\n\n return AVERROR(EINVAL);\n\n\n\n\n avctx->frame_size = s->samples_input / avctx->channels;\n\n\n\n /* Set decoder specific info */\n\n avctx->extradata_size = 0;\n\n if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {\n\n\n\n unsigned char *buffer = NULL;\n\n unsigned long decoder_specific_info_size;\n\n\n\n if (aacplusEncGetDecoderSpecificInfo(s->aacplus_handle, &buffer,\n\n &decoder_specific_info_size) == 1) {\n\n avctx->extradata = av_malloc(decoder_specific_info_size + FF_INPUT_BUFFER_PADDING_SIZE);\n\n\n\n\n\n avctx->extradata_size = decoder_specific_info_size;\n\n memcpy(avctx->extradata, buffer, avctx->extradata_size);\n\n\n\n\n return 0;\n", + "output": "1", + "index": 7711 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, int height, INT64 pts)\n\n{\n\n ContextInfo *ci = (ContextInfo *) ctx;\n\n AVPicture picture1;\n\n Imlib_Image image;\n\n DATA32 *data;\n\n\n\n image = get_cached_image(ci, width, height);\n\n\n\n if (!image) {\n\n image = imlib_create_image(width, height);\n\n put_cached_image(ci, image, width, height);\n\n }\n\n\n\n imlib_context_set_image(image);\n\n data = imlib_image_get_data();\n\n\n\n if (pix_fmt != PIX_FMT_RGBA32) {\n\n avpicture_fill(&picture1, (UINT8 *) data, PIX_FMT_RGBA32, width, height);\n\n if (img_convert(&picture1, PIX_FMT_RGBA32, \n\n picture, pix_fmt, width, height) < 0) {\n\n goto done;\n\n }\n\n } else {\n\n av_abort();\n\n }\n\n\n\n imlib_image_set_has_alpha(0);\n\n\n\n {\n\n int wid, hig, h_a, v_a; \n\n char buff[1000];\n\n char tbuff[1000];\n\n char *tbp = ci->text;\n\n time_t now = time(0);\n\n char *p, *q;\n\n int x, y;\n\n\n\n if (ci->file) {\n\n int fd = open(ci->file, O_RDONLY);\n\n\n\n if (fd < 0) {\n\n tbp = \"[File not found]\";\n\n } else {\n\n int l = read(fd, tbuff, sizeof(tbuff) - 1);\n\n\n\n if (l >= 0) {\n\n tbuff[l] = 0;\n\n tbp = tbuff;\n\n } else {\n\n tbp = \"[I/O Error]\";\n\n }\n\n close(fd);\n\n }\n\n }\n\n\n\n strftime(buff, sizeof(buff), tbp, localtime(&now));\n\n\n\n x = ci->x;\n\n y = ci->y;\n\n\n\n for (p = buff; p; p = q) {\n\n q = strchr(p, '\\n');\n\n if (q)\n\n *q++ = 0;\n\n\n\n imlib_text_draw_with_return_metrics(x, y, p, &wid, &hig, &h_a, &v_a);\n\n y += v_a;\n\n }\n\n }\n\n\n\n if (pix_fmt != PIX_FMT_RGBA32) {\n\n if (img_convert(picture, pix_fmt, \n\n &picture1, PIX_FMT_RGBA32, width, height) < 0) {\n\n }\n\n }\n\n\n\ndone:\n\n ;\n\n}\n", + "output": "0", + "index": 7611 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb)\n\n{\n\n int len, tag;\n\n int object_type_id = avio_r8(pb);\n\n avio_r8(pb); /* stream type */\n\n avio_rb24(pb); /* buffer size db */\n\n avio_rb32(pb); /* max bitrate */\n\n avio_rb32(pb); /* avg bitrate */\n\n\n\n if(avcodec_is_open(st->codec)) {\n\n av_log(fc, AV_LOG_DEBUG, \"codec open in read_dec_config_descr\\n\");\n\n return -1;\n\n }\n\n\n\n st->codec->codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id);\n\n av_dlog(fc, \"esds object type id 0x%02x\\n\", object_type_id);\n\n len = ff_mp4_read_descr(fc, pb, &tag);\n\n if (tag == MP4DecSpecificDescrTag) {\n\n av_dlog(fc, \"Specific MPEG4 header len=%d\\n\", len);\n\n if (!len || (uint64_t)len > (1<<30))\n\n return -1;\n\n av_free(st->codec->extradata);\n\n if (ff_alloc_extradata(st->codec, len))\n\n return AVERROR(ENOMEM);\n\n avio_read(pb, st->codec->extradata, len);\n\n if (st->codec->codec_id == AV_CODEC_ID_AAC) {\n\n MPEG4AudioConfig cfg = {0};\n\n avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata,\n\n st->codec->extradata_size * 8, 1);\n\n st->codec->channels = cfg.channels;\n\n if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4\n\n st->codec->sample_rate = avpriv_mpa_freq_tab[cfg.sampling_index];\n\n else if (cfg.ext_sample_rate)\n\n st->codec->sample_rate = cfg.ext_sample_rate;\n\n else\n\n st->codec->sample_rate = cfg.sample_rate;\n\n av_dlog(fc, \"mp4a config channels %d obj %d ext obj %d \"\n\n \"sample rate %d ext sample rate %d\\n\", st->codec->channels,\n\n cfg.object_type, cfg.ext_object_type,\n\n cfg.sample_rate, cfg.ext_sample_rate);\n\n if (!(st->codec->codec_id = ff_codec_get_id(mp4_audio_types,\n\n cfg.object_type)))\n\n st->codec->codec_id = AV_CODEC_ID_AAC;\n\n }\n\n }\n\n return 0;\n\n}\n", + "output": "1", + "index": 18972 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static size_t qemu_rdma_save_page(QEMUFile *f, void *opaque,\n\n ram_addr_t block_offset, ram_addr_t offset,\n\n size_t size, int *bytes_sent)\n\n{\n\n QEMUFileRDMA *rfile = opaque;\n\n RDMAContext *rdma = rfile->rdma;\n\n int ret;\n\n\n\n CHECK_ERROR_STATE();\n\n\n\n qemu_fflush(f);\n\n\n\n if (size > 0) {\n\n /*\n\n * Add this page to the current 'chunk'. If the chunk\n\n * is full, or the page doen't belong to the current chunk,\n\n * an actual RDMA write will occur and a new chunk will be formed.\n\n */\n\n ret = qemu_rdma_write(f, rdma, block_offset, offset, size);\n\n if (ret < 0) {\n\n fprintf(stderr, \"rdma migration: write error! %d\\n\", ret);\n\n goto err;\n\n }\n\n\n\n /*\n\n * We always return 1 bytes because the RDMA\n\n * protocol is completely asynchronous. We do not yet know\n\n * whether an identified chunk is zero or not because we're\n\n * waiting for other pages to potentially be merged with\n\n * the current chunk. So, we have to call qemu_update_position()\n\n * later on when the actual write occurs.\n\n */\n\n if (bytes_sent) {\n\n *bytes_sent = 1;\n\n }\n\n } else {\n\n uint64_t index, chunk;\n\n\n\n /* TODO: Change QEMUFileOps prototype to be signed: size_t => long\n\n if (size < 0) {\n\n ret = qemu_rdma_drain_cq(f, rdma);\n\n if (ret < 0) {\n\n fprintf(stderr, \"rdma: failed to synchronously drain\"\n\n \" completion queue before unregistration.\\n\");\n\n goto err;\n\n }\n\n }\n\n */\n\n\n\n ret = qemu_rdma_search_ram_block(rdma, block_offset,\n\n offset, size, &index, &chunk);\n\n\n\n if (ret) {\n\n fprintf(stderr, \"ram block search failed\\n\");\n\n goto err;\n\n }\n\n\n\n qemu_rdma_signal_unregister(rdma, index, chunk, 0);\n\n\n\n /*\n\n * TODO: Synchronous, guaranteed unregistration (should not occur during\n\n * fast-path). Otherwise, unregisters will process on the next call to\n\n * qemu_rdma_drain_cq()\n\n if (size < 0) {\n\n qemu_rdma_unregister_waiting(rdma);\n\n }\n\n */\n\n }\n\n\n\n /*\n\n * Drain the Completion Queue if possible, but do not block,\n\n * just poll.\n\n *\n\n * If nothing to poll, the end of the iteration will do this\n\n * again to make sure we don't overflow the request queue.\n\n */\n\n while (1) {\n\n uint64_t wr_id, wr_id_in;\n\n int ret = qemu_rdma_poll(rdma, &wr_id_in);\n\n if (ret < 0) {\n\n fprintf(stderr, \"rdma migration: polling error! %d\\n\", ret);\n\n goto err;\n\n }\n\n\n\n wr_id = wr_id_in & RDMA_WRID_TYPE_MASK;\n\n\n\n if (wr_id == RDMA_WRID_NONE) {\n\n break;\n\n }\n\n }\n\n\n\n return RAM_SAVE_CONTROL_DELAYED;\n\nerr:\n\n rdma->error_state = ret;\n\n return ret;\n\n}\n", + "output": "0", + "index": 23059 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int flic_read_header(AVFormatContext *s,\n\n AVFormatParameters *ap)\n\n{\n\n FlicDemuxContext *flic = s->priv_data;\n\n ByteIOContext *pb = &s->pb;\n\n unsigned char header[FLIC_HEADER_SIZE];\n\n AVStream *st;\n\n int speed;\n\n int magic_number;\n\n\n\n flic->pts = 0;\n\n\n\n /* load the whole header and pull out the width and height */\n\n if (get_buffer(pb, header, FLIC_HEADER_SIZE) != FLIC_HEADER_SIZE)\n\n return AVERROR(EIO);\n\n\n\n magic_number = AV_RL16(&header[4]);\n\n speed = AV_RL32(&header[0x10]);\n\n\n\n /* initialize the decoder streams */\n\n st = av_new_stream(s, 0);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n flic->video_stream_index = st->index;\n\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n\n st->codec->codec_id = CODEC_ID_FLIC;\n\n st->codec->codec_tag = 0; /* no fourcc */\n\n st->codec->width = AV_RL16(&header[0x08]);\n\n st->codec->height = AV_RL16(&header[0x0A]);\n\n\n\n if (!st->codec->width || !st->codec->height)\n\n return AVERROR_INVALIDDATA;\n\n\n\n /* send over the whole 128-byte FLIC header */\n\n st->codec->extradata_size = FLIC_HEADER_SIZE;\n\n st->codec->extradata = av_malloc(FLIC_HEADER_SIZE);\n\n memcpy(st->codec->extradata, header, FLIC_HEADER_SIZE);\n\n\n\n av_set_pts_info(st, 33, 1, 90000);\n\n\n\n /* Time to figure out the framerate: If there is a FLIC chunk magic\n\n * number at offset 0x10, assume this is from the Bullfrog game,\n\n * Magic Carpet. */\n\n if (AV_RL16(&header[0x10]) == FLIC_CHUNK_MAGIC_1) {\n\n\n\n flic->frame_pts_inc = FLIC_MC_PTS_INC;\n\n\n\n /* rewind the stream since the first chunk is at offset 12 */\n\n url_fseek(pb, 12, SEEK_SET);\n\n\n\n /* send over abbreviated FLIC header chunk */\n\n av_free(st->codec->extradata);\n\n st->codec->extradata_size = 12;\n\n st->codec->extradata = av_malloc(12);\n\n memcpy(st->codec->extradata, header, 12);\n\n\n\n } else if (magic_number == FLIC_FILE_MAGIC_1) {\n\n /*\n\n * in this case, the speed (n) is number of 1/70s ticks between frames:\n\n *\n\n * pts n * frame #\n\n * -------- = ----------- => pts = n * (90000/70) * frame #\n\n * 90000 70\n\n *\n\n * therefore, the frame pts increment = n * 1285.7\n\n */\n\n flic->frame_pts_inc = speed * 1285.7;\n\n } else if ((magic_number == FLIC_FILE_MAGIC_2) ||\n\n (magic_number == FLIC_FILE_MAGIC_3)) {\n\n /*\n\n * in this case, the speed (n) is number of milliseconds between frames:\n\n *\n\n * pts n * frame #\n\n * -------- = ----------- => pts = n * 90 * frame #\n\n * 90000 1000\n\n *\n\n * therefore, the frame pts increment = n * 90\n\n */\n\n flic->frame_pts_inc = speed * 90;\n\n } else {\n\n av_log(s, AV_LOG_INFO, \"Invalid or unsupported magic chunk in file\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n if (flic->frame_pts_inc == 0)\n\n flic->frame_pts_inc = FLIC_DEFAULT_PTS_INC;\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 18807 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void tlb_fill(unsigned long addr, int is_write, int is_user, void *retaddr)\n\n{\n\n TranslationBlock *tb;\n\n CPUState *saved_env;\n\n unsigned long pc;\n\n int ret;\n\n\n\n /* XXX: hack to restore env in all cases, even if not called from\n\n generated code */\n\n saved_env = env;\n\n env = cpu_single_env;\n\n {\n\n unsigned long tlb_addrr, tlb_addrw;\n\n int index;\n\n index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);\n\n tlb_addrr = env->tlb_read[is_user][index].address;\n\n tlb_addrw = env->tlb_write[is_user][index].address;\n\n#if 0\n\n if (loglevel) {\n\n fprintf(logfile,\n\n \"%s 1 %p %p idx=%d addr=0x%08lx tbl_addr=0x%08lx 0x%08lx \"\n\n \"(0x%08lx 0x%08lx)\\n\", __func__, env,\n\n &env->tlb_read[is_user][index], index, addr,\n\n tlb_addrr, tlb_addrw, addr & TARGET_PAGE_MASK,\n\n tlb_addrr & (TARGET_PAGE_MASK | TLB_INVALID_MASK));\n\n }\n\n#endif\n\n }\n\n ret = cpu_ppc_handle_mmu_fault(env, addr, is_write, is_user, 1);\n\n if (ret) {\n\n if (retaddr) {\n\n /* now we have a real cpu fault */\n\n pc = (unsigned long)retaddr;\n\n tb = tb_find_pc(pc);\n\n if (tb) {\n\n /* the PC is inside the translated code. It means that we have\n\n a virtual CPU fault */\n\n cpu_restore_state(tb, env, pc, NULL);\n\n }\n\n }\n\n do_raise_exception_err(env->exception_index, env->error_code);\n\n }\n\n {\n\n unsigned long tlb_addrr, tlb_addrw;\n\n int index;\n\n index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);\n\n tlb_addrr = env->tlb_read[is_user][index].address;\n\n tlb_addrw = env->tlb_write[is_user][index].address;\n\n#if 0\n\n printf(\"%s 2 %p %p idx=%d addr=0x%08lx tbl_addr=0x%08lx 0x%08lx \"\n\n \"(0x%08lx 0x%08lx)\\n\", __func__, env,\n\n &env->tlb_read[is_user][index], index, addr,\n\n tlb_addrr, tlb_addrw, addr & TARGET_PAGE_MASK,\n\n tlb_addrr & (TARGET_PAGE_MASK | TLB_INVALID_MASK));\n\n#endif\n\n }\n\n env = saved_env;\n\n}\n", + "output": "0", + "index": 7329 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,\n\n uint8_t *header_idx, int frame_code)\n\n{\n\n AVFormatContext *s = nut->avf;\n\n AVIOContext *bc = s->pb;\n\n StreamContext *stc;\n\n int size, flags, size_mul, pts_delta, i, reserved_count;\n\n uint64_t tmp;\n\n\n\n if (avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"Last frame must have been damaged %\"PRId64\" > %\"PRId64\" + %d\\n\",\n\n avio_tell(bc), nut->last_syncpoint_pos, nut->max_distance);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n flags = nut->frame_code[frame_code].flags;\n\n size_mul = nut->frame_code[frame_code].size_mul;\n\n size = nut->frame_code[frame_code].size_lsb;\n\n *stream_id = nut->frame_code[frame_code].stream_id;\n\n pts_delta = nut->frame_code[frame_code].pts_delta;\n\n reserved_count = nut->frame_code[frame_code].reserved_count;\n\n *header_idx = nut->frame_code[frame_code].header_idx;\n\n\n\n if (flags & FLAG_INVALID)\n\n return AVERROR_INVALIDDATA;\n\n if (flags & FLAG_CODED)\n\n flags ^= ffio_read_varlen(bc);\n\n if (flags & FLAG_STREAM_ID) {\n\n GET_V(*stream_id, tmp < s->nb_streams);\n\n }\n\n stc = &nut->stream[*stream_id];\n\n if (flags & FLAG_CODED_PTS) {\n\n int coded_pts = ffio_read_varlen(bc);\n\n // FIXME check last_pts validity?\n\n if (coded_pts < (1 << stc->msb_pts_shift)) {\n\n *pts = ff_lsb2full(stc, coded_pts);\n\n } else\n\n *pts = coded_pts - (1 << stc->msb_pts_shift);\n\n } else\n\n *pts = stc->last_pts + pts_delta;\n\n if (flags & FLAG_SIZE_MSB)\n\n size += size_mul * ffio_read_varlen(bc);\n\n if (flags & FLAG_MATCH_TIME)\n\n get_s(bc);\n\n if (flags & FLAG_HEADER_IDX)\n\n *header_idx = ffio_read_varlen(bc);\n\n if (flags & FLAG_RESERVED)\n\n reserved_count = ffio_read_varlen(bc);\n\n for (i = 0; i < reserved_count; i++)\n\n ffio_read_varlen(bc);\n\n\n\n if (*header_idx >= (unsigned)nut->header_count) {\n\n av_log(s, AV_LOG_ERROR, \"header_idx invalid\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n if (size > 4096)\n\n *header_idx = 0;\n\n size -= nut->header_len[*header_idx];\n\n\n\n if (flags & FLAG_CHECKSUM) {\n\n avio_rb32(bc); // FIXME check this\n\n } else if (size > 2 * nut->max_distance || FFABS(stc->last_pts - *pts) >\n\n stc->max_pts_distance) {\n\n av_log(s, AV_LOG_ERROR, \"frame size > 2max_distance and no checksum\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n stc->last_pts = *pts;\n\n stc->last_flags = flags;\n\n\n\n return size;\n\n}\n", + "output": "1", + "index": 20044 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int caca_write_header(AVFormatContext *s)\n\n{\n\n CACAContext *c = s->priv_data;\n\n AVStream *st = s->streams[0];\n\n AVCodecContext *encctx = st->codec;\n\n int ret, bpp;\n\n\n\n c->ctx = s;\n\n if (c->list_drivers) {\n\n list_drivers(c);\n\n return AVERROR_EXIT;\n\n }\n\n if (c->list_dither) {\n\n if (!strcmp(c->list_dither, \"colors\")) {\n\n list_dither_color(c);\n\n } else if (!strcmp(c->list_dither, \"charsets\")) {\n\n list_dither_charset(c);\n\n } else if (!strcmp(c->list_dither, \"algorithms\")) {\n\n list_dither_algorithm(c);\n\n } else if (!strcmp(c->list_dither, \"antialiases\")) {\n\n list_dither_antialias(c);\n\n } else {\n\n av_log(s, AV_LOG_ERROR,\n\n \"Invalid argument '%s', for 'list_dither' option\\n\"\n\n \"Argument must be one of 'algorithms, 'antialiases', 'charsets', 'colors'\\n\",\n\n c->list_dither);\n\n return AVERROR(EINVAL);\n\n }\n\n return AVERROR_EXIT;\n\n }\n\n\n\n if ( s->nb_streams > 1\n\n || encctx->codec_type != AVMEDIA_TYPE_VIDEO\n\n || encctx->codec_id != CODEC_ID_RAWVIDEO) {\n\n av_log(s, AV_LOG_ERROR, \"Only supports one rawvideo stream\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n if (encctx->pix_fmt != PIX_FMT_RGB24) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"Unsupported pixel format '%s', choose rgb24\\n\",\n\n av_get_pix_fmt_name(encctx->pix_fmt));\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n c->canvas = caca_create_canvas(c->window_width, c->window_height);\n\n if (!c->canvas) {\n\n av_log(s, AV_LOG_ERROR, \"Failed to create canvas\\n\");\n\n return AVERROR(errno);\n\n }\n\n\n\n c->display = caca_create_display_with_driver(c->canvas, c->driver);\n\n if (!c->display) {\n\n av_log(s, AV_LOG_ERROR, \"Failed to create display\\n\");\n\n list_drivers(c);\n\n caca_free_canvas(c->canvas);\n\n return AVERROR(errno);\n\n }\n\n\n\n if (!c->window_width || !c->window_height) {\n\n c->window_width = caca_get_canvas_width(c->canvas);\n\n c->window_height = caca_get_canvas_height(c->canvas);\n\n }\n\n\n\n bpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[encctx->pix_fmt]);\n\n c->dither = caca_create_dither(bpp, encctx->width, encctx->height,\n\n bpp / 8 * encctx->width,\n\n 0x0000ff, 0x00ff00, 0xff0000, 0);\n\n if (!c->dither) {\n\n av_log(s, AV_LOG_ERROR, \"Failed to create dither\\n\");\n\n ret = AVERROR(errno);\n\n goto fail;\n\n }\n\n\n\n#define CHECK_DITHER_OPT(opt) \\\n\n if (caca_set_dither_##opt(c->dither, c->opt) < 0) { \\\n\n ret = AVERROR(errno); \\\n\n av_log(s, AV_LOG_ERROR, \"Failed to set value '%s' for option '%s'\\n\", \\\n\n c->opt, #opt); \\\n\n goto fail; \\\n\n }\n\n CHECK_DITHER_OPT(algorithm);\n\n CHECK_DITHER_OPT(antialias);\n\n CHECK_DITHER_OPT(charset);\n\n CHECK_DITHER_OPT(color);\n\n\n\n if (!c->window_title)\n\n c->window_title = av_strdup(s->filename);\n\n caca_set_display_title(c->display, c->window_title);\n\n caca_set_display_time(c->display, av_rescale_q(1, st->codec->time_base, AV_TIME_BASE_Q));\n\n\n\n return 0;\n\n\n\nfail:\n\n caca_write_trailer(s);\n\n return ret;\n\n}\n", + "output": "1", + "index": 11391 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int xen_pt_register_regions(XenPCIPassthroughState *s)\n\n{\n\n int i = 0;\n\n XenHostPCIDevice *d = &s->real_device;\n\n\n\n /* Register PIO/MMIO BARs */\n\n for (i = 0; i < PCI_ROM_SLOT; i++) {\n\n XenHostPCIIORegion *r = &d->io_regions[i];\n\n uint8_t type;\n\n\n\n if (r->base_addr == 0 || r->size == 0) {\n\n continue;\n\n }\n\n\n\n s->bases[i].access.u = r->base_addr;\n\n\n\n if (r->type & XEN_HOST_PCI_REGION_TYPE_IO) {\n\n type = PCI_BASE_ADDRESS_SPACE_IO;\n\n } else {\n\n type = PCI_BASE_ADDRESS_SPACE_MEMORY;\n\n if (r->type & XEN_HOST_PCI_REGION_TYPE_PREFETCH) {\n\n type |= PCI_BASE_ADDRESS_MEM_PREFETCH;\n\n }\n\n if (r->type & XEN_HOST_PCI_REGION_TYPE_MEM_64) {\n\n type |= PCI_BASE_ADDRESS_MEM_TYPE_64;\n\n }\n\n }\n\n\n\n memory_region_init_io(&s->bar[i], OBJECT(s), &ops, &s->dev,\n\n \"xen-pci-pt-bar\", r->size);\n\n pci_register_bar(&s->dev, i, type, &s->bar[i]);\n\n\n\n XEN_PT_LOG(&s->dev, \"IO region %i registered (size=0x%08\"PRIx64\n\n \" base_addr=0x%08\"PRIx64\" type: %#x)\\n\",\n\n i, r->size, r->base_addr, type);\n\n }\n\n\n\n /* Register expansion ROM address */\n\n if (d->rom.base_addr && d->rom.size) {\n\n uint32_t bar_data = 0;\n\n\n\n /* Re-set BAR reported by OS, otherwise ROM can't be read. */\n\n if (xen_host_pci_get_long(d, PCI_ROM_ADDRESS, &bar_data)) {\n\n return 0;\n\n }\n\n if ((bar_data & PCI_ROM_ADDRESS_MASK) == 0) {\n\n bar_data |= d->rom.base_addr & PCI_ROM_ADDRESS_MASK;\n\n xen_host_pci_set_long(d, PCI_ROM_ADDRESS, bar_data);\n\n }\n\n\n\n s->bases[PCI_ROM_SLOT].access.maddr = d->rom.base_addr;\n\n\n\n memory_region_init_io(&s->rom, OBJECT(s), &ops, &s->dev,\n\n \"xen-pci-pt-rom\", d->rom.size);\n\n pci_register_bar(&s->dev, PCI_ROM_SLOT, PCI_BASE_ADDRESS_MEM_PREFETCH,\n\n &s->rom);\n\n\n\n XEN_PT_LOG(&s->dev, \"Expansion ROM registered (size=0x%08\"PRIx64\n\n \" base_addr=0x%08\"PRIx64\")\\n\",\n\n d->rom.size, d->rom.base_addr);\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 9784 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static ssize_t sdp_svc_search(struct bt_l2cap_sdp_state_s *sdp,\n\n uint8_t *rsp, const uint8_t *req, ssize_t len)\n\n{\n\n ssize_t seqlen;\n\n int i, count, start, end, max;\n\n int32_t handle;\n\n\n\n /* Perform the search */\n\n for (i = 0; i < sdp->services; i ++)\n\n sdp->service_list[i].match = 0;\n\n\n\n if (len < 1)\n\n return -SDP_INVALID_SYNTAX;\n\n if ((*req & ~SDP_DSIZE_MASK) == SDP_DTYPE_SEQ) {\n\n seqlen = sdp_datalen(&req, &len);\n\n if (seqlen < 3 || len < seqlen)\n\n return -SDP_INVALID_SYNTAX;\n\n len -= seqlen;\n\n\n\n while (seqlen)\n\n if (sdp_svc_match(sdp, &req, &seqlen))\n\n return -SDP_INVALID_SYNTAX;\n\n } else if (sdp_svc_match(sdp, &req, &seqlen))\n\n return -SDP_INVALID_SYNTAX;\n\n\n\n if (len < 3)\n\n return -SDP_INVALID_SYNTAX;\n\n max = (req[0] << 8) | req[1];\n\n req += 2;\n\n len -= 2;\n\n\n\n if (*req) {\n\n if (len <= sizeof(int))\n\n return -SDP_INVALID_SYNTAX;\n\n len -= sizeof(int);\n\n memcpy(&start, req + 1, sizeof(int));\n\n } else\n\n start = 0;\n\n\n\n if (len > 1)\n\n return -SDP_INVALID_SYNTAX;\n\n\n\n /* Output the results */\n\n len = 4;\n\n count = 0;\n\n end = start;\n\n for (i = 0; i < sdp->services; i ++)\n\n if (sdp->service_list[i].match) {\n\n if (count >= start && count < max && len + 4 < MAX_RSP_PARAM_SIZE) {\n\n handle = i;\n\n memcpy(rsp + len, &handle, 4);\n\n len += 4;\n\n end = count + 1;\n\n }\n\n\n\n count ++;\n\n }\n\n\n\n rsp[0] = count >> 8;\n\n rsp[1] = count & 0xff;\n\n rsp[2] = (end - start) >> 8;\n\n rsp[3] = (end - start) & 0xff;\n\n\n\n if (end < count) {\n\n rsp[len ++] = sizeof(int);\n\n memcpy(rsp + len, &end, sizeof(int));\n\n len += 4;\n\n } else\n\n rsp[len ++] = 0;\n\n\n\n return len;\n\n}\n", + "output": "1", + "index": 9794 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number)\n\n{\n\n int time_incr;\n\n int time_div, time_mod;\n\n\n\n if(s->pict_type==AV_PICTURE_TYPE_I){\n\n if(!(s->flags&CODEC_FLAG_GLOBAL_HEADER)){\n\n if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) //HACK, the reference sw is buggy\n\n mpeg4_encode_visual_object_header(s);\n\n if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || picture_number==0) //HACK, the reference sw is buggy\n\n mpeg4_encode_vol_header(s, 0, 0);\n\n }\n\n if(!(s->workaround_bugs & FF_BUG_MS))\n\n mpeg4_encode_gop_header(s);\n\n }\n\n\n\n s->partitioned_frame= s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_B;\n\n\n\n put_bits(&s->pb, 16, 0); /* vop header */\n\n put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */\n\n put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */\n\n\n\n assert(s->time>=0);\n\n time_div= s->time/s->avctx->time_base.den;\n\n time_mod= s->time%s->avctx->time_base.den;\n\n time_incr= time_div - s->last_time_base;\n\n assert(time_incr >= 0);\n\n while(time_incr--)\n\n put_bits(&s->pb, 1, 1);\n\n\n\n put_bits(&s->pb, 1, 0);\n\n\n\n put_bits(&s->pb, 1, 1); /* marker */\n\n put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */\n\n put_bits(&s->pb, 1, 1); /* marker */\n\n put_bits(&s->pb, 1, 1); /* vop coded */\n\n if ( s->pict_type == AV_PICTURE_TYPE_P\n\n || (s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE)) {\n\n put_bits(&s->pb, 1, s->no_rounding); /* rounding type */\n\n }\n\n put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */\n\n if(!s->progressive_sequence){\n\n put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first);\n\n put_bits(&s->pb, 1, s->alternate_scan);\n\n }\n\n //FIXME sprite stuff\n\n\n\n put_bits(&s->pb, 5, s->qscale);\n\n\n\n if (s->pict_type != AV_PICTURE_TYPE_I)\n\n put_bits(&s->pb, 3, s->f_code); /* fcode_for */\n\n if (s->pict_type == AV_PICTURE_TYPE_B)\n\n put_bits(&s->pb, 3, s->b_code); /* fcode_back */\n\n}\n", + "output": "0", + "index": 14872 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void generate_joint_tables(HYuvContext *s)\n\n{\n\n uint16_t symbols[1 << VLC_BITS];\n\n uint16_t bits[1 << VLC_BITS];\n\n uint8_t len[1 << VLC_BITS];\n\n if (s->bitstream_bpp < 24) {\n\n int p, i, y, u;\n\n for (p = 0; p < 3; p++) {\n\n for (i = y = 0; y < 256; y++) {\n\n int len0 = s->len[0][y];\n\n int limit = VLC_BITS - len0;\n\n if (limit <= 0)\n\n continue;\n\n for (u = 0; u < 256; u++) {\n\n int len1 = s->len[p][u];\n\n if (len1 > limit)\n\n continue;\n\n len[i] = len0 + len1;\n\n bits[i] = (s->bits[0][y] << len1) + s->bits[p][u];\n\n symbols[i] = (y << 8) + u;\n\n if (symbols[i] != 0xffff) // reserved to mean \"invalid\"\n\n i++;\n\n }\n\n }\n\n ff_free_vlc(&s->vlc[3 + p]);\n\n ff_init_vlc_sparse(&s->vlc[3 + p], VLC_BITS, i, len, 1, 1,\n\n bits, 2, 2, symbols, 2, 2, 0);\n\n }\n\n } else {\n\n uint8_t (*map)[4] = (uint8_t(*)[4]) s->pix_bgr_map;\n\n int i, b, g, r, code;\n\n int p0 = s->decorrelate;\n\n int p1 = !s->decorrelate;\n\n /* Restrict the range to +/-16 because that's pretty much guaranteed\n\n * to cover all the combinations that fit in 11 bits total, and it\n\n * does not matter if we miss a few rare codes. */\n\n for (i = 0, g = -16; g < 16; g++) {\n\n int len0 = s->len[p0][g & 255];\n\n int limit0 = VLC_BITS - len0;\n\n if (limit0 < 2)\n\n continue;\n\n for (b = -16; b < 16; b++) {\n\n int len1 = s->len[p1][b & 255];\n\n int limit1 = limit0 - len1;\n\n if (limit1 < 1)\n\n continue;\n\n code = (s->bits[p0][g & 255] << len1) + s->bits[p1][b & 255];\n\n for (r = -16; r < 16; r++) {\n\n int len2 = s->len[2][r & 255];\n\n if (len2 > limit1)\n\n continue;\n\n len[i] = len0 + len1 + len2;\n\n bits[i] = (code << len2) + s->bits[2][r & 255];\n\n if (s->decorrelate) {\n\n map[i][G] = g;\n\n map[i][B] = g + b;\n\n map[i][R] = g + r;\n\n } else {\n\n map[i][B] = g;\n\n map[i][G] = b;\n\n map[i][R] = r;\n\n }\n\n i++;\n\n }\n\n }\n\n }\n\n ff_free_vlc(&s->vlc[3]);\n\n init_vlc(&s->vlc[3], VLC_BITS, i, len, 1, 1, bits, 2, 2, 0);\n\n }\n\n}\n", + "output": "1", + "index": 3887 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void cpu_loop(CPUMBState *env)\n\n{\n\n int trapnr, ret;\n\n target_siginfo_t info;\n\n \n\n while (1) {\n\n trapnr = cpu_mb_exec (env);\n\n switch (trapnr) {\n\n case 0xaa:\n\n {\n\n info.si_signo = SIGSEGV;\n\n info.si_errno = 0;\n\n /* XXX: check env->error_code */\n\n info.si_code = TARGET_SEGV_MAPERR;\n\n info._sifields._sigfault._addr = 0;\n\n queue_signal(env, info.si_signo, &info);\n\n }\n\n break;\n\n\tcase EXCP_INTERRUPT:\n\n\t /* just indicate that signals should be handled asap */\n\n\t break;\n\n case EXCP_BREAK:\n\n /* Return address is 4 bytes after the call. */\n\n env->regs[14] += 4;\n\n ret = do_syscall(env, \n\n env->regs[12], \n\n env->regs[5], \n\n env->regs[6], \n\n env->regs[7], \n\n env->regs[8], \n\n env->regs[9], \n\n env->regs[10],\n\n 0, 0);\n\n env->regs[3] = ret;\n\n env->sregs[SR_PC] = env->regs[14];\n\n break;\n\n case EXCP_HW_EXCP:\n\n env->regs[17] = env->sregs[SR_PC] + 4;\n\n if (env->iflags & D_FLAG) {\n\n env->sregs[SR_ESR] |= 1 << 12;\n\n env->sregs[SR_PC] -= 4;\n\n /* FIXME: if branch was immed, replay the imm as well. */\n\n }\n\n\n\n env->iflags &= ~(IMM_FLAG | D_FLAG);\n\n\n\n switch (env->sregs[SR_ESR] & 31) {\n\n case ESR_EC_DIVZERO:\n\n info.si_signo = SIGFPE;\n\n info.si_errno = 0;\n\n info.si_code = TARGET_FPE_FLTDIV;\n\n info._sifields._sigfault._addr = 0;\n\n queue_signal(env, info.si_signo, &info);\n\n break;\n\n case ESR_EC_FPU:\n\n info.si_signo = SIGFPE;\n\n info.si_errno = 0;\n\n if (env->sregs[SR_FSR] & FSR_IO) {\n\n info.si_code = TARGET_FPE_FLTINV;\n\n }\n\n if (env->sregs[SR_FSR] & FSR_DZ) {\n\n info.si_code = TARGET_FPE_FLTDIV;\n\n }\n\n info._sifields._sigfault._addr = 0;\n\n queue_signal(env, info.si_signo, &info);\n\n break;\n\n default:\n\n printf (\"Unhandled hw-exception: 0x%x\\n\",\n\n env->sregs[SR_ESR] & ESR_EC_MASK);\n\n cpu_dump_state(env, stderr, fprintf, 0);\n\n exit (1);\n\n break;\n\n }\n\n break;\n\n case EXCP_DEBUG:\n\n {\n\n int sig;\n\n\n\n sig = gdb_handlesig (env, TARGET_SIGTRAP);\n\n if (sig)\n\n {\n\n info.si_signo = sig;\n\n info.si_errno = 0;\n\n info.si_code = TARGET_TRAP_BRKPT;\n\n queue_signal(env, info.si_signo, &info);\n\n }\n\n }\n\n break;\n\n default:\n\n printf (\"Unhandled trap: 0x%x\\n\", trapnr);\n\n cpu_dump_state(env, stderr, fprintf, 0);\n\n exit (1);\n\n }\n\n process_pending_signals (env);\n\n }\n\n}\n", + "output": "1", + "index": 23338 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int mpegts_read_header(AVFormatContext *s,\n\n AVFormatParameters *ap)\n\n{\n\n MpegTSContext *ts = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n uint8_t buf[5*1024];\n\n int len;\n\n int64_t pos;\n\n\n\n#if FF_API_FORMAT_PARAMETERS\n\n if (ap) {\n\n if (ap->mpeg2ts_compute_pcr)\n\n ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr;\n\n if(ap->mpeg2ts_raw){\n\n av_log(s, AV_LOG_ERROR, \"use mpegtsraw_demuxer!\\n\");\n\n return -1;\n\n }\n\n }\n\n#endif\n\n\n\n /* read the first 1024 bytes to get packet size */\n\n pos = avio_tell(pb);\n\n len = avio_read(pb, buf, sizeof(buf));\n\n if (len != sizeof(buf))\n\n goto fail;\n\n ts->raw_packet_size = get_packet_size(buf, sizeof(buf));\n\n if (ts->raw_packet_size <= 0)\n\n goto fail;\n\n ts->stream = s;\n\n ts->auto_guess = 0;\n\n\n\n if (s->iformat == &ff_mpegts_demuxer) {\n\n /* normal demux */\n\n\n\n /* first do a scaning to get all the services */\n\n if (avio_seek(pb, pos, SEEK_SET) < 0)\n\n av_log(s, AV_LOG_ERROR, \"Unable to seek back to the start\\n\");\n\n\n\n mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1);\n\n\n\n mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1);\n\n\n\n handle_packets(ts, s->probesize / ts->raw_packet_size);\n\n /* if could not find service, enable auto_guess */\n\n\n\n ts->auto_guess = 1;\n\n\n\n av_dlog(ts->stream, \"tuning done\\n\");\n\n\n\n s->ctx_flags |= AVFMTCTX_NOHEADER;\n\n } else {\n\n AVStream *st;\n\n int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;\n\n int64_t pcrs[2], pcr_h;\n\n int packet_count[2];\n\n uint8_t packet[TS_PACKET_SIZE];\n\n\n\n /* only read packets */\n\n\n\n st = av_new_stream(s, 0);\n\n if (!st)\n\n goto fail;\n\n av_set_pts_info(st, 60, 1, 27000000);\n\n st->codec->codec_type = AVMEDIA_TYPE_DATA;\n\n st->codec->codec_id = CODEC_ID_MPEG2TS;\n\n\n\n /* we iterate until we find two PCRs to estimate the bitrate */\n\n pcr_pid = -1;\n\n nb_pcrs = 0;\n\n nb_packets = 0;\n\n for(;;) {\n\n ret = read_packet(s, packet, ts->raw_packet_size);\n\n if (ret < 0)\n\n return -1;\n\n pid = AV_RB16(packet + 1) & 0x1fff;\n\n if ((pcr_pid == -1 || pcr_pid == pid) &&\n\n parse_pcr(&pcr_h, &pcr_l, packet) == 0) {\n\n pcr_pid = pid;\n\n packet_count[nb_pcrs] = nb_packets;\n\n pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;\n\n nb_pcrs++;\n\n if (nb_pcrs >= 2)\n\n break;\n\n }\n\n nb_packets++;\n\n }\n\n\n\n /* NOTE1: the bitrate is computed without the FEC */\n\n /* NOTE2: it is only the bitrate of the start of the stream */\n\n ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);\n\n ts->cur_pcr = pcrs[0] - ts->pcr_incr * packet_count[0];\n\n s->bit_rate = (TS_PACKET_SIZE * 8) * 27e6 / ts->pcr_incr;\n\n st->codec->bit_rate = s->bit_rate;\n\n st->start_time = ts->cur_pcr;\n\n av_dlog(ts->stream, \"start=%0.3f pcr=%0.3f incr=%d\\n\",\n\n st->start_time / 1000000.0, pcrs[0] / 27e6, ts->pcr_incr);\n\n }\n\n\n\n avio_seek(pb, pos, SEEK_SET);\n\n return 0;\n\n fail:\n\n return -1;\n\n}\n", + "output": "0", + "index": 22424 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold int libopus_decode_init(AVCodecContext *avc)\n{\n struct libopus_context *opus = avc->priv_data;\n int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;\n uint8_t mapping_arr[8] = { 0, 1 }, *mapping;\n avc->sample_rate = 48000;\n avc->sample_fmt = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?\n AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;\n avc->channel_layout = avc->channels > 8 ? 0 :\n ff_vorbis_channel_layouts[avc->channels - 1];\n if (avc->extradata_size >= OPUS_HEAD_SIZE) {\n gain_db = sign_extend(AV_RL16(avc->extradata + 16), 16);\n channel_map = AV_RL8 (avc->extradata + 18);\n if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + avc->channels) {\n nb_streams = avc->extradata[OPUS_HEAD_SIZE + 0];\n nb_coupled = avc->extradata[OPUS_HEAD_SIZE + 1];\n if (nb_streams + nb_coupled != avc->channels)\n av_log(avc, AV_LOG_WARNING, \"Inconsistent channel mapping.\\n\");\n mapping = avc->extradata + OPUS_HEAD_SIZE + 2;\n } else {\n if (avc->channels > 2 || channel_map) {\n av_log(avc, AV_LOG_ERROR,\n \"No channel mapping for %d channels.\\n\", avc->channels);\n return AVERROR(EINVAL);\n nb_streams = 1;\n nb_coupled = avc->channels > 1;\n mapping = mapping_arr;\n if (avc->channels > 2 && avc->channels <= 8) {\n const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[avc->channels - 1];\n int ch;\n /* Remap channels from Vorbis order to libav order */\n for (ch = 0; ch < avc->channels; ch++)\n mapping_arr[ch] = mapping[vorbis_offset[ch]];\n mapping = mapping_arr;\n opus->dec = opus_multistream_decoder_create(avc->sample_rate, avc->channels,\n nb_streams, nb_coupled,\n mapping, &ret);\n if (!opus->dec) {\n av_log(avc, AV_LOG_ERROR, \"Unable to create decoder: %s\\n\",\n opus_strerror(ret));\n return ff_opus_error_to_averror(ret);\n ret = opus_multistream_decoder_ctl(opus->dec, OPUS_SET_GAIN(gain_db));\n if (ret != OPUS_OK)\n av_log(avc, AV_LOG_WARNING, \"Failed to set gain: %s\\n\",\n opus_strerror(ret));\n avc->delay = 3840; /* Decoder delay (in samples) at 48kHz */\n return 0;", + "output": "1", + "index": 19618 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)\n\n{\n\n AVFrame *frame_current, *frame_ref;\n\n VP56mb mb_type;\n\n VP56Frame ref_frame;\n\n int b, ab, b_max, plane, off;\n\n\n\n if (s->frames[VP56_FRAME_CURRENT]->key_frame)\n\n mb_type = VP56_MB_INTRA;\n\n else\n\n mb_type = vp56_decode_mv(s, row, col);\n\n ref_frame = ff_vp56_reference_frame[mb_type];\n\n\n\n s->parse_coeff(s);\n\n\n\n vp56_add_predictors_dc(s, ref_frame);\n\n\n\n frame_current = s->frames[VP56_FRAME_CURRENT];\n\n frame_ref = s->frames[ref_frame];\n\n if (mb_type != VP56_MB_INTRA && !frame_ref->data[0])\n\n return;\n\n\n\n ab = 6*is_alpha;\n\n b_max = 6 - 2*is_alpha;\n\n\n\n switch (mb_type) {\n\n case VP56_MB_INTRA:\n\n for (b=0; bvp3dsp.idct_put(frame_current->data[plane] + s->block_offset[b],\n\n s->stride[plane], s->block_coeff[b]);\n\n }\n\n break;\n\n\n\n case VP56_MB_INTER_NOVEC_PF:\n\n case VP56_MB_INTER_NOVEC_GF:\n\n for (b=0; bblock_offset[b];\n\n s->hdsp.put_pixels_tab[1][0](frame_current->data[plane] + off,\n\n frame_ref->data[plane] + off,\n\n s->stride[plane], 8);\n\n s->vp3dsp.idct_add(frame_current->data[plane] + off,\n\n s->stride[plane], s->block_coeff[b]);\n\n }\n\n break;\n\n\n\n case VP56_MB_INTER_DELTA_PF:\n\n case VP56_MB_INTER_V1_PF:\n\n case VP56_MB_INTER_V2_PF:\n\n case VP56_MB_INTER_DELTA_GF:\n\n case VP56_MB_INTER_4V:\n\n case VP56_MB_INTER_V1_GF:\n\n case VP56_MB_INTER_V2_GF:\n\n for (b=0; bdata[plane], s->stride[plane],\n\n 16*col+x_off, 16*row+y_off);\n\n s->vp3dsp.idct_add(frame_current->data[plane] + s->block_offset[b],\n\n s->stride[plane], s->block_coeff[b]);\n\n }\n\n break;\n\n }\n\n\n\n if (is_alpha) {\n\n s->block_coeff[4][0] = 0;\n\n s->block_coeff[5][0] = 0;\n\n }\n\n}\n", + "output": "1", + "index": 4695 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length)\n\n{\n\n int x, y;\n\n const int width = f->avctx->width;\n\n const int height = f->avctx->height;\n\n uint16_t *src = (uint16_t *)f->last_picture.data[0];\n\n uint16_t *dst = (uint16_t *)f->current_picture.data[0];\n\n const int stride = f->current_picture.linesize[0] >> 1;\n\n unsigned int bitstream_size, bytestream_size, wordstream_size, extra,\n\n bytestream_offset, wordstream_offset;\n\n\n\n if (f->version > 1) {\n\n extra = 20;\n\n if (length < extra)\n\n return -1;\n\n bitstream_size = AV_RL32(buf + 8);\n\n wordstream_size = AV_RL32(buf + 12);\n\n bytestream_size = AV_RL32(buf + 16);\n\n } else {\n\n extra = 0;\n\n bitstream_size = AV_RL16(buf - 4);\n\n wordstream_size = AV_RL16(buf - 2);\n\n bytestream_size = FFMAX(length - bitstream_size - wordstream_size, 0);\n\n }\n\n\n\n if (bitstream_size > length ||\n\n bytestream_size > length - bitstream_size ||\n\n wordstream_size > length - bytestream_size - bitstream_size ||\n\n extra > length - bytestream_size - bitstream_size - wordstream_size) {\n\n av_log(f->avctx, AV_LOG_ERROR, \"lengths %d %d %d %d\\n\", bitstream_size, bytestream_size, wordstream_size,\n\n bitstream_size+ bytestream_size+ wordstream_size - length);\n\n return -1;\n\n }\n\n\n\n av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size,\n\n bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE);\n\n if (!f->bitstream_buffer)\n\n return AVERROR(ENOMEM);\n\n f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra),\n\n bitstream_size / 4);\n\n memset((uint8_t*)f->bitstream_buffer + bitstream_size,\n\n 0, FF_INPUT_BUFFER_PADDING_SIZE);\n\n init_get_bits(&f->gb, f->bitstream_buffer, 8 * bitstream_size);\n\n\n\n wordstream_offset = extra + bitstream_size;\n\n bytestream_offset = extra + bitstream_size + wordstream_size;\n\n bytestream2_init(&f->g2, buf + wordstream_offset,\n\n length - wordstream_offset);\n\n bytestream2_init(&f->g, buf + bytestream_offset,\n\n length - bytestream_offset);\n\n\n\n init_mv(f);\n\n\n\n for (y = 0; y < height; y += 8) {\n\n for (x = 0; x < width; x += 8)\n\n decode_p_block(f, dst + x, src + x, 3, 3, stride);\n\n src += 8 * stride;\n\n dst += 8 * stride;\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 21645 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void RENAME(interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dest,\n\n int width, int height, int src1Stride,\n\n int src2Stride, int dstStride)\n\n{\n\n int h;\n\n\n\n for (h=0; h < height; h++) {\n\n int w;\n\n\n\n if (width >= 16)\n\n#if COMPILE_TEMPLATE_SSE2\n\n __asm__(\n\n \"xor %%\"REG_a\", %%\"REG_a\" \\n\\t\"\n\n \"1: \\n\\t\"\n\n PREFETCH\" 64(%1, %%\"REG_a\") \\n\\t\"\n\n PREFETCH\" 64(%2, %%\"REG_a\") \\n\\t\"\n\n \"movdqa (%1, %%\"REG_a\"), %%xmm0 \\n\\t\"\n\n \"movdqa (%1, %%\"REG_a\"), %%xmm1 \\n\\t\"\n\n \"movdqa (%2, %%\"REG_a\"), %%xmm2 \\n\\t\"\n\n \"punpcklbw %%xmm2, %%xmm0 \\n\\t\"\n\n \"punpckhbw %%xmm2, %%xmm1 \\n\\t\"\n\n \"movntdq %%xmm0, (%0, %%\"REG_a\", 2) \\n\\t\"\n\n \"movntdq %%xmm1, 16(%0, %%\"REG_a\", 2) \\n\\t\"\n\n \"add $16, %%\"REG_a\" \\n\\t\"\n\n \"cmp %3, %%\"REG_a\" \\n\\t\"\n\n \" jb 1b \\n\\t\"\n\n ::\"r\"(dest), \"r\"(src1), \"r\"(src2), \"r\" ((x86_reg)width-15)\n\n : \"memory\", XMM_CLOBBERS(\"xmm0\", \"xmm1\", \"xmm2\",) \"%\"REG_a\n\n );\n\n#else\n\n __asm__(\n\n \"xor %%\"REG_a\", %%\"REG_a\" \\n\\t\"\n\n \"1: \\n\\t\"\n\n PREFETCH\" 64(%1, %%\"REG_a\") \\n\\t\"\n\n PREFETCH\" 64(%2, %%\"REG_a\") \\n\\t\"\n\n \"movq (%1, %%\"REG_a\"), %%mm0 \\n\\t\"\n\n \"movq 8(%1, %%\"REG_a\"), %%mm2 \\n\\t\"\n\n \"movq %%mm0, %%mm1 \\n\\t\"\n\n \"movq %%mm2, %%mm3 \\n\\t\"\n\n \"movq (%2, %%\"REG_a\"), %%mm4 \\n\\t\"\n\n \"movq 8(%2, %%\"REG_a\"), %%mm5 \\n\\t\"\n\n \"punpcklbw %%mm4, %%mm0 \\n\\t\"\n\n \"punpckhbw %%mm4, %%mm1 \\n\\t\"\n\n \"punpcklbw %%mm5, %%mm2 \\n\\t\"\n\n \"punpckhbw %%mm5, %%mm3 \\n\\t\"\n\n MOVNTQ\" %%mm0, (%0, %%\"REG_a\", 2) \\n\\t\"\n\n MOVNTQ\" %%mm1, 8(%0, %%\"REG_a\", 2) \\n\\t\"\n\n MOVNTQ\" %%mm2, 16(%0, %%\"REG_a\", 2) \\n\\t\"\n\n MOVNTQ\" %%mm3, 24(%0, %%\"REG_a\", 2) \\n\\t\"\n\n \"add $16, %%\"REG_a\" \\n\\t\"\n\n \"cmp %3, %%\"REG_a\" \\n\\t\"\n\n \" jb 1b \\n\\t\"\n\n ::\"r\"(dest), \"r\"(src1), \"r\"(src2), \"r\" ((x86_reg)width-15)\n\n : \"memory\", \"%\"REG_a\n\n );\n\n#endif\n\n for (w= (width&(~15)); w < width; w++) {\n\n dest[2*w+0] = src1[w];\n\n dest[2*w+1] = src2[w];\n\n }\n\n dest += dstStride;\n\n src1 += src1Stride;\n\n src2 += src2Stride;\n\n }\n\n __asm__(\n\n#if !COMPILE_TEMPLATE_SSE2\n\n EMMS\" \\n\\t\"\n\n#endif\n\n SFENCE\" \\n\\t\"\n\n ::: \"memory\"\n\n );\n\n}\n", + "output": "1", + "index": 23340 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void set_watchdog_timer(IPMIBmcSim *ibs,\n\n uint8_t *cmd, unsigned int cmd_len,\n\n uint8_t *rsp, unsigned int *rsp_len,\n\n unsigned int max_rsp_len)\n\n{\n\n IPMIInterface *s = ibs->parent.intf;\n\n IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s);\n\n unsigned int val;\n\n\n\n IPMI_CHECK_CMD_LEN(8);\n\n val = cmd[2] & 0x7; /* Validate use */\n\n if (val == 0 || val > 5) {\n\n rsp[2] = IPMI_CC_INVALID_DATA_FIELD;\n\n return;\n\n }\n\n val = cmd[3] & 0x7; /* Validate action */\n\n switch (val) {\n\n case IPMI_BMC_WATCHDOG_ACTION_NONE:\n\n break;\n\n\n\n case IPMI_BMC_WATCHDOG_ACTION_RESET:\n\n rsp[2] = k->do_hw_op(s, IPMI_RESET_CHASSIS, 1);\n\n break;\n\n\n\n case IPMI_BMC_WATCHDOG_ACTION_POWER_DOWN:\n\n rsp[2] = k->do_hw_op(s, IPMI_POWEROFF_CHASSIS, 1);\n\n break;\n\n\n\n case IPMI_BMC_WATCHDOG_ACTION_POWER_CYCLE:\n\n rsp[2] = k->do_hw_op(s, IPMI_POWERCYCLE_CHASSIS, 1);\n\n break;\n\n\n\n default:\n\n rsp[2] = IPMI_CC_INVALID_DATA_FIELD;\n\n }\n\n if (rsp[2]) {\n\n rsp[2] = IPMI_CC_INVALID_DATA_FIELD;\n\n return;\n\n }\n\n\n\n val = (cmd[3] >> 4) & 0x7; /* Validate preaction */\n\n switch (val) {\n\n case IPMI_BMC_WATCHDOG_PRE_MSG_INT:\n\n case IPMI_BMC_WATCHDOG_PRE_NONE:\n\n break;\n\n\n\n case IPMI_BMC_WATCHDOG_PRE_NMI:\n\n if (!k->do_hw_op(s, IPMI_SEND_NMI, 1)) {\n\n /* NMI not supported. */\n\n rsp[2] = IPMI_CC_INVALID_DATA_FIELD;\n\n return;\n\n }\n\n break;\n\n\n\n default:\n\n /* We don't support PRE_SMI */\n\n rsp[2] = IPMI_CC_INVALID_DATA_FIELD;\n\n return;\n\n }\n\n\n\n ibs->watchdog_initialized = 1;\n\n ibs->watchdog_use = cmd[2] & IPMI_BMC_WATCHDOG_USE_MASK;\n\n ibs->watchdog_action = cmd[3] & IPMI_BMC_WATCHDOG_ACTION_MASK;\n\n ibs->watchdog_pretimeout = cmd[4];\n\n ibs->watchdog_expired &= ~cmd[5];\n\n ibs->watchdog_timeout = cmd[6] | (((uint16_t) cmd[7]) << 8);\n\n if (ibs->watchdog_running & IPMI_BMC_WATCHDOG_GET_DONT_STOP(ibs)) {\n\n do_watchdog_reset(ibs);\n\n } else {\n\n ibs->watchdog_running = 0;\n\n }\n\n}\n", + "output": "1", + "index": 9146 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void gen_intermediate_code_internal(CPULM32State *env,\n\n TranslationBlock *tb, int search_pc)\n\n{\n\n struct DisasContext ctx, *dc = &ctx;\n\n uint16_t *gen_opc_end;\n\n uint32_t pc_start;\n\n int j, lj;\n\n uint32_t next_page_start;\n\n int num_insns;\n\n int max_insns;\n\n\n\n qemu_log_try_set_file(stderr);\n\n\n\n pc_start = tb->pc;\n\n dc->env = env;\n\n dc->tb = tb;\n\n\n\n gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;\n\n\n\n dc->is_jmp = DISAS_NEXT;\n\n dc->pc = pc_start;\n\n dc->singlestep_enabled = env->singlestep_enabled;\n\n dc->nr_nops = 0;\n\n\n\n if (pc_start & 3) {\n\n cpu_abort(env, \"LM32: unaligned PC=%x\\n\", pc_start);\n\n }\n\n\n\n if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {\n\n qemu_log(\"-----------------------------------------\\n\");\n\n log_cpu_state(env, 0);\n\n }\n\n\n\n next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;\n\n lj = -1;\n\n num_insns = 0;\n\n max_insns = tb->cflags & CF_COUNT_MASK;\n\n if (max_insns == 0) {\n\n max_insns = CF_COUNT_MASK;\n\n }\n\n\n\n gen_icount_start();\n\n do {\n\n check_breakpoint(env, dc);\n\n\n\n if (search_pc) {\n\n j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;\n\n if (lj < j) {\n\n lj++;\n\n while (lj < j) {\n\n tcg_ctx.gen_opc_instr_start[lj++] = 0;\n\n }\n\n }\n\n tcg_ctx.gen_opc_pc[lj] = dc->pc;\n\n tcg_ctx.gen_opc_instr_start[lj] = 1;\n\n tcg_ctx.gen_opc_icount[lj] = num_insns;\n\n }\n\n\n\n /* Pretty disas. */\n\n LOG_DIS(\"%8.8x:\\t\", dc->pc);\n\n\n\n if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) {\n\n gen_io_start();\n\n }\n\n\n\n decode(dc, cpu_ldl_code(env, dc->pc));\n\n dc->pc += 4;\n\n num_insns++;\n\n\n\n } while (!dc->is_jmp\n\n && tcg_ctx.gen_opc_ptr < gen_opc_end\n\n && !env->singlestep_enabled\n\n && !singlestep\n\n && (dc->pc < next_page_start)\n\n && num_insns < max_insns);\n\n\n\n if (tb->cflags & CF_LAST_IO) {\n\n gen_io_end();\n\n }\n\n\n\n if (unlikely(env->singlestep_enabled)) {\n\n if (dc->is_jmp == DISAS_NEXT) {\n\n tcg_gen_movi_tl(cpu_pc, dc->pc);\n\n }\n\n t_gen_raise_exception(dc, EXCP_DEBUG);\n\n } else {\n\n switch (dc->is_jmp) {\n\n case DISAS_NEXT:\n\n gen_goto_tb(dc, 1, dc->pc);\n\n break;\n\n default:\n\n case DISAS_JUMP:\n\n case DISAS_UPDATE:\n\n /* indicate that the hash table must be used\n\n to find the next TB */\n\n tcg_gen_exit_tb(0);\n\n break;\n\n case DISAS_TB_JUMP:\n\n /* nothing more to generate */\n\n break;\n\n }\n\n }\n\n\n\n gen_icount_end(tb, num_insns);\n\n *tcg_ctx.gen_opc_ptr = INDEX_op_end;\n\n if (search_pc) {\n\n j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;\n\n lj++;\n\n while (lj <= j) {\n\n tcg_ctx.gen_opc_instr_start[lj++] = 0;\n\n }\n\n } else {\n\n tb->size = dc->pc - pc_start;\n\n tb->icount = num_insns;\n\n }\n\n\n\n#ifdef DEBUG_DISAS\n\n if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {\n\n qemu_log(\"\\n\");\n\n log_target_disas(env, pc_start, dc->pc - pc_start, 0);\n\n qemu_log(\"\\nisize=%d osize=%td\\n\",\n\n dc->pc - pc_start, tcg_ctx.gen_opc_ptr -\n\n tcg_ctx.gen_opc_buf);\n\n }\n\n#endif\n\n}\n", + "output": "1", + "index": 4643 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void put_frame(\n\n AVFormatContext *s,\n\n ASFStream *stream,\n\n AVStream *avst,\n\n int timestamp,\n\n const uint8_t *buf,\n\n int m_obj_size,\n\n int flags\n\n )\n\n{\n\n ASFContext *asf = s->priv_data;\n\n int m_obj_offset, payload_len, frag_len1;\n\n\n\n m_obj_offset = 0;\n\n while (m_obj_offset < m_obj_size) {\n\n payload_len = m_obj_size - m_obj_offset;\n\n if (asf->packet_timestamp_start == -1) {\n\n asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);\n\n\n\n asf->packet_size_left = PACKET_SIZE;\n\n if (asf->multi_payloads_present){\n\n frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;\n\n }\n\n else {\n\n frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;\n\n }\n\n asf->packet_timestamp_start = timestamp;\n\n }\n\n else {\n\n // multi payloads\n\n frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1;\n\n\n\n asf->packet_timestamp_start = timestamp;\n\n\n\n if(frag_len1 < payload_len && avst->codec->codec_type == CODEC_TYPE_AUDIO){\n\n flush_packet(s);\n\n continue;\n\n }\n\n }\n\n if (frag_len1 > 0) {\n\n if (payload_len > frag_len1)\n\n payload_len = frag_len1;\n\n else if (payload_len == (frag_len1 - 1))\n\n payload_len = frag_len1 - 2; //additional byte need to put padding length\n\n\n\n put_payload_header(s, stream, timestamp+PREROLL_TIME, m_obj_size, m_obj_offset, payload_len, flags);\n\n put_buffer(&asf->pb, buf, payload_len);\n\n\n\n if (asf->multi_payloads_present)\n\n asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS);\n\n else\n\n asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD);\n\n asf->packet_timestamp_end = timestamp;\n\n\n\n asf->packet_nb_payloads++;\n\n } else {\n\n payload_len = 0;\n\n }\n\n m_obj_offset += payload_len;\n\n buf += payload_len;\n\n\n\n if (!asf->multi_payloads_present)\n\n flush_packet(s);\n\n else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + PACKET_HEADER_MIN_SIZE + 1))\n\n flush_packet(s);\n\n }\n\n stream->seq++;\n\n}\n", + "output": "0", + "index": 13027 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)\n\n{\n\n const uint8_t *buf = avpkt->data;\n\n int buf_size = avpkt->size;\n\n VBDecContext * const c = avctx->priv_data;\n\n uint8_t *outptr, *srcptr;\n\n int i, j;\n\n int flags;\n\n uint32_t size;\n\n int rest = buf_size;\n\n int offset = 0;\n\n\n\n if(c->pic.data[0])\n\n avctx->release_buffer(avctx, &c->pic);\n\n c->pic.reference = 3;\n\n if(avctx->get_buffer(avctx, &c->pic) < 0){\n\n av_log(avctx, AV_LOG_ERROR, \"get_buffer() failed\\n\");\n\n return -1;\n\n }\n\n\n\n c->stream = buf;\n\n flags = bytestream_get_le16(&c->stream);\n\n rest -= 2;\n\n\n\n if(flags & VB_HAS_GMC){\n\n i = (int16_t)bytestream_get_le16(&c->stream);\n\n j = (int16_t)bytestream_get_le16(&c->stream);\n\n offset = i + j * avctx->width;\n\n rest -= 4;\n\n }\n\n if(flags & VB_HAS_VIDEO){\n\n size = bytestream_get_le32(&c->stream);\n\n if(size > rest){\n\n av_log(avctx, AV_LOG_ERROR, \"Frame size is too big\\n\");\n\n return -1;\n\n }\n\n vb_decode_framedata(c, c->stream, size, offset);\n\n c->stream += size - 4;\n\n rest -= size;\n\n }\n\n if(flags & VB_HAS_PALETTE){\n\n size = bytestream_get_le32(&c->stream);\n\n if(size > rest){\n\n av_log(avctx, AV_LOG_ERROR, \"Palette size is too big\\n\");\n\n return -1;\n\n }\n\n vb_decode_palette(c, size);\n\n rest -= size;\n\n }\n\n\n\n memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE);\n\n c->pic.palette_has_changed = flags & VB_HAS_PALETTE;\n\n\n\n outptr = c->pic.data[0];\n\n srcptr = c->frame;\n\n\n\n for(i = 0; i < avctx->height; i++){\n\n memcpy(outptr, srcptr, avctx->width);\n\n srcptr += avctx->width;\n\n outptr += c->pic.linesize[0];\n\n }\n\n\n\n FFSWAP(uint8_t*, c->frame, c->prev_frame);\n\n\n\n *data_size = sizeof(AVFrame);\n\n *(AVFrame*)data = c->pic;\n\n\n\n /* always report that the buffer was completely consumed */\n\n return buf_size;\n\n}\n", + "output": "1", + "index": 5918 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int sd_open(BlockDriverState *bs, QDict *options, int flags,\n\n Error **errp)\n\n{\n\n int ret, fd;\n\n uint32_t vid = 0;\n\n BDRVSheepdogState *s = bs->opaque;\n\n char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];\n\n uint32_t snapid;\n\n char *buf = NULL;\n\n QemuOpts *opts;\n\n Error *local_err = NULL;\n\n const char *filename;\n\n\n\n s->bs = bs;\n\n s->aio_context = bdrv_get_aio_context(bs);\n\n\n\n opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);\n\n qemu_opts_absorb_qdict(opts, options, &local_err);\n\n if (local_err) {\n\n error_propagate(errp, local_err);\n\n ret = -EINVAL;\n\n goto err_no_fd;\n\n }\n\n\n\n filename = qemu_opt_get(opts, \"filename\");\n\n\n\n QLIST_INIT(&s->inflight_aio_head);\n\n QLIST_INIT(&s->failed_aio_head);\n\n QLIST_INIT(&s->inflight_aiocb_head);\n\n s->fd = -1;\n\n\n\n memset(vdi, 0, sizeof(vdi));\n\n memset(tag, 0, sizeof(tag));\n\n\n\n if (strstr(filename, \"://\")) {\n\n ret = sd_parse_uri(s, filename, vdi, &snapid, tag);\n\n } else {\n\n ret = parse_vdiname(s, filename, vdi, &snapid, tag);\n\n }\n\n if (ret < 0) {\n\n error_setg(errp, \"Can't parse filename\");\n\n goto err_no_fd;\n\n }\n\n s->fd = get_sheep_fd(s, errp);\n\n if (s->fd < 0) {\n\n ret = s->fd;\n\n goto err_no_fd;\n\n }\n\n\n\n ret = find_vdi_name(s, vdi, snapid, tag, &vid, true, errp);\n\n if (ret) {\n\n goto err;\n\n }\n\n\n\n /*\n\n * QEMU block layer emulates writethrough cache as 'writeback + flush', so\n\n * we always set SD_FLAG_CMD_CACHE (writeback cache) as default.\n\n */\n\n s->cache_flags = SD_FLAG_CMD_CACHE;\n\n if (flags & BDRV_O_NOCACHE) {\n\n s->cache_flags = SD_FLAG_CMD_DIRECT;\n\n }\n\n s->discard_supported = true;\n\n\n\n if (snapid || tag[0] != '\\0') {\n\n DPRINTF(\"%\" PRIx32 \" snapshot inode was open.\\n\", vid);\n\n s->is_snapshot = true;\n\n }\n\n\n\n fd = connect_to_sdog(s, errp);\n\n if (fd < 0) {\n\n ret = fd;\n\n goto err;\n\n }\n\n\n\n buf = g_malloc(SD_INODE_SIZE);\n\n ret = read_object(fd, s->bs, buf, vid_to_vdi_oid(vid),\n\n 0, SD_INODE_SIZE, 0, s->cache_flags);\n\n\n\n closesocket(fd);\n\n\n\n if (ret) {\n\n error_setg(errp, \"Can't read snapshot inode\");\n\n goto err;\n\n }\n\n\n\n memcpy(&s->inode, buf, sizeof(s->inode));\n\n\n\n bs->total_sectors = s->inode.vdi_size / BDRV_SECTOR_SIZE;\n\n pstrcpy(s->name, sizeof(s->name), vdi);\n\n qemu_co_mutex_init(&s->lock);\n\n qemu_co_queue_init(&s->overlapping_queue);\n\n qemu_opts_del(opts);\n\n g_free(buf);\n\n return 0;\n\n\n\nerr:\n\n aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd,\n\n false, NULL, NULL, NULL, NULL);\n\n closesocket(s->fd);\n\nerr_no_fd:\n\n qemu_opts_del(opts);\n\n g_free(buf);\n\n return ret;\n\n}\n", + "output": "1", + "index": 27145 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)\n\n{\n\n int size;\n\n FFMContext *ffm = s->priv_data;\n\n int duration, ret;\n\n\n\n switch(ffm->read_state) {\n\n case READ_HEADER:\n\n if ((ret = ffm_is_avail_data(s, FRAME_HEADER_SIZE+4)) < 0)\n\n return ret;\n\n\n\n av_dlog(s, \"pos=%08\"PRIx64\" spos=%\"PRIx64\", write_index=%\"PRIx64\" size=%\"PRIx64\"\\n\",\n\n avio_tell(s->pb), s->pb->pos, ffm->write_index, ffm->file_size);\n\n if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=\n\n FRAME_HEADER_SIZE)\n\n return -1;\n\n if (ffm->header[1] & FLAG_DTS)\n\n if (ffm_read_data(s, ffm->header+16, 4, 1) != 4)\n\n return -1;\n\n ffm->read_state = READ_DATA;\n\n /* fall thru */\n\n case READ_DATA:\n\n size = AV_RB24(ffm->header + 2);\n\n if ((ret = ffm_is_avail_data(s, size)) < 0)\n\n return ret;\n\n\n\n duration = AV_RB24(ffm->header + 5);\n\n\n\n av_new_packet(pkt, size);\n\n pkt->stream_index = ffm->header[0];\n\n if ((unsigned)pkt->stream_index >= s->nb_streams) {\n\n av_log(s, AV_LOG_ERROR, \"invalid stream index %d\\n\", pkt->stream_index);\n\n av_free_packet(pkt);\n\n ffm->read_state = READ_HEADER;\n\n return -1;\n\n }\n\n pkt->pos = avio_tell(s->pb);\n\n if (ffm->header[1] & FLAG_KEY_FRAME)\n\n pkt->flags |= AV_PKT_FLAG_KEY;\n\n\n\n ffm->read_state = READ_HEADER;\n\n if (ffm_read_data(s, pkt->data, size, 0) != size) {\n\n /* bad case: desynchronized packet. we cancel all the packet loading */\n\n av_free_packet(pkt);\n\n return -1;\n\n }\n\n pkt->pts = AV_RB64(ffm->header+8);\n\n if (ffm->header[1] & FLAG_DTS)\n\n pkt->dts = pkt->pts - AV_RB32(ffm->header+16);\n\n else\n\n pkt->dts = pkt->pts;\n\n pkt->duration = duration;\n\n break;\n\n }\n\n return 0;\n\n}\n", + "output": "0", + "index": 24518 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int vnc_display_get_address(const char *addrstr,\n\n bool websocket,\n\n bool reverse,\n\n int displaynum,\n\n int to,\n\n bool has_ipv4,\n\n bool has_ipv6,\n\n bool ipv4,\n\n bool ipv6,\n\n SocketAddressLegacy **retaddr,\n\n Error **errp)\n\n{\n\n int ret = -1;\n\n SocketAddressLegacy *addr = NULL;\n\n\n\n addr = g_new0(SocketAddressLegacy, 1);\n\n\n\n if (strncmp(addrstr, \"unix:\", 5) == 0) {\n\n addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;\n\n addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);\n\n addr->u.q_unix.data->path = g_strdup(addrstr + 5);\n\n\n\n if (websocket) {\n\n error_setg(errp, \"UNIX sockets not supported with websock\");\n\n goto cleanup;\n\n }\n\n\n\n if (to) {\n\n error_setg(errp, \"Port range not support with UNIX socket\");\n\n goto cleanup;\n\n }\n\n ret = 0;\n\n } else {\n\n const char *port;\n\n size_t hostlen;\n\n unsigned long long baseport = 0;\n\n InetSocketAddress *inet;\n\n\n\n port = strrchr(addrstr, ':');\n\n if (!port) {\n\n if (websocket) {\n\n hostlen = 0;\n\n port = addrstr;\n\n } else {\n\n error_setg(errp, \"no vnc port specified\");\n\n goto cleanup;\n\n }\n\n } else {\n\n hostlen = port - addrstr;\n\n port++;\n\n if (*port == '\\0') {\n\n error_setg(errp, \"vnc port cannot be empty\");\n\n goto cleanup;\n\n }\n\n }\n\n\n\n addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;\n\n inet = addr->u.inet.data = g_new0(InetSocketAddress, 1);\n\n if (addrstr[0] == '[' && addrstr[hostlen - 1] == ']') {\n\n inet->host = g_strndup(addrstr + 1, hostlen - 2);\n\n } else {\n\n inet->host = g_strndup(addrstr, hostlen);\n\n }\n\n /* plain VNC port is just an offset, for websocket\n\n * port is absolute */\n\n if (websocket) {\n\n if (g_str_equal(addrstr, \"\") ||\n\n g_str_equal(addrstr, \"on\")) {\n\n if (displaynum == -1) {\n\n error_setg(errp, \"explicit websocket port is required\");\n\n goto cleanup;\n\n }\n\n inet->port = g_strdup_printf(\n\n \"%d\", displaynum + 5700);\n\n if (to) {\n\n inet->has_to = true;\n\n inet->to = to + 5700;\n\n }\n\n } else {\n\n inet->port = g_strdup(port);\n\n }\n\n } else {\n\n int offset = reverse ? 0 : 5900;\n\n if (parse_uint_full(port, &baseport, 10) < 0) {\n\n error_setg(errp, \"can't convert to a number: %s\", port);\n\n goto cleanup;\n\n }\n\n if (baseport > 65535 ||\n\n baseport + offset > 65535) {\n\n error_setg(errp, \"port %s out of range\", port);\n\n goto cleanup;\n\n }\n\n inet->port = g_strdup_printf(\n\n \"%d\", (int)baseport + offset);\n\n\n\n if (to) {\n\n inet->has_to = true;\n\n inet->to = to + offset;\n\n }\n\n }\n\n\n\n inet->ipv4 = ipv4;\n\n inet->has_ipv4 = has_ipv4;\n\n inet->ipv6 = ipv6;\n\n inet->has_ipv6 = has_ipv6;\n\n\n\n ret = baseport;\n\n }\n\n\n\n *retaddr = addr;\n\n\n\n cleanup:\n\n if (ret < 0) {\n\n qapi_free_SocketAddressLegacy(addr);\n\n }\n\n return ret;\n\n}\n", + "output": "0", + "index": 27017 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void scale_coefs (\n\n int32_t *dst,\n\n const int32_t *src,\n\n int dynrng,\n\n int len)\n\n{\n\n int i, shift, round;\n\n int16_t mul;\n\n int temp, temp1, temp2, temp3, temp4, temp5, temp6, temp7;\n\n\n\n mul = (dynrng & 0x1f) + 0x20;\n\n shift = 4 - ((dynrng << 23) >> 28);\n\n if (shift > 0 ) {\n\n round = 1 << (shift-1);\n\n for (i=0; i> shift;\n\n temp3 = src[i+3] * mul;\n\n temp2 = temp2 + round;\n\n\n\n dst[i+1] = temp1 >> shift;\n\n temp4 = src[i + 4] * mul;\n\n temp3 = temp3 + round;\n\n dst[i+2] = temp2 >> shift;\n\n\n\n temp5 = src[i+5] * mul;\n\n temp4 = temp4 + round;\n\n dst[i+3] = temp3 >> shift;\n\n temp6 = src[i+6] * mul;\n\n\n\n dst[i+4] = temp4 >> shift;\n\n temp5 = temp5 + round;\n\n temp7 = src[i+7] * mul;\n\n temp6 = temp6 + round;\n\n\n\n dst[i+5] = temp5 >> shift;\n\n temp7 = temp7 + round;\n\n dst[i+6] = temp6 >> shift;\n\n dst[i+7] = temp7 >> shift;\n\n\n\n }\n\n } else {\n\n shift = -shift;\n\n for (i=0; ipriv_data;\n\n int visible_width, visible_height, colorspace;\n\n int offset_x = 0, offset_y = 0;\n\n AVRational fps, aspect;\n\n\n\n s->theora = get_bits_long(gb, 24);\n\n av_log(avctx, AV_LOG_DEBUG, \"Theora bitstream version %X\\n\", s->theora);\n\n\n\n /* 3.2.0 aka alpha3 has the same frame orientation as original vp3 */\n\n /* but previous versions have the image flipped relative to vp3 */\n\n if (s->theora < 0x030200)\n\n {\n\n s->flipped_image = 1;\n\n av_log(avctx, AV_LOG_DEBUG, \"Old (width = get_bits(gb, 16) << 4;\n\n visible_height = s->height = get_bits(gb, 16) << 4;\n\n\n\n if(av_image_check_size(s->width, s->height, 0, avctx)){\n\n av_log(avctx, AV_LOG_ERROR, \"Invalid dimensions (%dx%d)\\n\", s->width, s->height);\n\n s->width= s->height= 0;\n\n return -1;\n\n }\n\n\n\n if (s->theora >= 0x030200) {\n\n visible_width = get_bits_long(gb, 24);\n\n visible_height = get_bits_long(gb, 24);\n\n\n\n offset_x = get_bits(gb, 8); /* offset x */\n\n offset_y = get_bits(gb, 8); /* offset y, from bottom */\n\n }\n\n\n\n fps.num = get_bits_long(gb, 32);\n\n fps.den = get_bits_long(gb, 32);\n\n if (fps.num && fps.den) {\n\n av_reduce(&avctx->time_base.num, &avctx->time_base.den,\n\n fps.den, fps.num, 1<<30);\n\n }\n\n\n\n aspect.num = get_bits_long(gb, 24);\n\n aspect.den = get_bits_long(gb, 24);\n\n if (aspect.num && aspect.den) {\n\n av_reduce(&avctx->sample_aspect_ratio.num,\n\n &avctx->sample_aspect_ratio.den,\n\n aspect.num, aspect.den, 1<<30);\n\n }\n\n\n\n if (s->theora < 0x030200)\n\n skip_bits(gb, 5); /* keyframe frequency force */\n\n colorspace = get_bits(gb, 8);\n\n skip_bits(gb, 24); /* bitrate */\n\n\n\n skip_bits(gb, 6); /* quality hint */\n\n\n\n if (s->theora >= 0x030200)\n\n {\n\n skip_bits(gb, 5); /* keyframe frequency force */\n\n avctx->pix_fmt = theora_pix_fmts[get_bits(gb, 2)];\n\n if (avctx->pix_fmt == AV_PIX_FMT_NONE) {\n\n av_log(avctx, AV_LOG_ERROR, \"Invalid pixel format\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n skip_bits(gb, 3); /* reserved */\n\n }\n\n\n\n// align_get_bits(gb);\n\n\n\n if ( visible_width <= s->width && visible_width > s->width-16\n\n && visible_height <= s->height && visible_height > s->height-16\n\n && !offset_x && (offset_y == s->height - visible_height))\n\n avcodec_set_dimensions(avctx, visible_width, visible_height);\n\n else\n\n avcodec_set_dimensions(avctx, s->width, s->height);\n\n\n\n if (colorspace == 1) {\n\n avctx->color_primaries = AVCOL_PRI_BT470M;\n\n } else if (colorspace == 2) {\n\n avctx->color_primaries = AVCOL_PRI_BT470BG;\n\n }\n\n if (colorspace == 1 || colorspace == 2) {\n\n avctx->colorspace = AVCOL_SPC_BT470BG;\n\n avctx->color_trc = AVCOL_TRC_BT709;\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 3864 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int svq1_decode_init(AVCodecContext *avctx)\n\n{\n\n MpegEncContext *s = avctx->priv_data;\n\n int i;\n\n\n\n MPV_decode_defaults(s);\n\n\n\n s->avctx = avctx;\n\n s->width = (avctx->width+3)&~3;\n\n s->height = (avctx->height+3)&~3;\n\n s->codec_id= avctx->codec->id;\n\n avctx->pix_fmt = PIX_FMT_YUV410P;\n\n avctx->has_b_frames= 1; // not true, but DP frames and these behave like unidirectional b frames\n\n s->flags= avctx->flags;\n\n if (MPV_common_init(s) < 0) return -1;\n\n\n\n init_vlc(&svq1_block_type, 2, 4,\n\n &svq1_block_type_vlc[0][1], 2, 1,\n\n &svq1_block_type_vlc[0][0], 2, 1);\n\n\n\n init_vlc(&svq1_motion_component, 7, 33,\n\n &mvtab[0][1], 2, 1,\n\n &mvtab[0][0], 2, 1);\n\n\n\n for (i = 0; i < 6; i++) {\n\n init_vlc(&svq1_intra_multistage[i], 3, 8,\n\n &svq1_intra_multistage_vlc[i][0][1], 2, 1,\n\n &svq1_intra_multistage_vlc[i][0][0], 2, 1);\n\n init_vlc(&svq1_inter_multistage[i], 3, 8,\n\n &svq1_inter_multistage_vlc[i][0][1], 2, 1,\n\n &svq1_inter_multistage_vlc[i][0][0], 2, 1);\n\n }\n\n\n\n init_vlc(&svq1_intra_mean, 8, 256,\n\n &svq1_intra_mean_vlc[0][1], 4, 2,\n\n &svq1_intra_mean_vlc[0][0], 4, 2);\n\n\n\n init_vlc(&svq1_inter_mean, 9, 512,\n\n &svq1_inter_mean_vlc[0][1], 4, 2,\n\n &svq1_inter_mean_vlc[0][0], 4, 2);\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 17742 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static Qcow2BitmapList *bitmap_list_load(BlockDriverState *bs, uint64_t offset,\n\n uint64_t size, Error **errp)\n\n{\n\n int ret;\n\n BDRVQcow2State *s = bs->opaque;\n\n uint8_t *dir, *dir_end;\n\n Qcow2BitmapDirEntry *e;\n\n uint32_t nb_dir_entries = 0;\n\n Qcow2BitmapList *bm_list = NULL;\n\n\n\n if (size == 0) {\n\n error_setg(errp, \"Requested bitmap directory size is zero\");\n\n return NULL;\n\n }\n\n\n\n if (size > QCOW2_MAX_BITMAP_DIRECTORY_SIZE) {\n\n error_setg(errp, \"Requested bitmap directory size is too big\");\n\n return NULL;\n\n }\n\n\n\n dir = g_try_malloc(size);\n\n if (dir == NULL) {\n\n error_setg(errp, \"Failed to allocate space for bitmap directory\");\n\n return NULL;\n\n }\n\n dir_end = dir + size;\n\n\n\n ret = bdrv_pread(bs->file, offset, dir, size);\n\n if (ret < 0) {\n\n error_setg_errno(errp, -ret, \"Failed to read bitmap directory\");\n\n goto fail;\n\n }\n\n\n\n bm_list = bitmap_list_new();\n\n for (e = (Qcow2BitmapDirEntry *)dir;\n\n e < (Qcow2BitmapDirEntry *)dir_end;\n\n e = next_dir_entry(e))\n\n {\n\n Qcow2Bitmap *bm;\n\n\n\n if ((uint8_t *)(e + 1) > dir_end) {\n\n goto broken_dir;\n\n }\n\n\n\n if (++nb_dir_entries > s->nb_bitmaps) {\n\n error_setg(errp, \"More bitmaps found than specified in header\"\n\n \" extension\");\n\n goto fail;\n\n }\n\n bitmap_dir_entry_to_cpu(e);\n\n\n\n if ((uint8_t *)next_dir_entry(e) > dir_end) {\n\n goto broken_dir;\n\n }\n\n\n\n if (e->extra_data_size != 0) {\n\n error_setg(errp, \"Bitmap extra data is not supported\");\n\n goto fail;\n\n }\n\n\n\n ret = check_dir_entry(bs, e);\n\n if (ret < 0) {\n\n error_setg(errp, \"Bitmap '%.*s' doesn't satisfy the constraints\",\n\n e->name_size, dir_entry_name_field(e));\n\n goto fail;\n\n }\n\n\n\n bm = g_new(Qcow2Bitmap, 1);\n\n bm->table.offset = e->bitmap_table_offset;\n\n bm->table.size = e->bitmap_table_size;\n\n bm->flags = e->flags;\n\n bm->granularity_bits = e->granularity_bits;\n\n bm->name = dir_entry_copy_name(e);\n\n QSIMPLEQ_INSERT_TAIL(bm_list, bm, entry);\n\n }\n\n\n\n if (nb_dir_entries != s->nb_bitmaps) {\n\n error_setg(errp, \"Less bitmaps found than specified in header\"\n\n \" extension\");\n\n goto fail;\n\n }\n\n\n\n if ((uint8_t *)e != dir_end) {\n\n goto broken_dir;\n\n }\n\n\n\n g_free(dir);\n\n return bm_list;\n\n\n\nbroken_dir:\n\n ret = -EINVAL;\n\n error_setg(errp, \"Broken bitmap directory\");\n\n\n\nfail:\n\n g_free(dir);\n\n bitmap_list_free(bm_list);\n\n\n\n return NULL;\n\n}\n", + "output": "1", + "index": 9658 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap)\n\n{\n\n MXFContext *mxf = s->priv_data;\n\n KLVPacket klv;\n\n int64_t essence_offset = 0;\n\n\n\n mxf->last_forward_tell = INT64_MAX;\n\n\n\n if (!mxf_read_sync(s->pb, mxf_header_partition_pack_key, 14)) {\n\n av_log(s, AV_LOG_ERROR, \"could not find header partition pack key\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n avio_seek(s->pb, -14, SEEK_CUR);\n\n mxf->fc = s;\n\n mxf->run_in = avio_tell(s->pb);\n\n\n\n while (!s->pb->eof_reached) {\n\n const MXFMetadataReadTableEntry *metadata;\n\n\n\n if (klv_read_packet(&klv, s->pb) < 0) {\n\n /* EOF - seek to previous partition or stop */\n\n if(mxf_parse_handle_partition_or_eof(mxf) <= 0)\n\n break;\n\n else\n\n continue;\n\n }\n\n\n\n PRINT_KEY(s, \"read header\", klv.key);\n\n av_dlog(s, \"size %\"PRIu64\" offset %#\"PRIx64\"\\n\", klv.length, klv.offset);\n\n if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key) ||\n\n IS_KLV_KEY(klv.key, mxf_essence_element_key) ||\n\n IS_KLV_KEY(klv.key, mxf_avid_essence_element_key) ||\n\n IS_KLV_KEY(klv.key, mxf_system_item_key)) {\n\n if (!mxf->current_partition->essence_offset) {\n\n compute_partition_essence_offset(s, mxf, &klv);\n\n }\n\n\n\n if (!essence_offset)\n\n essence_offset = klv.offset;\n\n\n\n /* seek to footer, previous partition or stop */\n\n if (mxf_parse_handle_essence(mxf) <= 0)\n\n break;\n\n continue;\n\n } else if (!memcmp(klv.key, mxf_header_partition_pack_key, 13) &&\n\n klv.key[13] >= 2 && klv.key[13] <= 4 && mxf->current_partition) {\n\n /* next partition pack - keep going, seek to previous partition or stop */\n\n if(mxf_parse_handle_partition_or_eof(mxf) <= 0)\n\n break;\n\n }\n\n\n\n for (metadata = mxf_metadata_read_table; metadata->read; metadata++) {\n\n if (IS_KLV_KEY(klv.key, metadata->key)) {\n\n int res;\n\n if (klv.key[5] == 0x53) {\n\n res = mxf_read_local_tags(mxf, &klv, metadata->read, metadata->ctx_size, metadata->type);\n\n } else {\n\n uint64_t next = avio_tell(s->pb) + klv.length;\n\n res = metadata->read(mxf, s->pb, 0, klv.length, klv.key, klv.offset);\n\n avio_seek(s->pb, next, SEEK_SET);\n\n }\n\n if (res < 0) {\n\n av_log(s, AV_LOG_ERROR, \"error reading header metadata\\n\");\n\n return res;\n\n }\n\n break;\n\n }\n\n }\n\n if (!metadata->read)\n\n avio_skip(s->pb, klv.length);\n\n }\n\n /* FIXME avoid seek */\n\n if (!essence_offset) {\n\n av_log(s, AV_LOG_ERROR, \"no essence\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n avio_seek(s->pb, essence_offset, SEEK_SET);\n\n\n\n mxf_compute_essence_containers(mxf);\n\n\n\n return mxf_parse_structural_metadata(mxf);\n\n}\n", + "output": "1", + "index": 1878 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int http_receive_data(HTTPContext *c)\n\n{\n\n int len;\n\n HTTPContext *c1;\n\n\n\n if (c->buffer_ptr >= c->buffer_end) {\n\n FFStream *feed = c->stream;\n\n /* a packet has been received : write it in the store, except\n\n if header */\n\n if (c->data_count > FFM_PACKET_SIZE) {\n\n \n\n // printf(\"writing pos=0x%Lx size=0x%Lx\\n\", feed->feed_write_index, feed->feed_size);\n\n /* XXX: use llseek or url_seek */\n\n lseek(c->feed_fd, feed->feed_write_index, SEEK_SET);\n\n write(c->feed_fd, c->buffer, FFM_PACKET_SIZE);\n\n \n\n feed->feed_write_index += FFM_PACKET_SIZE;\n\n /* update file size */\n\n if (feed->feed_write_index > c->stream->feed_size)\n\n feed->feed_size = feed->feed_write_index;\n\n\n\n /* handle wrap around if max file size reached */\n\n if (feed->feed_write_index >= c->stream->feed_max_size)\n\n feed->feed_write_index = FFM_PACKET_SIZE;\n\n\n\n /* write index */\n\n ffm_write_write_index(c->feed_fd, feed->feed_write_index);\n\n\n\n /* wake up any waiting connections */\n\n for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {\n\n if (c1->state == HTTPSTATE_WAIT_FEED && \n\n c1->stream->feed == c->stream->feed) {\n\n c1->state = HTTPSTATE_SEND_DATA;\n\n }\n\n }\n\n } else {\n\n /* We have a header in our hands that contains useful data */\n\n AVFormatContext s;\n\n ByteIOContext *pb = &s.pb;\n\n int i;\n\n\n\n memset(&s, 0, sizeof(s));\n\n\n\n url_open_buf(pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY);\n\n pb->buf_end = c->buffer_end; /* ?? */\n\n pb->is_streamed = 1;\n\n\n\n if (feed->fmt->read_header(&s, 0) < 0) {\n\n goto fail;\n\n }\n\n\n\n /* Now we have the actual streams */\n\n if (s.nb_streams != feed->nb_streams) {\n\n goto fail;\n\n }\n\n for (i = 0; i < s.nb_streams; i++) {\n\n memcpy(&feed->streams[i]->codec, &s.streams[i]->codec, sizeof(AVCodecContext));\n\n } \n\n }\n\n c->buffer_ptr = c->buffer;\n\n }\n\n\n\n len = read(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr);\n\n if (len < 0) {\n\n if (errno != EAGAIN && errno != EINTR) {\n\n /* error : close connection */\n\n goto fail;\n\n }\n\n } else if (len == 0) {\n\n /* end of connection : close it */\n\n goto fail;\n\n } else {\n\n c->buffer_ptr += len;\n\n c->data_count += len;\n\n }\n\n return 0;\n\n fail:\n\n c->stream->feed_opened = 0;\n\n close(c->feed_fd);\n\n return -1;\n\n}\n", + "output": "1", + "index": 376 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){\n\n int i;\n\n int w= s->width;\n\n int h= s->height;\n\n InternalBuffer *buf;\n\n int *picture_number;\n\n\n\n assert(pic->data[0]==NULL);\n\n assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count);\n\n\n\n if(avcodec_check_dimensions(s,w,h))\n\n return -1;\n\n\n\n if(s->internal_buffer==NULL){\n\n s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer));\n\n }\n\n#if 0\n\n s->internal_buffer= av_fast_realloc(\n\n s->internal_buffer,\n\n &s->internal_buffer_size,\n\n sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/\n\n );\n\n#endif\n\n\n\n buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];\n\n picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack\n\n (*picture_number)++;\n\n\n\n if(buf->base[0]){\n\n pic->age= *picture_number - buf->last_pic_num;\n\n buf->last_pic_num= *picture_number;\n\n }else{\n\n int h_chroma_shift, v_chroma_shift;\n\n int pixel_size, size[3];\n\n AVPicture picture;\n\n\n\n avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);\n\n\n\n avcodec_align_dimensions(s, &w, &h);\n\n\n\n if(!(s->flags&CODEC_FLAG_EMU_EDGE)){\n\n w+= EDGE_WIDTH*2;\n\n h+= EDGE_WIDTH*2;\n\n }\n\n avpicture_fill(&picture, NULL, s->pix_fmt, w, h);\n\n pixel_size= picture.linesize[0]*8 / w;\n\n//av_log(NULL, AV_LOG_ERROR, \"%d %d %d %d\\n\", (int)picture.data[1], w, h, s->pix_fmt);\n\n assert(pixel_size>=1);\n\n //FIXME next ensures that linesize= 2^x uvlinesize, thats needed because some MC code assumes it\n\n if(pixel_size == 3*8)\n\n w= ALIGN(w, STRIDE_ALIGN<pix_fmt, w, h);\n\n size[0] = picture.linesize[0] * h;\n\n size[1] -= size[0];\n\n if(picture.data[2])\n\n size[1]= size[2]= size[1]/2;\n\n else\n\n size[2]= 0;\n\n\n\n buf->last_pic_num= -256*256*256*64;\n\n memset(buf->base, 0, sizeof(buf->base));\n\n memset(buf->data, 0, sizeof(buf->data));\n\n\n\n for(i=0; i<3 && size[i]; i++){\n\n const int h_shift= i==0 ? 0 : h_chroma_shift;\n\n const int v_shift= i==0 ? 0 : v_chroma_shift;\n\n\n\n buf->linesize[i]= picture.linesize[i];\n\n\n\n buf->base[i]= av_malloc(size[i]+16); //FIXME 16\n\n if(buf->base[i]==NULL) return -1;\n\n memset(buf->base[i], 128, size[i]);\n\n\n\n // no edge if EDEG EMU or not planar YUV, we check for PAL8 redundantly to protect against a exploitable bug regression ...\n\n if((s->flags&CODEC_FLAG_EMU_EDGE) || (s->pix_fmt == PIX_FMT_PAL8) || !size[2])\n\n buf->data[i] = buf->base[i];\n\n else\n\n buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), STRIDE_ALIGN);\n\n }\n\n pic->age= 256*256*256*64;\n\n }\n\n pic->type= FF_BUFFER_TYPE_INTERNAL;\n\n\n\n for(i=0; i<4; i++){\n\n pic->base[i]= buf->base[i];\n\n pic->data[i]= buf->data[i];\n\n pic->linesize[i]= buf->linesize[i];\n\n }\n\n s->internal_buffer_count++;\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 23669 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)\n\n{\n\n AVIContext *avi = s->priv_data;\n\n AVStream *st;\n\n int i, index;\n\n int64_t pos;\n\n AVIStream *ast;\n\n\n\n if (!avi->index_loaded) {\n\n /* we only load the index on demand */\n\n avi_load_index(s);\n\n avi->index_loaded = 1;\n\n }\n\n assert(stream_index>= 0);\n\n\n\n st = s->streams[stream_index];\n\n ast= st->priv_data;\n\n index= av_index_search_timestamp(st, timestamp * FFMAX(ast->sample_size, 1), flags);\n\n if(index<0)\n\n return -1;\n\n\n\n /* find the position */\n\n pos = st->index_entries[index].pos;\n\n timestamp = st->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);\n\n\n\n av_dlog(s, \"XX %\"PRId64\" %d %\"PRId64\"\\n\",\n\n timestamp, index, st->index_entries[index].timestamp);\n\n\n\n if (CONFIG_DV_DEMUXER && avi->dv_demux) {\n\n /* One and only one real stream for DV in AVI, and it has video */\n\n /* offsets. Calling with other stream indexes should have failed */\n\n /* the av_index_search_timestamp call above. */\n\n assert(stream_index == 0);\n\n\n\n /* Feed the DV video stream version of the timestamp to the */\n\n /* DV demux so it can synthesize correct timestamps. */\n\n ff_dv_offset_reset(avi->dv_demux, timestamp);\n\n\n\n avio_seek(s->pb, pos, SEEK_SET);\n\n avi->stream_index= -1;\n\n return 0;\n\n }\n\n\n\n for(i = 0; i < s->nb_streams; i++) {\n\n AVStream *st2 = s->streams[i];\n\n AVIStream *ast2 = st2->priv_data;\n\n\n\n ast2->packet_size=\n\n ast2->remaining= 0;\n\n\n\n if (ast2->sub_ctx) {\n\n seek_subtitle(st, st2, timestamp);\n\n continue;\n\n }\n\n\n\n if (st2->nb_index_entries <= 0)\n\n continue;\n\n\n\n// assert(st2->codec->block_align);\n\n assert((int64_t)st2->time_base.num*ast2->rate == (int64_t)st2->time_base.den*ast2->scale);\n\n index = av_index_search_timestamp(\n\n st2,\n\n av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),\n\n flags | AVSEEK_FLAG_BACKWARD);\n\n if(index<0)\n\n index=0;\n\n\n\n if(!avi->non_interleaved){\n\n while(index>0 && st2->index_entries[index].pos > pos)\n\n index--;\n\n while(index+1 < st2->nb_index_entries && st2->index_entries[index].pos < pos)\n\n index++;\n\n }\n\n\n\n av_dlog(s, \"%\"PRId64\" %d %\"PRId64\"\\n\",\n\n timestamp, index, st2->index_entries[index].timestamp);\n\n /* extract the current frame number */\n\n ast2->frame_offset = st2->index_entries[index].timestamp;\n\n }\n\n\n\n /* do the seek */\n\n avio_seek(s->pb, pos, SEEK_SET);\n\n avi->stream_index= -1;\n\n return 0;\n\n}\n", + "output": "0", + "index": 25641 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s)\n\n{\n\n AVStream *video_st = s->streams[0];\n\n AVCodecParameters *video_par = s->streams[0]->codecpar;\n\n AVCodecParameters *audio_par = s->streams[1]->codecpar;\n\n int audio_rate = audio_par->sample_rate;\n\n int64_t frame_rate = (video_st->avg_frame_rate.num * 0x10000LL) / video_st->avg_frame_rate.den;\n\n int audio_kbitrate = audio_par->bit_rate / 1000;\n\n int video_kbitrate = FFMIN(video_par->bit_rate / 1000, 800 - audio_kbitrate);\n\n\n\n if (frame_rate < 0 || frame_rate > INT32_MAX) {\n\n av_log(s, AV_LOG_ERROR, \"Frame rate %f outside supported range\\n\", frame_rate / (double)0x10000);\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n avio_wb32(pb, 0x94); /* size */\n\n ffio_wfourcc(pb, \"uuid\");\n\n ffio_wfourcc(pb, \"PROF\");\n\n\n\n avio_wb32(pb, 0x21d24fce); /* 96 bit UUID */\n\n avio_wb32(pb, 0xbb88695c);\n\n avio_wb32(pb, 0xfac9c740);\n\n\n\n avio_wb32(pb, 0x0); /* ? */\n\n avio_wb32(pb, 0x3); /* 3 sections ? */\n\n\n\n avio_wb32(pb, 0x14); /* size */\n\n ffio_wfourcc(pb, \"FPRF\");\n\n avio_wb32(pb, 0x0); /* ? */\n\n avio_wb32(pb, 0x0); /* ? */\n\n avio_wb32(pb, 0x0); /* ? */\n\n\n\n avio_wb32(pb, 0x2c); /* size */\n\n ffio_wfourcc(pb, \"APRF\"); /* audio */\n\n avio_wb32(pb, 0x0);\n\n avio_wb32(pb, 0x2); /* TrackID */\n\n ffio_wfourcc(pb, \"mp4a\");\n\n avio_wb32(pb, 0x20f);\n\n avio_wb32(pb, 0x0);\n\n avio_wb32(pb, audio_kbitrate);\n\n avio_wb32(pb, audio_kbitrate);\n\n avio_wb32(pb, audio_rate);\n\n avio_wb32(pb, audio_par->channels);\n\n\n\n avio_wb32(pb, 0x34); /* size */\n\n ffio_wfourcc(pb, \"VPRF\"); /* video */\n\n avio_wb32(pb, 0x0);\n\n avio_wb32(pb, 0x1); /* TrackID */\n\n if (video_par->codec_id == AV_CODEC_ID_H264) {\n\n ffio_wfourcc(pb, \"avc1\");\n\n avio_wb16(pb, 0x014D);\n\n avio_wb16(pb, 0x0015);\n\n } else {\n\n ffio_wfourcc(pb, \"mp4v\");\n\n avio_wb16(pb, 0x0000);\n\n avio_wb16(pb, 0x0103);\n\n }\n\n avio_wb32(pb, 0x0);\n\n avio_wb32(pb, video_kbitrate);\n\n avio_wb32(pb, video_kbitrate);\n\n avio_wb32(pb, frame_rate);\n\n avio_wb32(pb, frame_rate);\n\n avio_wb16(pb, video_par->width);\n\n avio_wb16(pb, video_par->height);\n\n avio_wb32(pb, 0x010001); /* ? */\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 18958 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s,\n void *last, void *dst, int last2, int w,\n int stride, int comp, int bits)\n{\n int i, x = 0;\n int Ra, Rb, Rc, Rd;\n int D0, D1, D2;\n while (x < w) {\n int err, pred;\n /* compute gradients */\n Ra = x ? R(dst, x - stride) : R(last, x);\n Rb = R(last, x);\n Rc = x ? R(last, x - stride) : last2;\n Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride);\n D0 = Rd - Rb;\n D1 = Rb - Rc;\n D2 = Rc - Ra;\n /* run mode */\n if ((FFABS(D0) <= state->near) &&\n (FFABS(D1) <= state->near) &&\n (FFABS(D2) <= state->near)) {\n int r;\n int RItype;\n /* decode full runs while available */\n while (get_bits1(&s->gb)) {\n int r;\n r = 1 << ff_log2_run[state->run_index[comp]];\n if (x + r * stride > w)\n r = (w - x) / stride;\n for (i = 0; i < r; i++) {\n W(dst, x, Ra);\n x += stride;\n }\n /* if EOL reached, we stop decoding */\n if (r != 1 << ff_log2_run[state->run_index[comp]])\n if (state->run_index[comp] < 31)\n state->run_index[comp]++;\n if (x + stride > w)\n }\n /* decode aborted run */\n r = ff_log2_run[state->run_index[comp]];\n if (r)\n r = get_bits_long(&s->gb, r);\n if (x + r * stride > w) {\n r = (w - x) / stride;\n }\n for (i = 0; i < r; i++) {\n W(dst, x, Ra);\n x += stride;\n }\n if (x >= w) {\n av_log(NULL, AV_LOG_ERROR, \"run overflow\\n\");\n av_assert0(x <= w);\n }\n /* decode run termination value */\n Rb = R(last, x);\n RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0;\n err = ls_get_code_runterm(&s->gb, state, RItype,\n ff_log2_run[state->run_index[comp]]);\n if (state->run_index[comp])\n state->run_index[comp]--;\n if (state->near && RItype) {\n pred = Ra + err;\n } else {\n if (Rb < Ra)\n pred = Rb - err;\n else\n pred = Rb + err;\n }\n } else { /* regular mode */\n int context, sign;\n context = ff_jpegls_quantize(state, D0) * 81 +\n ff_jpegls_quantize(state, D1) * 9 +\n ff_jpegls_quantize(state, D2);\n pred = mid_pred(Ra, Ra + Rb - Rc, Rb);\n if (context < 0) {\n context = -context;\n sign = 1;\n } else {\n sign = 0;\n }\n if (sign) {\n pred = av_clip(pred - state->C[context], 0, state->maxval);\n err = -ls_get_code_regular(&s->gb, state, context);\n } else {\n pred = av_clip(pred + state->C[context], 0, state->maxval);\n err = ls_get_code_regular(&s->gb, state, context);\n }\n /* we have to do something more for near-lossless coding */\n pred += err;\n }\n if (state->near) {\n if (pred < -state->near)\n pred += state->range * state->twonear;\n else if (pred > state->maxval + state->near)\n pred -= state->range * state->twonear;\n pred = av_clip(pred, 0, state->maxval);\n }\n pred &= state->maxval;\n W(dst, x, pred);\n x += stride;\n }\n}", + "output": "1", + "index": 23342 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int nbd_receive_list(QIOChannel *ioc, char **name, Error **errp)\n\n{\n\n uint64_t magic;\n\n uint32_t opt;\n\n uint32_t type;\n\n uint32_t len;\n\n uint32_t namelen;\n\n\n\n *name = NULL;\n\n if (read_sync(ioc, &magic, sizeof(magic)) != sizeof(magic)) {\n\n error_setg(errp, \"failed to read list option magic\");\n\n return -1;\n\n }\n\n magic = be64_to_cpu(magic);\n\n if (magic != NBD_REP_MAGIC) {\n\n error_setg(errp, \"Unexpected option list magic\");\n\n return -1;\n\n }\n\n if (read_sync(ioc, &opt, sizeof(opt)) != sizeof(opt)) {\n\n error_setg(errp, \"failed to read list option\");\n\n return -1;\n\n }\n\n opt = be32_to_cpu(opt);\n\n if (opt != NBD_OPT_LIST) {\n\n error_setg(errp, \"Unexpected option type %x expected %x\",\n\n opt, NBD_OPT_LIST);\n\n return -1;\n\n }\n\n\n\n if (read_sync(ioc, &type, sizeof(type)) != sizeof(type)) {\n\n error_setg(errp, \"failed to read list option type\");\n\n return -1;\n\n }\n\n type = be32_to_cpu(type);\n\n if (type == NBD_REP_ERR_UNSUP) {\n\n return 0;\n\n }\n\n if (nbd_handle_reply_err(opt, type, errp) < 0) {\n\n return -1;\n\n }\n\n\n\n if (read_sync(ioc, &len, sizeof(len)) != sizeof(len)) {\n\n error_setg(errp, \"failed to read option length\");\n\n return -1;\n\n }\n\n len = be32_to_cpu(len);\n\n\n\n if (type == NBD_REP_ACK) {\n\n if (len != 0) {\n\n error_setg(errp, \"length too long for option end\");\n\n return -1;\n\n }\n\n } else if (type == NBD_REP_SERVER) {\n\n if (read_sync(ioc, &namelen, sizeof(namelen)) != sizeof(namelen)) {\n\n error_setg(errp, \"failed to read option name length\");\n\n return -1;\n\n }\n\n namelen = be32_to_cpu(namelen);\n\n if (len != (namelen + sizeof(namelen))) {\n\n error_setg(errp, \"incorrect option mame length\");\n\n return -1;\n\n }\n\n if (namelen > 255) {\n\n error_setg(errp, \"export name length too long %d\", namelen);\n\n return -1;\n\n }\n\n\n\n *name = g_new0(char, namelen + 1);\n\n if (read_sync(ioc, *name, namelen) != namelen) {\n\n error_setg(errp, \"failed to read export name\");\n\n g_free(*name);\n\n *name = NULL;\n\n return -1;\n\n }\n\n (*name)[namelen] = '\\0';\n\n } else {\n\n error_setg(errp, \"Unexpected reply type %x expected %x\",\n\n type, NBD_REP_SERVER);\n\n return -1;\n\n }\n\n return 1;\n\n}\n", + "output": "1", + "index": 10871 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int encode_bitstream(FlashSVContext *s, const AVFrame *p, uint8_t *buf,\n\n int buf_size, int block_width, int block_height,\n\n uint8_t *previous_frame, int *I_frame)\n\n{\n\n\n\n PutBitContext pb;\n\n int h_blocks, v_blocks, h_part, v_part, i, j;\n\n int buf_pos, res;\n\n int pred_blocks = 0;\n\n\n\n init_put_bits(&pb, buf, buf_size * 8);\n\n\n\n put_bits(&pb, 4, block_width / 16 - 1);\n\n put_bits(&pb, 12, s->image_width);\n\n put_bits(&pb, 4, block_height / 16 - 1);\n\n put_bits(&pb, 12, s->image_height);\n\n flush_put_bits(&pb);\n\n buf_pos = 4;\n\n\n\n h_blocks = s->image_width / block_width;\n\n h_part = s->image_width % block_width;\n\n v_blocks = s->image_height / block_height;\n\n v_part = s->image_height % block_height;\n\n\n\n /* loop over all block columns */\n\n for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) {\n\n\n\n int y_pos = j * block_height; // vertical position in frame\n\n int cur_blk_height = (j < v_blocks) ? block_height : v_part;\n\n\n\n /* loop over all block rows */\n\n for (i = 0; i < h_blocks + (h_part ? 1 : 0); i++) {\n\n int x_pos = i * block_width; // horizontal position in frame\n\n int cur_blk_width = (i < h_blocks) ? block_width : h_part;\n\n int ret = Z_OK;\n\n uint8_t *ptr = buf + buf_pos;\n\n\n\n /* copy the block to the temp buffer before compression\n\n * (if it differs from the previous frame's block) */\n\n res = copy_region_enc(p->data[0], s->tmpblock,\n\n s->image_height - (y_pos + cur_blk_height + 1),\n\n x_pos, cur_blk_height, cur_blk_width,\n\n p->linesize[0], previous_frame);\n\n\n\n if (res || *I_frame) {\n\n unsigned long zsize = 3 * block_width * block_height;\n\n ret = compress2(ptr + 2, &zsize, s->tmpblock,\n\n 3 * cur_blk_width * cur_blk_height, 9);\n\n\n\n //ret = deflateReset(&s->zstream);\n\n if (ret != Z_OK)\n\n av_log(s->avctx, AV_LOG_ERROR,\n\n \"error while compressing block %dx%d\\n\", i, j);\n\n\n\n bytestream_put_be16(&ptr, zsize);\n\n buf_pos += zsize + 2;\n\n av_dlog(s->avctx, \"buf_pos = %d\\n\", buf_pos);\n\n } else {\n\n pred_blocks++;\n\n bytestream_put_be16(&ptr, 0);\n\n buf_pos += 2;\n\n }\n\n }\n\n }\n\n\n\n if (pred_blocks)\n\n *I_frame = 0;\n\n else\n\n *I_frame = 1;\n\n\n\n return buf_pos;\n\n}\n", + "output": "1", + "index": 26338 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int usbredir_handle_interrupt_data(USBRedirDevice *dev,\n\n USBPacket *p, uint8_t ep)\n\n{\n\n if (ep & USB_DIR_IN) {\n\n /* Input interrupt endpoint, buffered packet input */\n\n struct buf_packet *intp;\n\n int status, len;\n\n\n\n if (!dev->endpoint[EP2I(ep)].interrupt_started &&\n\n !dev->endpoint[EP2I(ep)].interrupt_error) {\n\n struct usb_redir_start_interrupt_receiving_header start_int = {\n\n .endpoint = ep,\n\n };\n\n /* No id, we look at the ep when receiving a status back */\n\n usbredirparser_send_start_interrupt_receiving(dev->parser, 0,\n\n &start_int);\n\n usbredirparser_do_write(dev->parser);\n\n DPRINTF(\"interrupt recv started ep %02X\\n\", ep);\n\n dev->endpoint[EP2I(ep)].interrupt_started = 1;\n\n /* We don't really want to drop interrupt packets ever, but\n\n having some upper limit to how much we buffer is good. */\n\n dev->endpoint[EP2I(ep)].bufpq_target_size = 1000;\n\n dev->endpoint[EP2I(ep)].bufpq_dropping_packets = 0;\n\n }\n\n\n\n intp = QTAILQ_FIRST(&dev->endpoint[EP2I(ep)].bufpq);\n\n if (intp == NULL) {\n\n DPRINTF2(\"interrupt-token-in ep %02X, no intp\\n\", ep);\n\n /* Check interrupt_error for stream errors */\n\n status = dev->endpoint[EP2I(ep)].interrupt_error;\n\n dev->endpoint[EP2I(ep)].interrupt_error = 0;\n\n if (status) {\n\n return usbredir_handle_status(dev, status, 0);\n\n }\n\n return USB_RET_NAK;\n\n }\n\n DPRINTF(\"interrupt-token-in ep %02X status %d len %d\\n\", ep,\n\n intp->status, intp->len);\n\n\n\n status = intp->status;\n\n if (status != usb_redir_success) {\n\n bufp_free(dev, intp, ep);\n\n return usbredir_handle_status(dev, status, 0);\n\n }\n\n\n\n len = intp->len;\n\n if (len > p->iov.size) {\n\n ERROR(\"received int data is larger then packet ep %02X\\n\", ep);\n\n bufp_free(dev, intp, ep);\n\n return USB_RET_BABBLE;\n\n }\n\n usb_packet_copy(p, intp->data, len);\n\n bufp_free(dev, intp, ep);\n\n return len;\n\n } else {\n\n /* Output interrupt endpoint, normal async operation */\n\n AsyncURB *aurb = async_alloc(dev, p);\n\n struct usb_redir_interrupt_packet_header interrupt_packet;\n\n uint8_t buf[p->iov.size];\n\n\n\n DPRINTF(\"interrupt-out ep %02X len %zd id %u\\n\", ep, p->iov.size,\n\n aurb->packet_id);\n\n\n\n interrupt_packet.endpoint = ep;\n\n interrupt_packet.length = p->iov.size;\n\n aurb->interrupt_packet = interrupt_packet;\n\n\n\n usb_packet_copy(p, buf, p->iov.size);\n\n usbredir_log_data(dev, \"interrupt data out:\", buf, p->iov.size);\n\n usbredirparser_send_interrupt_packet(dev->parser, aurb->packet_id,\n\n &interrupt_packet, buf, p->iov.size);\n\n usbredirparser_do_write(dev->parser);\n\n return USB_RET_ASYNC;\n\n }\n\n}\n", + "output": "0", + "index": 7830 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,\n\n uint16_t *refcount_table, int64_t refcount_table_size, int64_t l2_offset,\n\n int flags)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n uint64_t *l2_table, l2_entry;\n\n uint64_t next_contiguous_offset = 0;\n\n int i, l2_size, nb_csectors;\n\n\n\n /* Read L2 table from disk */\n\n l2_size = s->l2_size * sizeof(uint64_t);\n\n l2_table = g_malloc(l2_size);\n\n\n\n if (bdrv_pread(bs->file, l2_offset, l2_table, l2_size) != l2_size)\n\n goto fail;\n\n\n\n /* Do the actual checks */\n\n for(i = 0; i < s->l2_size; i++) {\n\n l2_entry = be64_to_cpu(l2_table[i]);\n\n\n\n switch (qcow2_get_cluster_type(l2_entry)) {\n\n case QCOW2_CLUSTER_COMPRESSED:\n\n /* Compressed clusters don't have QCOW_OFLAG_COPIED */\n\n if (l2_entry & QCOW_OFLAG_COPIED) {\n\n fprintf(stderr, \"ERROR: cluster %\" PRId64 \": \"\n\n \"copied flag must never be set for compressed \"\n\n \"clusters\\n\", l2_entry >> s->cluster_bits);\n\n l2_entry &= ~QCOW_OFLAG_COPIED;\n\n res->corruptions++;\n\n }\n\n\n\n /* Mark cluster as used */\n\n nb_csectors = ((l2_entry >> s->csize_shift) &\n\n s->csize_mask) + 1;\n\n l2_entry &= s->cluster_offset_mask;\n\n inc_refcounts(bs, res, refcount_table, refcount_table_size,\n\n l2_entry & ~511, nb_csectors * 512);\n\n\n\n if (flags & CHECK_FRAG_INFO) {\n\n res->bfi.allocated_clusters++;\n\n res->bfi.compressed_clusters++;\n\n\n\n /* Compressed clusters are fragmented by nature. Since they\n\n * take up sub-sector space but we only have sector granularity\n\n * I/O we need to re-read the same sectors even for adjacent\n\n * compressed clusters.\n\n */\n\n res->bfi.fragmented_clusters++;\n\n }\n\n break;\n\n\n\n case QCOW2_CLUSTER_ZERO:\n\n if ((l2_entry & L2E_OFFSET_MASK) == 0) {\n\n break;\n\n }\n\n /* fall through */\n\n\n\n case QCOW2_CLUSTER_NORMAL:\n\n {\n\n uint64_t offset = l2_entry & L2E_OFFSET_MASK;\n\n\n\n if (flags & CHECK_FRAG_INFO) {\n\n res->bfi.allocated_clusters++;\n\n if (next_contiguous_offset &&\n\n offset != next_contiguous_offset) {\n\n res->bfi.fragmented_clusters++;\n\n }\n\n next_contiguous_offset = offset + s->cluster_size;\n\n }\n\n\n\n /* Mark cluster as used */\n\n inc_refcounts(bs, res, refcount_table,refcount_table_size,\n\n offset, s->cluster_size);\n\n\n\n /* Correct offsets are cluster aligned */\n\n if (offset_into_cluster(s, offset)) {\n\n fprintf(stderr, \"ERROR offset=%\" PRIx64 \": Cluster is not \"\n\n \"properly aligned; L2 entry corrupted.\\n\", offset);\n\n res->corruptions++;\n\n }\n\n break;\n\n }\n\n\n\n case QCOW2_CLUSTER_UNALLOCATED:\n\n break;\n\n\n\n default:\n\n abort();\n\n }\n\n }\n\n\n\n g_free(l2_table);\n\n return 0;\n\n\n\nfail:\n\n fprintf(stderr, \"ERROR: I/O error in check_refcounts_l2\\n\");\n\n g_free(l2_table);\n\n return -EIO;\n\n}\n", + "output": "1", + "index": 19427 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void dwt_encode97_int(DWTContext *s, int *t)\n\n{\n\n int lev,\n\n w = s->linelen[s->ndeclevels-1][0];\n\n int *line = s->i_linebuf;\n\n line += 5;\n\n\n\n for (lev = s->ndeclevels-1; lev >= 0; lev--){\n\n int lh = s->linelen[lev][0],\n\n lv = s->linelen[lev][1],\n\n mh = s->mod[lev][0],\n\n mv = s->mod[lev][1],\n\n lp;\n\n int *l;\n\n\n\n // VER_SD\n\n l = line + mv;\n\n for (lp = 0; lp < lh; lp++) {\n\n int i, j = 0;\n\n\n\n for (i = 0; i < lv; i++)\n\n l[i] = t[w*i + lp];\n\n\n\n sd_1d97_int(line, mv, mv + lv);\n\n\n\n // copy back and deinterleave\n\n for (i = mv; i < lv; i+=2, j++)\n\n t[w*j + lp] = ((l[i] * I_LFTG_X) + (1 << 16)) >> 17;\n\n for (i = 1-mv; i < lv; i+=2, j++)\n\n t[w*j + lp] = ((l[i] * I_LFTG_K) + (1 << 16)) >> 17;\n\n }\n\n\n\n // HOR_SD\n\n l = line + mh;\n\n for (lp = 0; lp < lv; lp++){\n\n int i, j = 0;\n\n\n\n for (i = 0; i < lh; i++)\n\n l[i] = t[w*lp + i];\n\n\n\n sd_1d97_int(line, mh, mh + lh);\n\n\n\n // copy back and deinterleave\n\n for (i = mh; i < lh; i+=2, j++)\n\n t[w*lp + j] = ((l[i] * I_LFTG_X) + (1 << 16)) >> 17;\n\n for (i = 1-mh; i < lh; i+=2, j++)\n\n t[w*lp + j] = ((l[i] * I_LFTG_K) + (1 << 16)) >> 17;\n\n }\n\n\n\n }\n\n}\n", + "output": "1", + "index": 22034 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void sh7750_mem_writel(void *opaque, target_phys_addr_t addr,\n\n\t\t\t uint32_t mem_value)\n\n{\n\n SH7750State *s = opaque;\n\n uint16_t temp;\n\n\n\n switch (addr) {\n\n\t/* SDRAM controller */\n\n case SH7750_BCR1_A7:\n\n case SH7750_BCR4_A7:\n\n case SH7750_WCR1_A7:\n\n case SH7750_WCR2_A7:\n\n case SH7750_WCR3_A7:\n\n case SH7750_MCR_A7:\n\n\tignore_access(\"long write\", addr);\n\n\treturn;\n\n\t/* IO ports */\n\n case SH7750_PCTRA_A7:\n\n\ttemp = porta_lines(s);\n\n\ts->pctra = mem_value;\n\n\ts->portdira = portdir(mem_value);\n\n\ts->portpullupa = portpullup(mem_value);\n\n\tporta_changed(s, temp);\n\n\treturn;\n\n case SH7750_PCTRB_A7:\n\n\ttemp = portb_lines(s);\n\n\ts->pctrb = mem_value;\n\n\ts->portdirb = portdir(mem_value);\n\n\ts->portpullupb = portpullup(mem_value);\n\n\tportb_changed(s, temp);\n\n\treturn;\n\n case SH7750_MMUCR_A7:\n\n\ts->cpu->mmucr = mem_value;\n\n\treturn;\n\n case SH7750_PTEH_A7:\n\n\n\n\n\ts->cpu->pteh = mem_value;\n\n\treturn;\n\n case SH7750_PTEL_A7:\n\n\ts->cpu->ptel = mem_value;\n\n\treturn;\n\n case SH7750_PTEA_A7:\n\n\ts->cpu->ptea = mem_value & 0x0000000f;\n\n\treturn;\n\n case SH7750_TTB_A7:\n\n\ts->cpu->ttb = mem_value;\n\n\treturn;\n\n case SH7750_TEA_A7:\n\n\ts->cpu->tea = mem_value;\n\n\treturn;\n\n case SH7750_TRA_A7:\n\n\ts->cpu->tra = mem_value & 0x000007ff;\n\n\treturn;\n\n case SH7750_EXPEVT_A7:\n\n\ts->cpu->expevt = mem_value & 0x000007ff;\n\n\treturn;\n\n case SH7750_INTEVT_A7:\n\n\ts->cpu->intevt = mem_value & 0x000007ff;\n\n\treturn;\n\n case SH7750_CCR_A7:\n\n\ts->ccr = mem_value;\n\n\treturn;\n\n default:\n\n\terror_access(\"long write\", addr);\n\n\tassert(0);\n\n }\n\n}", + "output": "1", + "index": 2252 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,\n\n unsigned int *out_bytes,\n\n unsigned max_in_bytes, unsigned max_out_bytes)\n\n{\n\n VirtIODevice *vdev = vq->vdev;\n\n unsigned int max, idx;\n\n unsigned int total_bufs, in_total, out_total;\n\n VRingMemoryRegionCaches *caches;\n\n MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;\n\n int64_t len = 0;\n\n int rc;\n\n\n\n if (unlikely(!vq->vring.desc)) {\n\n if (in_bytes) {\n\n *in_bytes = 0;\n\n }\n\n if (out_bytes) {\n\n *out_bytes = 0;\n\n }\n\n return;\n\n }\n\n\n\n rcu_read_lock();\n\n idx = vq->last_avail_idx;\n\n total_bufs = in_total = out_total = 0;\n\n\n\n max = vq->vring.num;\n\n caches = atomic_rcu_read(&vq->vring.caches);\n\n if (caches->desc.len < max * sizeof(VRingDesc)) {\n\n virtio_error(vdev, \"Cannot map descriptor ring\");\n\n goto err;\n\n }\n\n\n\n while ((rc = virtqueue_num_heads(vq, idx)) > 0) {\n\n MemoryRegionCache *desc_cache = &caches->desc;\n\n unsigned int num_bufs;\n\n VRingDesc desc;\n\n unsigned int i;\n\n\n\n num_bufs = total_bufs;\n\n\n\n if (!virtqueue_get_head(vq, idx++, &i)) {\n\n goto err;\n\n }\n\n\n\n vring_desc_read(vdev, &desc, desc_cache, i);\n\n\n\n if (desc.flags & VRING_DESC_F_INDIRECT) {\n\n if (desc.len % sizeof(VRingDesc)) {\n\n virtio_error(vdev, \"Invalid size for indirect buffer table\");\n\n goto err;\n\n }\n\n\n\n /* If we've got too many, that implies a descriptor loop. */\n\n if (num_bufs >= max) {\n\n virtio_error(vdev, \"Looped descriptor\");\n\n goto err;\n\n }\n\n\n\n /* loop over the indirect descriptor table */\n\n len = address_space_cache_init(&indirect_desc_cache,\n\n vdev->dma_as,\n\n desc.addr, desc.len, false);\n\n desc_cache = &indirect_desc_cache;\n\n if (len < desc.len) {\n\n virtio_error(vdev, \"Cannot map indirect buffer\");\n\n goto err;\n\n }\n\n\n\n max = desc.len / sizeof(VRingDesc);\n\n num_bufs = i = 0;\n\n vring_desc_read(vdev, &desc, desc_cache, i);\n\n }\n\n\n\n do {\n\n /* If we've got too many, that implies a descriptor loop. */\n\n if (++num_bufs > max) {\n\n virtio_error(vdev, \"Looped descriptor\");\n\n goto err;\n\n }\n\n\n\n if (desc.flags & VRING_DESC_F_WRITE) {\n\n in_total += desc.len;\n\n } else {\n\n out_total += desc.len;\n\n }\n\n if (in_total >= max_in_bytes && out_total >= max_out_bytes) {\n\n goto done;\n\n }\n\n\n\n rc = virtqueue_read_next_desc(vdev, &desc, desc_cache, max, &i);\n\n } while (rc == VIRTQUEUE_READ_DESC_MORE);\n\n\n\n if (rc == VIRTQUEUE_READ_DESC_ERROR) {\n\n goto err;\n\n }\n\n\n\n if (desc_cache == &indirect_desc_cache) {\n\n address_space_cache_destroy(&indirect_desc_cache);\n\n total_bufs++;\n\n } else {\n\n total_bufs = num_bufs;\n\n }\n\n }\n\n\n\n if (rc < 0) {\n\n goto err;\n\n }\n\n\n\ndone:\n\n address_space_cache_destroy(&indirect_desc_cache);\n\n if (in_bytes) {\n\n *in_bytes = in_total;\n\n }\n\n if (out_bytes) {\n\n *out_bytes = out_total;\n\n }\n\n rcu_read_unlock();\n\n return;\n\n\n\nerr:\n\n in_total = out_total = 0;\n\n goto done;\n\n}\n", + "output": "1", + "index": 17738 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void raise_mmu_exception(CPUMIPSState *env, target_ulong address,\n\n int rw, int tlb_error)\n\n{\n\n CPUState *cs = CPU(mips_env_get_cpu(env));\n\n int exception = 0, error_code = 0;\n\n\n\n if (rw == MMU_INST_FETCH) {\n\n error_code |= EXCP_INST_NOTAVAIL;\n\n }\n\n\n\n switch (tlb_error) {\n\n default:\n\n case TLBRET_BADADDR:\n\n /* Reference to kernel address from user mode or supervisor mode */\n\n /* Reference to supervisor address from user mode */\n\n if (rw == MMU_DATA_STORE) {\n\n exception = EXCP_AdES;\n\n } else {\n\n exception = EXCP_AdEL;\n\n }\n\n break;\n\n case TLBRET_NOMATCH:\n\n /* No TLB match for a mapped address */\n\n if (rw == MMU_DATA_STORE) {\n\n exception = EXCP_TLBS;\n\n } else {\n\n exception = EXCP_TLBL;\n\n }\n\n error_code |= EXCP_TLB_NOMATCH;\n\n break;\n\n case TLBRET_INVALID:\n\n /* TLB match with no valid bit */\n\n if (rw == MMU_DATA_STORE) {\n\n exception = EXCP_TLBS;\n\n } else {\n\n exception = EXCP_TLBL;\n\n }\n\n break;\n\n case TLBRET_DIRTY:\n\n /* TLB match but 'D' bit is cleared */\n\n exception = EXCP_LTLBL;\n\n break;\n\n case TLBRET_XI:\n\n /* Execute-Inhibit Exception */\n\n if (env->CP0_PageGrain & (1 << CP0PG_IEC)) {\n\n exception = EXCP_TLBXI;\n\n } else {\n\n exception = EXCP_TLBL;\n\n }\n\n break;\n\n case TLBRET_RI:\n\n /* Read-Inhibit Exception */\n\n if (env->CP0_PageGrain & (1 << CP0PG_IEC)) {\n\n exception = EXCP_TLBRI;\n\n } else {\n\n exception = EXCP_TLBL;\n\n }\n\n break;\n\n }\n\n /* Raise exception */\n\n env->CP0_BadVAddr = address;\n\n env->CP0_Context = (env->CP0_Context & ~0x007fffff) |\n\n ((address >> 9) & 0x007ffff0);\n\n env->CP0_EntryHi = (env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask) |\n\n\n (address & (TARGET_PAGE_MASK << 1));\n\n#if defined(TARGET_MIPS64)\n\n env->CP0_EntryHi &= env->SEGMask;\n\n env->CP0_XContext =\n\n /* PTEBase */ (env->CP0_XContext & ((~0ULL) << (env->SEGBITS - 7))) |\n\n /* R */ (extract64(address, 62, 2) << (env->SEGBITS - 9)) |\n\n /* BadVPN2 */ (extract64(address, 13, env->SEGBITS - 13) << 4);\n\n#endif\n\n cs->exception_index = exception;\n\n env->error_code = error_code;\n\n}", + "output": "1", + "index": 2355 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)\n\n{\n\n unsigned int i, head, max;\n\n hwaddr desc_pa = vq->vring.desc;\n\n VirtIODevice *vdev = vq->vdev;\n\n\n\n if (!virtqueue_num_heads(vq, vq->last_avail_idx))\n\n return 0;\n\n\n\n /* When we start there are none of either input nor output. */\n\n elem->out_num = elem->in_num = 0;\n\n\n\n max = vq->vring.num;\n\n\n\n i = head = virtqueue_get_head(vq, vq->last_avail_idx++);\n\n if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {\n\n vring_set_avail_event(vq, vq->last_avail_idx);\n\n }\n\n\n\n if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_INDIRECT) {\n\n if (vring_desc_len(vdev, desc_pa, i) % sizeof(VRingDesc)) {\n\n error_report(\"Invalid size for indirect buffer table\");\n\n exit(1);\n\n }\n\n\n\n /* loop over the indirect descriptor table */\n\n max = vring_desc_len(vdev, desc_pa, i) / sizeof(VRingDesc);\n\n desc_pa = vring_desc_addr(vdev, desc_pa, i);\n\n i = 0;\n\n }\n\n\n\n /* Collect all the descriptors */\n\n do {\n\n struct iovec *sg;\n\n\n\n if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_WRITE) {\n\n if (elem->in_num >= ARRAY_SIZE(elem->in_sg)) {\n\n error_report(\"Too many write descriptors in indirect table\");\n\n exit(1);\n\n }\n\n elem->in_addr[elem->in_num] = vring_desc_addr(vdev, desc_pa, i);\n\n sg = &elem->in_sg[elem->in_num++];\n\n } else {\n\n if (elem->out_num >= ARRAY_SIZE(elem->out_sg)) {\n\n error_report(\"Too many read descriptors in indirect table\");\n\n exit(1);\n\n }\n\n elem->out_addr[elem->out_num] = vring_desc_addr(vdev, desc_pa, i);\n\n sg = &elem->out_sg[elem->out_num++];\n\n }\n\n\n\n sg->iov_len = vring_desc_len(vdev, desc_pa, i);\n\n\n\n /* If we've got too many, that implies a descriptor loop. */\n\n if ((elem->in_num + elem->out_num) > max) {\n\n error_report(\"Looped descriptor\");\n\n exit(1);\n\n }\n\n } while ((i = virtqueue_next_desc(vdev, desc_pa, i, max)) != max);\n\n\n\n /* Now map what we have collected */\n\n virtqueue_map(elem);\n\n\n\n elem->index = head;\n\n\n\n vq->inuse++;\n\n\n\n trace_virtqueue_pop(vq, elem, elem->in_num, elem->out_num);\n\n return elem->in_num + elem->out_num;\n\n}\n", + "output": "0", + "index": 13496 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void encode_cblk(Jpeg2000EncoderContext *s, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, Jpeg2000Tile *tile,\n\n int width, int height, int bandpos, int lev)\n\n{\n\n int pass_t = 2, passno, x, y, max=0, nmsedec, bpno;\n\n int64_t wmsedec = 0;\n\n\n\n for (y = 0; y < height+2; y++)\n\n memset(t1->flags[y], 0, (width+2)*sizeof(int));\n\n\n\n for (y = 0; y < height; y++){\n\n for (x = 0; x < width; x++){\n\n if (t1->data[y][x] < 0){\n\n t1->flags[y+1][x+1] |= JPEG2000_T1_SGN;\n\n t1->data[y][x] = -t1->data[y][x];\n\n }\n\n max = FFMAX(max, t1->data[y][x]);\n\n }\n\n }\n\n\n\n if (max == 0){\n\n cblk->nonzerobits = 0;\n\n bpno = 0;\n\n } else{\n\n cblk->nonzerobits = av_log2(max) + 1 - NMSEDEC_FRACBITS;\n\n bpno = cblk->nonzerobits - 1;\n\n }\n\n\n\n ff_mqc_initenc(&t1->mqc, cblk->data);\n\n\n\n for (passno = 0; bpno >= 0; passno++){\n\n nmsedec=0;\n\n\n\n switch(pass_t){\n\n case 0: encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno);\n\n break;\n\n case 1: encode_refpass(t1, width, height, &nmsedec, bpno);\n\n break;\n\n case 2: encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno);\n\n break;\n\n }\n\n\n\n cblk->passes[passno].rate = ff_mqc_flush_to(&t1->mqc, cblk->passes[passno].flushed, &cblk->passes[passno].flushed_len);\n\n wmsedec += (int64_t)nmsedec << (2*bpno);\n\n cblk->passes[passno].disto = wmsedec;\n\n\n\n if (++pass_t == 3){\n\n pass_t = 0;\n\n bpno--;\n\n }\n\n }\n\n cblk->npasses = passno;\n\n cblk->ninclpasses = passno;\n\n\n\n cblk->passes[passno-1].rate = ff_mqc_flush_to(&t1->mqc, cblk->passes[passno-1].flushed, &cblk->passes[passno-1].flushed_len);\n\n}\n", + "output": "0", + "index": 10405 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void *aio_thread(void *unused)\n\n{\n\n sigset_t set;\n\n\n\n /* block all signals */\n\n sigfillset(&set);\n\n sigprocmask(SIG_BLOCK, &set, NULL);\n\n\n\n while (1) {\n\n struct qemu_paiocb *aiocb;\n\n size_t offset;\n\n int ret = 0;\n\n\n\n pthread_mutex_lock(&lock);\n\n\n\n while (TAILQ_EMPTY(&request_list) &&\n\n !(ret == ETIMEDOUT)) {\n\n struct timespec ts = { 0 };\n\n qemu_timeval tv;\n\n\n\n qemu_gettimeofday(&tv);\n\n ts.tv_sec = tv.tv_sec + 10;\n\n ret = pthread_cond_timedwait(&cond, &lock, &ts);\n\n }\n\n\n\n if (ret == ETIMEDOUT)\n\n break;\n\n\n\n aiocb = TAILQ_FIRST(&request_list);\n\n TAILQ_REMOVE(&request_list, aiocb, node);\n\n\n\n offset = 0;\n\n aiocb->active = 1;\n\n\n\n idle_threads--;\n\n pthread_mutex_unlock(&lock);\n\n\n\n while (offset < aiocb->aio_nbytes) {\n\n ssize_t len;\n\n\n\n if (aiocb->is_write)\n\n len = pwrite(aiocb->aio_fildes,\n\n (const char *)aiocb->aio_buf + offset,\n\n aiocb->aio_nbytes - offset,\n\n aiocb->aio_offset + offset);\n\n else\n\n len = pread(aiocb->aio_fildes,\n\n (char *)aiocb->aio_buf + offset,\n\n aiocb->aio_nbytes - offset,\n\n aiocb->aio_offset + offset);\n\n\n\n if (len == -1 && errno == EINTR)\n\n continue;\n\n else if (len == -1) {\n\n pthread_mutex_lock(&lock);\n\n aiocb->ret = -errno;\n\n pthread_mutex_unlock(&lock);\n\n break;\n\n } else if (len == 0)\n\n break;\n\n\n\n offset += len;\n\n\n\n pthread_mutex_lock(&lock);\n\n aiocb->ret = offset;\n\n pthread_mutex_unlock(&lock);\n\n }\n\n\n\n pthread_mutex_lock(&lock);\n\n idle_threads++;\n\n pthread_mutex_unlock(&lock);\n\n\n\n sigqueue(getpid(),\n\n aiocb->aio_sigevent.sigev_signo,\n\n aiocb->aio_sigevent.sigev_value);\n\n }\n\n\n\n idle_threads--;\n\n cur_threads--;\n\n pthread_mutex_unlock(&lock);\n\n\n\n return NULL;\n\n}\n", + "output": "1", + "index": 5939 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)\n\n{\n\n CDXLDemuxContext *cdxl = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n uint32_t current_size, video_size, image_size;\n\n uint16_t audio_size, palette_size, width, height;\n\n int64_t pos;\n\n int ret;\n\n\n\n if (pb->eof_reached)\n\n return AVERROR_EOF;\n\n\n\n pos = avio_tell(pb);\n\n if (!cdxl->read_chunk &&\n\n avio_read(pb, cdxl->header, CDXL_HEADER_SIZE) != CDXL_HEADER_SIZE)\n\n return AVERROR_EOF;\n\n if (cdxl->header[0] != 1) {\n\n av_log(s, AV_LOG_ERROR, \"non-standard cdxl file\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n current_size = AV_RB32(&cdxl->header[2]);\n\n width = AV_RB16(&cdxl->header[14]);\n\n height = AV_RB16(&cdxl->header[16]);\n\n palette_size = AV_RB16(&cdxl->header[20]);\n\n audio_size = AV_RB16(&cdxl->header[22]);\n\n image_size = FFALIGN(width, 16) * height * cdxl->header[19] / 8;\n\n video_size = palette_size + image_size;\n\n\n\n if (palette_size > 512)\n\n return AVERROR_INVALIDDATA;\n\n if (current_size < (uint64_t)audio_size + video_size + CDXL_HEADER_SIZE)\n\n return AVERROR_INVALIDDATA;\n\n\n\n if (cdxl->read_chunk && audio_size) {\n\n if (cdxl->audio_stream_index == -1) {\n\n AVStream *st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n\n\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n st->codec->codec_tag = 0;\n\n st->codec->codec_id = CODEC_ID_PCM_S8;\n\n st->codec->channels = cdxl->header[1] & 0x10 ? 2 : 1;\n\n st->codec->sample_rate = cdxl->sample_rate;\n\n st->start_time = 0;\n\n cdxl->audio_stream_index = st->index;\n\n avpriv_set_pts_info(st, 64, 1, cdxl->sample_rate);\n\n }\n\n\n\n ret = av_get_packet(pb, pkt, audio_size);\n\n if (ret < 0)\n\n return ret;\n\n pkt->stream_index = cdxl->audio_stream_index;\n\n pkt->pos = pos;\n\n pkt->duration = audio_size;\n\n cdxl->read_chunk = 0;\n\n } else {\n\n if (cdxl->video_stream_index == -1) {\n\n AVStream *st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n\n\n st->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n\n st->codec->codec_tag = 0;\n\n st->codec->codec_id = CODEC_ID_CDXL;\n\n st->codec->width = width;\n\n st->codec->height = height;\n\n st->start_time = 0;\n\n cdxl->video_stream_index = st->index;\n\n if (cdxl->framerate)\n\n avpriv_set_pts_info(st, 64, cdxl->fps.den, cdxl->fps.num);\n\n else\n\n avpriv_set_pts_info(st, 64, 1, cdxl->sample_rate);\n\n }\n\n\n\n if (av_new_packet(pkt, video_size + CDXL_HEADER_SIZE) < 0)\n\n return AVERROR(ENOMEM);\n\n memcpy(pkt->data, cdxl->header, CDXL_HEADER_SIZE);\n\n ret = avio_read(pb, pkt->data + CDXL_HEADER_SIZE, video_size);\n\n if (ret < 0) {\n\n av_free_packet(pkt);\n\n return ret;\n\n }\n\n\n pkt->stream_index = cdxl->video_stream_index;\n\n pkt->flags |= AV_PKT_FLAG_KEY;\n\n pkt->pos = pos;\n\n pkt->duration = cdxl->framerate ? 1 : audio_size ? audio_size : 220;\n\n cdxl->read_chunk = audio_size;\n\n }\n\n\n\n if (!cdxl->read_chunk)\n\n avio_skip(pb, current_size - audio_size - video_size - CDXL_HEADER_SIZE);\n\n return ret;\n\n}", + "output": "1", + "index": 3865 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold int vaapi_encode_h265_init_constant_bitrate(AVCodecContext *avctx)\n\n{\n\n VAAPIEncodeContext *ctx = avctx->priv_data;\n\n VAAPIEncodeH265Context *priv = ctx->priv_data;\n\n int hrd_buffer_size;\n\n int hrd_initial_buffer_fullness;\n\n\n\n if (avctx->bit_rate > INT32_MAX) {\n\n av_log(avctx, AV_LOG_ERROR, \"Target bitrate of 2^31 bps or \"\n\n \"higher is not supported.\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n if (avctx->rc_buffer_size)\n\n hrd_buffer_size = avctx->rc_buffer_size;\n\n else\n\n hrd_buffer_size = avctx->bit_rate;\n\n if (avctx->rc_initial_buffer_occupancy)\n\n hrd_initial_buffer_fullness = avctx->rc_initial_buffer_occupancy;\n\n else\n\n hrd_initial_buffer_fullness = hrd_buffer_size * 3 / 4;\n\n\n\n priv->rc_params.misc.type = VAEncMiscParameterTypeRateControl;\n\n priv->rc_params.rc = (VAEncMiscParameterRateControl) {\n\n .bits_per_second = avctx->bit_rate,\n\n .target_percentage = 66,\n\n .window_size = 1000,\n\n .initial_qp = (avctx->qmax >= 0 ? avctx->qmax : 40),\n\n .min_qp = (avctx->qmin >= 0 ? avctx->qmin : 20),\n\n .basic_unit_size = 0,\n\n };\n\n ctx->global_params[ctx->nb_global_params] =\n\n &priv->rc_params.misc;\n\n ctx->global_params_size[ctx->nb_global_params++] =\n\n sizeof(priv->rc_params);\n\n\n\n priv->hrd_params.misc.type = VAEncMiscParameterTypeHRD;\n\n priv->hrd_params.hrd = (VAEncMiscParameterHRD) {\n\n .initial_buffer_fullness = hrd_initial_buffer_fullness,\n\n .buffer_size = hrd_buffer_size,\n\n };\n\n ctx->global_params[ctx->nb_global_params] =\n\n &priv->hrd_params.misc;\n\n ctx->global_params_size[ctx->nb_global_params++] =\n\n sizeof(priv->hrd_params);\n\n\n\n // These still need to be set for pic_init_qp/slice_qp_delta.\n\n priv->fixed_qp_idr = 30;\n\n priv->fixed_qp_p = 30;\n\n priv->fixed_qp_b = 30;\n\n\n\n av_log(avctx, AV_LOG_DEBUG, \"Using constant-bitrate = %\"PRId64\" bps.\\n\",\n\n avctx->bit_rate);\n\n return 0;\n\n}\n", + "output": "0", + "index": 14169 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void RENAME(rgb24to32)(const uint8_t *src,uint8_t *dst,unsigned src_size)\n\n{\n\n uint8_t *dest = dst;\n\n const uint8_t *s = src;\n\n const uint8_t *end;\n\n#ifdef HAVE_MMX\n\n const uint8_t *mm_end;\n\n#endif\n\n end = s + src_size;\n\n#ifdef HAVE_MMX\n\n __asm __volatile(PREFETCH\"\t%0\"::\"m\"(*s):\"memory\");\n\n mm_end = end - 23;\n\n __asm __volatile(\"movq\t%0, %%mm7\"::\"m\"(mask32):\"memory\");\n\n while(s < mm_end)\n\n {\n\n __asm __volatile(\n\n\tPREFETCH\"\t32%1\\n\\t\"\n\n\t\"movd\t%1, %%mm0\\n\\t\"\n\n\t\"punpckldq 3%1, %%mm0\\n\\t\"\n\n\t\"movd\t6%1, %%mm1\\n\\t\"\n\n\t\"punpckldq 9%1, %%mm1\\n\\t\"\n\n\t\"movd\t12%1, %%mm2\\n\\t\"\n\n\t\"punpckldq 15%1, %%mm2\\n\\t\"\n\n\t\"movd\t18%1, %%mm3\\n\\t\"\n\n\t\"punpckldq 21%1, %%mm3\\n\\t\"\n\n\t\"pand\t%%mm7, %%mm0\\n\\t\"\n\n\t\"pand\t%%mm7, %%mm1\\n\\t\"\n\n\t\"pand\t%%mm7, %%mm2\\n\\t\"\n\n\t\"pand\t%%mm7, %%mm3\\n\\t\"\n\n\tMOVNTQ\"\t%%mm0, %0\\n\\t\"\n\n\tMOVNTQ\"\t%%mm1, 8%0\\n\\t\"\n\n\tMOVNTQ\"\t%%mm2, 16%0\\n\\t\"\n\n\tMOVNTQ\"\t%%mm3, 24%0\"\n\n\t:\"=m\"(*dest)\n\n\t:\"m\"(*s)\n\n\t:\"memory\");\n\n dest += 32;\n\n s += 24;\n\n }\n\n __asm __volatile(SFENCE:::\"memory\");\n\n __asm __volatile(EMMS:::\"memory\");\n\n#endif\n\n while(s < end)\n\n {\n\n#ifdef WORDS_BIGENDIAN\n\n *dest++ = 0;\n\n *dest++ = *s++;\n\n *dest++ = *s++;\n\n *dest++ = *s++;\n\n#else\n\n *dest++ = *s++;\n\n *dest++ = *s++;\n\n *dest++ = *s++;\n\n *dest++ = 0;\n\n#endif\n\n }\n\n}\n", + "output": "1", + "index": 1819 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int img_info(int argc, char **argv)\n\n{\n\n int c;\n\n OutputFormat output_format = OFORMAT_HUMAN;\n\n bool chain = false;\n\n const char *filename, *fmt, *output;\n\n ImageInfoList *list;\n\n bool image_opts = false;\n\n\n\n fmt = NULL;\n\n output = NULL;\n\n for(;;) {\n\n int option_index = 0;\n\n static const struct option long_options[] = {\n\n {\"help\", no_argument, 0, 'h'},\n\n {\"format\", required_argument, 0, 'f'},\n\n {\"output\", required_argument, 0, OPTION_OUTPUT},\n\n {\"backing-chain\", no_argument, 0, OPTION_BACKING_CHAIN},\n\n {\"object\", required_argument, 0, OPTION_OBJECT},\n\n {\"image-opts\", no_argument, 0, OPTION_IMAGE_OPTS},\n\n {0, 0, 0, 0}\n\n };\n\n c = getopt_long(argc, argv, \"f:h\",\n\n long_options, &option_index);\n\n if (c == -1) {\n\n break;\n\n }\n\n switch(c) {\n\n case '?':\n\n case 'h':\n\n help();\n\n break;\n\n case 'f':\n\n fmt = optarg;\n\n break;\n\n case OPTION_OUTPUT:\n\n output = optarg;\n\n break;\n\n case OPTION_BACKING_CHAIN:\n\n chain = true;\n\n break;\n\n case OPTION_OBJECT: {\n\n QemuOpts *opts;\n\n opts = qemu_opts_parse_noisily(&qemu_object_opts,\n\n optarg, true);\n\n if (!opts) {\n\n return 1;\n\n }\n\n } break;\n\n case OPTION_IMAGE_OPTS:\n\n image_opts = true;\n\n break;\n\n }\n\n }\n\n if (optind != argc - 1) {\n\n error_exit(\"Expecting one image file name\");\n\n }\n\n filename = argv[optind++];\n\n\n\n if (output && !strcmp(output, \"json\")) {\n\n output_format = OFORMAT_JSON;\n\n } else if (output && !strcmp(output, \"human\")) {\n\n output_format = OFORMAT_HUMAN;\n\n } else if (output) {\n\n error_report(\"--output must be used with human or json as argument.\");\n\n return 1;\n\n }\n\n\n\n if (qemu_opts_foreach(&qemu_object_opts,\n\n user_creatable_add_opts_foreach,\n\n NULL, NULL)) {\n\n return 1;\n\n }\n\n\n\n list = collect_image_info_list(image_opts, filename, fmt, chain);\n\n if (!list) {\n\n return 1;\n\n }\n\n\n\n switch (output_format) {\n\n case OFORMAT_HUMAN:\n\n dump_human_image_info_list(list);\n\n break;\n\n case OFORMAT_JSON:\n\n if (chain) {\n\n dump_json_image_info_list(list);\n\n } else {\n\n dump_json_image_info(list->value);\n\n }\n\n break;\n\n }\n\n\n\n qapi_free_ImageInfoList(list);\n\n return 0;\n\n}\n", + "output": "1", + "index": 16383 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int adx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,\n\n AVPacket *avpkt)\n\n{\n\n const uint8_t *buf0 = avpkt->data;\n\n int buf_size = avpkt->size;\n\n ADXContext *c = avctx->priv_data;\n\n int16_t *samples = data;\n\n const uint8_t *buf = buf0;\n\n int rest = buf_size;\n\n\n\n if (!c->header_parsed) {\n\n int hdrsize = adx_decode_header(avctx, buf, rest);\n\n if (!hdrsize)\n\n return -1;\n\n c->header_parsed = 1;\n\n buf += hdrsize;\n\n rest -= hdrsize;\n\n }\n\n\n\n /* 18 bytes of data are expanded into 32*2 bytes of audio,\n\n so guard against buffer overflows */\n\n if (rest / 18 > *data_size / 64)\n\n rest = (*data_size / 64) * 18;\n\n\n\n if (c->in_temp) {\n\n int copysize = 18 * avctx->channels - c->in_temp;\n\n memcpy(c->dec_temp + c->in_temp, buf, copysize);\n\n rest -= copysize;\n\n buf += copysize;\n\n if (avctx->channels == 1) {\n\n adx_decode(samples, c->dec_temp, c->prev);\n\n samples += 32;\n\n } else {\n\n adx_decode_stereo(samples, c->dec_temp, c->prev);\n\n samples += 32*2;\n\n }\n\n }\n\n\n\n if (avctx->channels == 1) {\n\n while (rest >= 18) {\n\n adx_decode(samples, buf, c->prev);\n\n rest -= 18;\n\n buf += 18;\n\n samples += 32;\n\n }\n\n } else {\n\n while (rest >= 18 * 2) {\n\n adx_decode_stereo(samples, buf, c->prev);\n\n rest -= 18 * 2;\n\n buf += 18 * 2;\n\n samples += 32 * 2;\n\n }\n\n }\n\n\n\n c->in_temp = rest;\n\n if (rest) {\n\n memcpy(c->dec_temp, buf, rest);\n\n buf += rest;\n\n }\n\n *data_size = (uint8_t*)samples - (uint8_t*)data;\n\n return buf - buf0;\n\n}\n", + "output": "0", + "index": 18292 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void amdvi_realize(DeviceState *dev, Error **err)\n\n{\n\n int ret = 0;\n\n AMDVIState *s = AMD_IOMMU_DEVICE(dev);\n\n X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev);\n\n MachineState *ms = MACHINE(qdev_get_machine());\n\n MachineClass *mc = MACHINE_GET_CLASS(ms);\n\n PCMachineState *pcms =\n\n PC_MACHINE(object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE));\n\n PCIBus *bus;\n\n\n\n if (!pcms) {\n\n error_setg(err, \"Machine-type '%s' not supported by amd-iommu\",\n\n mc->name);\n\n return;\n\n }\n\n\n\n bus = pcms->bus;\n\n s->iotlb = g_hash_table_new_full(amdvi_uint64_hash,\n\n amdvi_uint64_equal, g_free, g_free);\n\n\n\n /* This device should take care of IOMMU PCI properties */\n\n x86_iommu->type = TYPE_AMD;\n\n qdev_set_parent_bus(DEVICE(&s->pci), &bus->qbus);\n\n object_property_set_bool(OBJECT(&s->pci), true, \"realized\", err);\n\n ret = pci_add_capability(&s->pci.dev, AMDVI_CAPAB_ID_SEC, 0,\n\n AMDVI_CAPAB_SIZE, err);\n\n if (ret < 0) {\n\n return;\n\n }\n\n s->capab_offset = ret;\n\n\n\n ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_MSI, 0,\n\n AMDVI_CAPAB_REG_SIZE, err);\n\n if (ret < 0) {\n\n return;\n\n }\n\n ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_HT, 0,\n\n AMDVI_CAPAB_REG_SIZE, err);\n\n if (ret < 0) {\n\n return;\n\n }\n\n\n\n /* set up MMIO */\n\n memory_region_init_io(&s->mmio, OBJECT(s), &mmio_mem_ops, s, \"amdvi-mmio\",\n\n AMDVI_MMIO_SIZE);\n\n\n\n sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio);\n\n sysbus_mmio_map(SYS_BUS_DEVICE(s), 0, AMDVI_BASE_ADDR);\n\n pci_setup_iommu(bus, amdvi_host_dma_iommu, s);\n\n s->devid = object_property_get_int(OBJECT(&s->pci), \"addr\", err);\n\n msi_init(&s->pci.dev, 0, 1, true, false, err);\n\n amdvi_init(s);\n\n}\n", + "output": "0", + "index": 26601 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void pl061_write(void *opaque, hwaddr offset,\n\n uint64_t value, unsigned size)\n\n{\n\n PL061State *s = (PL061State *)opaque;\n\n uint8_t mask;\n\n\n\n if (offset < 0x400) {\n\n mask = (offset >> 2) & s->dir;\n\n s->data = (s->data & ~mask) | (value & mask);\n\n pl061_update(s);\n\n return;\n\n }\n\n switch (offset) {\n\n case 0x400: /* Direction */\n\n s->dir = value & 0xff;\n\n break;\n\n case 0x404: /* Interrupt sense */\n\n s->isense = value & 0xff;\n\n break;\n\n case 0x408: /* Interrupt both edges */\n\n s->ibe = value & 0xff;\n\n break;\n\n case 0x40c: /* Interrupt event */\n\n s->iev = value & 0xff;\n\n break;\n\n case 0x410: /* Interrupt mask */\n\n s->im = value & 0xff;\n\n break;\n\n case 0x41c: /* Interrupt clear */\n\n s->istate &= ~value;\n\n break;\n\n case 0x420: /* Alternate function select */\n\n mask = s->cr;\n\n s->afsel = (s->afsel & ~mask) | (value & mask);\n\n break;\n\n case 0x500: /* 2mA drive */\n\n s->dr2r = value & 0xff;\n\n break;\n\n case 0x504: /* 4mA drive */\n\n s->dr4r = value & 0xff;\n\n break;\n\n case 0x508: /* 8mA drive */\n\n s->dr8r = value & 0xff;\n\n break;\n\n case 0x50c: /* Open drain */\n\n s->odr = value & 0xff;\n\n break;\n\n case 0x510: /* Pull-up */\n\n s->pur = value & 0xff;\n\n break;\n\n case 0x514: /* Pull-down */\n\n s->pdr = value & 0xff;\n\n break;\n\n case 0x518: /* Slew rate control */\n\n s->slr = value & 0xff;\n\n break;\n\n case 0x51c: /* Digital enable */\n\n s->den = value & 0xff;\n\n break;\n\n case 0x520: /* Lock */\n\n s->locked = (value != 0xacce551);\n\n break;\n\n case 0x524: /* Commit */\n\n if (!s->locked)\n\n s->cr = value & 0xff;\n\n break;\n\n case 0x528:\n\n s->amsel = value & 0xff;\n\n break;\n\n default:\n\n qemu_log_mask(LOG_GUEST_ERROR,\n\n \"pl061_write: Bad offset %x\\n\", (int)offset);\n\n }\n\n pl061_update(s);\n\n}\n", + "output": "0", + "index": 5226 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,\n\n VLCcode *codes, int flags)\n\n{\n\n int table_size, table_index, index, code_prefix, symbol, subtable_bits;\n\n int i, j, k, n, nb, inc;\n\n uint32_t code;\n\n VLC_TYPE (*table)[2];\n\n\n\n table_size = 1 << table_nb_bits;\n\n if (table_nb_bits > 30)\n\n return -1;\n\n table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);\n\n av_dlog(NULL, \"new table index=%d size=%d\\n\", table_index, table_size);\n\n if (table_index < 0)\n\n return table_index;\n\n table = &vlc->table[table_index];\n\n\n\n for (i = 0; i < table_size; i++) {\n\n table[i][1] = 0; //bits\n\n table[i][0] = -1; //codes\n\n }\n\n\n\n /* first pass: map codes and compute auxiliary table sizes */\n\n for (i = 0; i < nb_codes; i++) {\n\n n = codes[i].bits;\n\n code = codes[i].code;\n\n symbol = codes[i].symbol;\n\n av_dlog(NULL, \"i=%d n=%d code=0x%x\\n\", i, n, code);\n\n if (n <= table_nb_bits) {\n\n /* no need to add another table */\n\n j = code >> (32 - table_nb_bits);\n\n nb = 1 << (table_nb_bits - n);\n\n inc = 1;\n\n if (flags & INIT_VLC_LE) {\n\n j = bitswap_32(code);\n\n inc = 1 << n;\n\n }\n\n for (k = 0; k < nb; k++) {\n\n av_dlog(NULL, \"%4x: code=%d n=%d\\n\", j, i, n);\n\n if (table[j][1] /*bits*/ != 0) {\n\n av_log(NULL, AV_LOG_ERROR, \"incorrect codes\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n table[j][1] = n; //bits\n\n table[j][0] = symbol;\n\n j += inc;\n\n }\n\n } else {\n\n /* fill auxiliary table recursively */\n\n n -= table_nb_bits;\n\n code_prefix = code >> (32 - table_nb_bits);\n\n subtable_bits = n;\n\n codes[i].bits = n;\n\n codes[i].code = code << table_nb_bits;\n\n for (k = i+1; k < nb_codes; k++) {\n\n n = codes[k].bits - table_nb_bits;\n\n if (n <= 0)\n\n break;\n\n code = codes[k].code;\n\n if (code >> (32 - table_nb_bits) != code_prefix)\n\n break;\n\n codes[k].bits = n;\n\n codes[k].code = code << table_nb_bits;\n\n subtable_bits = FFMAX(subtable_bits, n);\n\n }\n\n subtable_bits = FFMIN(subtable_bits, table_nb_bits);\n\n j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix;\n\n table[j][1] = -subtable_bits;\n\n av_dlog(NULL, \"%4x: n=%d (subtable)\\n\",\n\n j, codes[i].bits + table_nb_bits);\n\n index = build_table(vlc, subtable_bits, k-i, codes+i, flags);\n\n if (index < 0)\n\n return index;\n\n /* note: realloc has been done, so reload tables */\n\n table = &vlc->table[table_index];\n\n table[j][0] = index; //code\n\n\n i = k-1;\n\n }\n\n }\n\n return table_index;\n\n}", + "output": "1", + "index": 19635 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base,\n\n uint32_t ramsize,\n\n const char *initrd_filename,\n\n const char *dtb_filename,\n\n void (*machine_cpu_reset)(MicroBlazeCPU *))\n\n{\n\n QemuOpts *machine_opts;\n\n const char *kernel_filename;\n\n const char *kernel_cmdline;\n\n const char *dtb_arg;\n\n\n\n machine_opts = qemu_get_machine_opts();\n\n kernel_filename = qemu_opt_get(machine_opts, \"kernel\");\n\n kernel_cmdline = qemu_opt_get(machine_opts, \"append\");\n\n dtb_arg = qemu_opt_get(machine_opts, \"dtb\");\n\n if (dtb_arg) { /* Preference a -dtb argument */\n\n dtb_filename = dtb_arg;\n\n } else { /* default to pcbios dtb as passed by machine_init */\n\n dtb_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, dtb_filename);\n\n }\n\n\n\n boot_info.machine_cpu_reset = machine_cpu_reset;\n\n qemu_register_reset(main_cpu_reset, cpu);\n\n\n\n if (kernel_filename) {\n\n int kernel_size;\n\n uint64_t entry, low, high;\n\n uint32_t base32;\n\n int big_endian = 0;\n\n\n\n#ifdef TARGET_WORDS_BIGENDIAN\n\n big_endian = 1;\n\n#endif\n\n\n\n /* Boots a kernel elf binary. */\n\n kernel_size = load_elf(kernel_filename, NULL, NULL,\n\n &entry, &low, &high,\n\n big_endian, ELF_MACHINE, 0);\n\n base32 = entry;\n\n if (base32 == 0xc0000000) {\n\n kernel_size = load_elf(kernel_filename, translate_kernel_address,\n\n NULL, &entry, NULL, NULL,\n\n big_endian, ELF_MACHINE, 0);\n\n }\n\n /* Always boot into physical ram. */\n\n boot_info.bootstrap_pc = ddr_base + (entry & 0x0fffffff);\n\n\n\n /* If it wasn't an ELF image, try an u-boot image. */\n\n if (kernel_size < 0) {\n\n hwaddr uentry, loadaddr;\n\n\n\n kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0);\n\n boot_info.bootstrap_pc = uentry;\n\n high = (loadaddr + kernel_size + 3) & ~3;\n\n }\n\n\n\n /* Not an ELF image nor an u-boot image, try a RAW image. */\n\n if (kernel_size < 0) {\n\n kernel_size = load_image_targphys(kernel_filename, ddr_base,\n\n ram_size);\n\n boot_info.bootstrap_pc = ddr_base;\n\n high = (ddr_base + kernel_size + 3) & ~3;\n\n }\n\n\n\n if (initrd_filename) {\n\n int initrd_size;\n\n uint32_t initrd_offset;\n\n\n\n high = ROUND_UP(high + kernel_size, 4);\n\n boot_info.initrd_start = high;\n\n initrd_offset = boot_info.initrd_start - ddr_base;\n\n\n\n initrd_size = load_ramdisk(initrd_filename,\n\n boot_info.initrd_start,\n\n ram_size - initrd_offset);\n\n if (initrd_size < 0) {\n\n initrd_size = load_image_targphys(initrd_filename,\n\n boot_info.initrd_start,\n\n ram_size - initrd_offset);\n\n }\n\n if (initrd_size < 0) {\n\n error_report(\"qemu: could not load initrd '%s'\\n\",\n\n initrd_filename);\n\n exit(EXIT_FAILURE);\n\n }\n\n boot_info.initrd_end = boot_info.initrd_start + initrd_size;\n\n high = ROUND_UP(high + initrd_size, 4);\n\n }\n\n\n\n boot_info.cmdline = high + 4096;\n\n if (kernel_cmdline && strlen(kernel_cmdline)) {\n\n pstrcpy_targphys(\"cmdline\", boot_info.cmdline, 256, kernel_cmdline);\n\n }\n\n /* Provide a device-tree. */\n\n boot_info.fdt = boot_info.cmdline + 4096;\n\n microblaze_load_dtb(boot_info.fdt, ram_size,\n\n boot_info.initrd_start,\n\n boot_info.initrd_end,\n\n kernel_cmdline,\n\n dtb_filename);\n\n }\n\n\n\n}\n", + "output": "1", + "index": 13265 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int check_refcounts_l1(BlockDriverState *bs,\n\n uint16_t *refcount_table,\n\n int refcount_table_size,\n\n int64_t l1_table_offset, int l1_size,\n\n int check_copied)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n uint64_t *l1_table, l2_offset, l1_size2;\n\n int i, refcount, ret;\n\n int errors = 0;\n\n\n\n l1_size2 = l1_size * sizeof(uint64_t);\n\n\n\n /* Mark L1 table as used */\n\n errors += inc_refcounts(bs, refcount_table, refcount_table_size,\n\n l1_table_offset, l1_size2);\n\n\n\n /* Read L1 table entries from disk */\n\n if (l1_size2 == 0) {\n\n l1_table = NULL;\n\n } else {\n\n l1_table = qemu_malloc(l1_size2);\n\n if (bdrv_pread(bs->file, l1_table_offset,\n\n l1_table, l1_size2) != l1_size2)\n\n goto fail;\n\n for(i = 0;i < l1_size; i++)\n\n be64_to_cpus(&l1_table[i]);\n\n }\n\n\n\n /* Do the actual checks */\n\n for(i = 0; i < l1_size; i++) {\n\n l2_offset = l1_table[i];\n\n if (l2_offset) {\n\n /* QCOW_OFLAG_COPIED must be set iff refcount == 1 */\n\n if (check_copied) {\n\n refcount = get_refcount(bs, (l2_offset & ~QCOW_OFLAG_COPIED)\n\n >> s->cluster_bits);\n\n if (refcount < 0) {\n\n fprintf(stderr, \"Can't get refcount for l2_offset %\"\n\n PRIx64 \": %s\\n\", l2_offset, strerror(-refcount));\n\n }\n\n if ((refcount == 1) != ((l2_offset & QCOW_OFLAG_COPIED) != 0)) {\n\n fprintf(stderr, \"ERROR OFLAG_COPIED: l2_offset=%\" PRIx64\n\n \" refcount=%d\\n\", l2_offset, refcount);\n\n errors++;\n\n }\n\n }\n\n\n\n /* Mark L2 table as used */\n\n l2_offset &= ~QCOW_OFLAG_COPIED;\n\n errors += inc_refcounts(bs, refcount_table,\n\n refcount_table_size,\n\n l2_offset,\n\n s->cluster_size);\n\n\n\n /* L2 tables are cluster aligned */\n\n if (l2_offset & (s->cluster_size - 1)) {\n\n fprintf(stderr, \"ERROR l2_offset=%\" PRIx64 \": Table is not \"\n\n \"cluster aligned; L1 entry corrupted\\n\", l2_offset);\n\n errors++;\n\n }\n\n\n\n /* Process and check L2 entries */\n\n ret = check_refcounts_l2(bs, refcount_table, refcount_table_size,\n\n l2_offset, check_copied);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n errors += ret;\n\n }\n\n }\n\n qemu_free(l1_table);\n\n return errors;\n\n\n\nfail:\n\n fprintf(stderr, \"ERROR: I/O error in check_refcounts_l1\\n\");\n\n qemu_free(l1_table);\n\n return -EIO;\n\n}\n", + "output": "1", + "index": 6894 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline TranslationBlock *tb_find_fast(void)\n\n{\n\n TranslationBlock *tb;\n\n target_ulong cs_base, pc;\n\n uint64_t flags;\n\n\n\n /* we record a subset of the CPU state. It will\n\n always be the same before a given translated block\n\n is executed. */\n\n#if defined(TARGET_I386)\n\n flags = env->hflags;\n\n flags |= (env->eflags & (IOPL_MASK | TF_MASK | VM_MASK));\n\n flags |= env->intercept;\n\n cs_base = env->segs[R_CS].base;\n\n pc = cs_base + env->eip;\n\n#elif defined(TARGET_ARM)\n\n flags = env->thumb | (env->vfp.vec_len << 1)\n\n | (env->vfp.vec_stride << 4);\n\n if ((env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR)\n\n flags |= (1 << 6);\n\n if (env->vfp.xregs[ARM_VFP_FPEXC] & (1 << 30))\n\n flags |= (1 << 7);\n\n flags |= (env->condexec_bits << 8);\n\n cs_base = 0;\n\n pc = env->regs[15];\n\n#elif defined(TARGET_SPARC)\n\n#ifdef TARGET_SPARC64\n\n // Combined FPU enable bits . PRIV . DMMU enabled . IMMU enabled\n\n flags = (((env->pstate & PS_PEF) >> 1) | ((env->fprs & FPRS_FEF) << 2))\n\n | (env->pstate & PS_PRIV) | ((env->lsu & (DMMU_E | IMMU_E)) >> 2);\n\n#else\n\n // FPU enable . Supervisor\n\n flags = (env->psref << 4) | env->psrs;\n\n#endif\n\n cs_base = env->npc;\n\n pc = env->pc;\n\n#elif defined(TARGET_PPC)\n\n flags = env->hflags;\n\n cs_base = 0;\n\n pc = env->nip;\n\n#elif defined(TARGET_MIPS)\n\n flags = env->hflags & (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK);\n\n cs_base = 0;\n\n pc = env->PC[env->current_tc];\n\n#elif defined(TARGET_M68K)\n\n flags = (env->fpcr & M68K_FPCR_PREC) /* Bit 6 */\n\n | (env->sr & SR_S) /* Bit 13 */\n\n | ((env->macsr >> 4) & 0xf); /* Bits 0-3 */\n\n cs_base = 0;\n\n pc = env->pc;\n\n#elif defined(TARGET_SH4)\n\n flags = env->flags;\n\n cs_base = 0;\n\n pc = env->pc;\n\n#elif defined(TARGET_ALPHA)\n\n flags = env->ps;\n\n cs_base = 0;\n\n pc = env->pc;\n\n#elif defined(TARGET_CRIS)\n\n flags = env->pregs[PR_CCS] & (U_FLAG | X_FLAG);\n\n cs_base = 0;\n\n pc = env->pc;\n\n#else\n\n#error unsupported CPU\n\n#endif\n\n tb = env->tb_jmp_cache[tb_jmp_cache_hash_func(pc)];\n\n if (__builtin_expect(!tb || tb->pc != pc || tb->cs_base != cs_base ||\n\n tb->flags != flags, 0)) {\n\n tb = tb_find_slow(pc, cs_base, flags);\n\n /* Note: we do it here to avoid a gcc bug on Mac OS X when\n\n doing it in tb_find_slow */\n\n if (tb_invalidated_flag) {\n\n /* as some TB could have been invalidated because\n\n of memory exceptions while generating the code, we\n\n must recompute the hash index here */\n\n T0 = 0;\n\n }\n\n }\n\n return tb;\n\n}\n", + "output": "1", + "index": 22051 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int vpc_open(BlockDriverState *bs, int flags)\n\n{\n\n BDRVVPCState *s = bs->opaque;\n\n int i;\n\n struct vhd_footer* footer;\n\n struct vhd_dyndisk_header* dyndisk_header;\n\n uint8_t buf[HEADER_SIZE];\n\n uint32_t checksum;\n\n int err = -1;\n\n int disk_type = VHD_DYNAMIC;\n\n\n\n if (bdrv_pread(bs->file, 0, s->footer_buf, HEADER_SIZE) != HEADER_SIZE)\n\n goto fail;\n\n\n\n footer = (struct vhd_footer*) s->footer_buf;\n\n if (strncmp(footer->creator, \"conectix\", 8)) {\n\n int64_t offset = bdrv_getlength(bs->file);\n\n if (offset < HEADER_SIZE) {\n\n goto fail;\n\n }\n\n /* If a fixed disk, the footer is found only at the end of the file */\n\n if (bdrv_pread(bs->file, offset-HEADER_SIZE, s->footer_buf, HEADER_SIZE)\n\n != HEADER_SIZE) {\n\n goto fail;\n\n }\n\n if (strncmp(footer->creator, \"conectix\", 8)) {\n\n goto fail;\n\n }\n\n disk_type = VHD_FIXED;\n\n }\n\n\n\n checksum = be32_to_cpu(footer->checksum);\n\n footer->checksum = 0;\n\n if (vpc_checksum(s->footer_buf, HEADER_SIZE) != checksum)\n\n fprintf(stderr, \"block-vpc: The header checksum of '%s' is \"\n\n \"incorrect.\\n\", bs->filename);\n\n\n\n /* Write 'checksum' back to footer, or else will leave it with zero. */\n\n footer->checksum = be32_to_cpu(checksum);\n\n\n\n // The visible size of a image in Virtual PC depends on the geometry\n\n // rather than on the size stored in the footer (the size in the footer\n\n // is too large usually)\n\n bs->total_sectors = (int64_t)\n\n be16_to_cpu(footer->cyls) * footer->heads * footer->secs_per_cyl;\n\n\n\n /* Allow a maximum disk size of approximately 2 TB */\n\n if (bs->total_sectors >= 65535LL * 255 * 255) {\n\n err = -EFBIG;\n\n goto fail;\n\n }\n\n\n\n if (disk_type == VHD_DYNAMIC) {\n\n if (bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), buf,\n\n HEADER_SIZE) != HEADER_SIZE) {\n\n goto fail;\n\n }\n\n\n\n dyndisk_header = (struct vhd_dyndisk_header *) buf;\n\n\n\n if (strncmp(dyndisk_header->magic, \"cxsparse\", 8)) {\n\n goto fail;\n\n }\n\n\n\n s->block_size = be32_to_cpu(dyndisk_header->block_size);\n\n s->bitmap_size = ((s->block_size / (8 * 512)) + 511) & ~511;\n\n\n\n s->max_table_entries = be32_to_cpu(dyndisk_header->max_table_entries);\n\n s->pagetable = g_malloc(s->max_table_entries * 4);\n\n\n\n s->bat_offset = be64_to_cpu(dyndisk_header->table_offset);\n\n if (bdrv_pread(bs->file, s->bat_offset, s->pagetable,\n\n s->max_table_entries * 4) != s->max_table_entries * 4) {\n\n goto fail;\n\n }\n\n\n\n s->free_data_block_offset =\n\n (s->bat_offset + (s->max_table_entries * 4) + 511) & ~511;\n\n\n\n for (i = 0; i < s->max_table_entries; i++) {\n\n be32_to_cpus(&s->pagetable[i]);\n\n if (s->pagetable[i] != 0xFFFFFFFF) {\n\n int64_t next = (512 * (int64_t) s->pagetable[i]) +\n\n s->bitmap_size + s->block_size;\n\n\n\n if (next > s->free_data_block_offset) {\n\n s->free_data_block_offset = next;\n\n }\n\n }\n\n }\n\n\n\n s->last_bitmap_offset = (int64_t) -1;\n\n\n\n#ifdef CACHE\n\n s->pageentry_u8 = g_malloc(512);\n\n s->pageentry_u32 = s->pageentry_u8;\n\n s->pageentry_u16 = s->pageentry_u8;\n\n s->last_pagetable = -1;\n\n#endif\n\n }\n\n\n\n qemu_co_mutex_init(&s->lock);\n\n\n\n /* Disable migration when VHD images are used */\n\n error_set(&s->migration_blocker,\n\n QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,\n\n \"vpc\", bs->device_name, \"live migration\");\n\n migrate_add_blocker(s->migration_blocker);\n\n\n\n return 0;\n\n fail:\n\n return err;\n\n}\n", + "output": "1", + "index": 7547 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static BlockDriverAIOCB *rbd_start_aio(BlockDriverState *bs,\n\n int64_t sector_num,\n\n QEMUIOVector *qiov,\n\n int nb_sectors,\n\n BlockDriverCompletionFunc *cb,\n\n void *opaque,\n\n RBDAIOCmd cmd)\n\n{\n\n RBDAIOCB *acb;\n\n RADOSCB *rcb;\n\n rbd_completion_t c;\n\n int64_t off, size;\n\n char *buf;\n\n int r;\n\n\n\n BDRVRBDState *s = bs->opaque;\n\n\n\n acb = qemu_aio_get(&rbd_aiocb_info, bs, cb, opaque);\n\n acb->cmd = cmd;\n\n acb->qiov = qiov;\n\n if (cmd == RBD_AIO_DISCARD) {\n\n acb->bounce = NULL;\n\n } else {\n\n acb->bounce = qemu_blockalign(bs, qiov->size);\n\n }\n\n acb->ret = 0;\n\n acb->error = 0;\n\n acb->s = s;\n\n acb->cancelled = 0;\n\n acb->bh = NULL;\n\n acb->status = -EINPROGRESS;\n\n\n\n if (cmd == RBD_AIO_WRITE) {\n\n qemu_iovec_to_buf(acb->qiov, 0, acb->bounce, qiov->size);\n\n }\n\n\n\n buf = acb->bounce;\n\n\n\n off = sector_num * BDRV_SECTOR_SIZE;\n\n size = nb_sectors * BDRV_SECTOR_SIZE;\n\n\n\n s->qemu_aio_count++; /* All the RADOSCB */\n\n\n\n rcb = g_malloc(sizeof(RADOSCB));\n\n rcb->done = 0;\n\n rcb->acb = acb;\n\n rcb->buf = buf;\n\n rcb->s = acb->s;\n\n rcb->size = size;\n\n r = rbd_aio_create_completion(rcb, (rbd_callback_t) rbd_finish_aiocb, &c);\n\n if (r < 0) {\n\n goto failed;\n\n }\n\n\n\n switch (cmd) {\n\n case RBD_AIO_WRITE:\n\n r = rbd_aio_write(s->image, off, size, buf, c);\n\n break;\n\n case RBD_AIO_READ:\n\n r = rbd_aio_read(s->image, off, size, buf, c);\n\n break;\n\n case RBD_AIO_DISCARD:\n\n r = rbd_aio_discard_wrapper(s->image, off, size, c);\n\n break;\n\n default:\n\n r = -EINVAL;\n\n }\n\n\n\n if (r < 0) {\n\n goto failed;\n\n }\n\n\n\n return &acb->common;\n\n\n\nfailed:\n\n g_free(rcb);\n\n s->qemu_aio_count--;\n\n qemu_aio_release(acb);\n\n return NULL;\n\n}\n", + "output": "0", + "index": 16233 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void compute_pkt_fields2(AVStream *st, AVPacket *pkt){\n\n int b_frames = FFMAX(st->codec.has_b_frames, st->codec.max_b_frames);\n\n int num, den, frame_size;\n\n\n\n// av_log(NULL, AV_LOG_DEBUG, \"av_write_frame: pts:%lld dts:%lld cur_dts:%lld b:%d size:%d st:%d\\n\", pkt->pts, pkt->dts, st->cur_dts, b_frames, pkt->size, pkt->stream_index);\n\n \n\n/* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE)\n\n return -1;*/\n\n \n\n if(pkt->pts != AV_NOPTS_VALUE)\n\n pkt->pts = av_rescale(pkt->pts, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num);\n\n if(pkt->dts != AV_NOPTS_VALUE)\n\n pkt->dts = av_rescale(pkt->dts, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num);\n\n\n\n /* duration field */\n\n pkt->duration = av_rescale(pkt->duration, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num);\n\n if (pkt->duration == 0) {\n\n compute_frame_duration(&num, &den, st, NULL, pkt);\n\n if (den && num) {\n\n pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num);\n\n }\n\n }\n\n\n\n //XXX/FIXME this is a temporary hack until all encoders output pts\n\n if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !b_frames){\n\n pkt->dts=\n\n// pkt->pts= st->cur_dts;\n\n pkt->pts= st->pts.val;\n\n }\n\n\n\n //calculate dts from pts \n\n if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE){\n\n if(b_frames){\n\n if(st->last_IP_pts == AV_NOPTS_VALUE){\n\n st->last_IP_pts= -pkt->duration;\n\n }\n\n if(st->last_IP_pts < pkt->pts){\n\n pkt->dts= st->last_IP_pts;\n\n st->last_IP_pts= pkt->pts;\n\n }else\n\n pkt->dts= pkt->pts;\n\n }else\n\n pkt->dts= pkt->pts;\n\n }\n\n \n\n// av_log(NULL, AV_LOG_DEBUG, \"av_write_frame: pts2:%lld dts2:%lld\\n\", pkt->pts, pkt->dts);\n\n st->cur_dts= pkt->dts;\n\n st->pts.val= pkt->dts;\n\n\n\n /* update pts */\n\n switch (st->codec.codec_type) {\n\n case CODEC_TYPE_AUDIO:\n\n frame_size = get_audio_frame_size(&st->codec, pkt->size);\n\n\n\n /* HACK/FIXME, we skip the initial 0-size packets as they are most likely equal to the encoder delay,\n\n but it would be better if we had the real timestamps from the encoder */\n\n if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) {\n\n av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);\n\n }\n\n break;\n\n case CODEC_TYPE_VIDEO:\n\n av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec.frame_rate_base);\n\n break;\n\n default:\n\n break;\n\n }\n\n}\n", + "output": "1", + "index": 11752 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)\n\n{\n\n LavfiContext *lavfi = avctx->priv_data;\n\n double min_pts = DBL_MAX;\n\n int stream_idx, min_pts_sink_idx = 0;\n\n AVFrame *frame = lavfi->decoded_frame;\n\n AVPicture pict;\n\n AVDictionary *frame_metadata;\n\n int ret, i;\n\n int size = 0;\n\n\n\n if (lavfi->subcc_packet.size) {\n\n *pkt = lavfi->subcc_packet;\n\n av_init_packet(&lavfi->subcc_packet);\n\n lavfi->subcc_packet.size = 0;\n\n lavfi->subcc_packet.data = NULL;\n\n return pkt->size;\n\n }\n\n\n\n /* iterate through all the graph sinks. Select the sink with the\n\n * minimum PTS */\n\n for (i = 0; i < lavfi->nb_sinks; i++) {\n\n AVRational tb = lavfi->sinks[i]->inputs[0]->time_base;\n\n double d;\n\n int ret;\n\n\n\n if (lavfi->sink_eof[i])\n\n continue;\n\n\n\n ret = av_buffersink_get_frame_flags(lavfi->sinks[i], frame,\n\n AV_BUFFERSINK_FLAG_PEEK);\n\n if (ret == AVERROR_EOF) {\n\n av_dlog(avctx, \"EOF sink_idx:%d\\n\", i);\n\n lavfi->sink_eof[i] = 1;\n\n continue;\n\n } else if (ret < 0)\n\n return ret;\n\n d = av_rescale_q_rnd(frame->pts, tb, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);\n\n av_dlog(avctx, \"sink_idx:%d time:%f\\n\", i, d);\n\n av_frame_unref(frame);\n\n\n\n if (d < min_pts) {\n\n min_pts = d;\n\n min_pts_sink_idx = i;\n\n }\n\n }\n\n if (min_pts == DBL_MAX)\n\n return AVERROR_EOF;\n\n\n\n av_dlog(avctx, \"min_pts_sink_idx:%i\\n\", min_pts_sink_idx);\n\n\n\n av_buffersink_get_frame_flags(lavfi->sinks[min_pts_sink_idx], frame, 0);\n\n stream_idx = lavfi->sink_stream_map[min_pts_sink_idx];\n\n\n\n if (frame->width /* FIXME best way of testing a video */) {\n\n size = avpicture_get_size(frame->format, frame->width, frame->height);\n\n if ((ret = av_new_packet(pkt, size)) < 0)\n\n return ret;\n\n\n\n memcpy(pict.data, frame->data, 4*sizeof(frame->data[0]));\n\n memcpy(pict.linesize, frame->linesize, 4*sizeof(frame->linesize[0]));\n\n\n\n avpicture_layout(&pict, frame->format, frame->width, frame->height,\n\n pkt->data, size);\n\n } else if (av_frame_get_channels(frame) /* FIXME test audio */) {\n\n size = frame->nb_samples * av_get_bytes_per_sample(frame->format) *\n\n av_frame_get_channels(frame);\n\n if ((ret = av_new_packet(pkt, size)) < 0)\n\n return ret;\n\n memcpy(pkt->data, frame->data[0], size);\n\n }\n\n\n\n frame_metadata = av_frame_get_metadata(frame);\n\n if (frame_metadata) {\n\n uint8_t *metadata;\n\n AVDictionaryEntry *e = NULL;\n\n AVBPrint meta_buf;\n\n\n\n av_bprint_init(&meta_buf, 0, AV_BPRINT_SIZE_UNLIMITED);\n\n while ((e = av_dict_get(frame_metadata, \"\", e, AV_DICT_IGNORE_SUFFIX))) {\n\n av_bprintf(&meta_buf, \"%s\", e->key);\n\n av_bprint_chars(&meta_buf, '\\0', 1);\n\n av_bprintf(&meta_buf, \"%s\", e->value);\n\n av_bprint_chars(&meta_buf, '\\0', 1);\n\n }\n\n if (!av_bprint_is_complete(&meta_buf) ||\n\n !(metadata = av_packet_new_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA,\n\n meta_buf.len))) {\n\n av_bprint_finalize(&meta_buf, NULL);\n\n return AVERROR(ENOMEM);\n\n }\n\n memcpy(metadata, meta_buf.str, meta_buf.len);\n\n av_bprint_finalize(&meta_buf, NULL);\n\n }\n\n\n\n if ((ret = create_subcc_packet(avctx, frame, min_pts_sink_idx)) < 0) {\n\n av_frame_unref(frame);\n\n av_packet_unref(pkt);\n\n return ret;\n\n }\n\n\n\n pkt->stream_index = stream_idx;\n\n pkt->pts = frame->pts;\n\n pkt->pos = av_frame_get_pkt_pos(frame);\n\n pkt->size = size;\n\n av_frame_unref(frame);\n\n return size;\n\n}\n", + "output": "0", + "index": 480 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void piix4_pm_realize(PCIDevice *dev, Error **errp)\n\n{\n\n PIIX4PMState *s = PIIX4_PM(dev);\n\n uint8_t *pci_conf;\n\n\n\n pci_conf = dev->config;\n\n pci_conf[0x06] = 0x80;\n\n pci_conf[0x07] = 0x02;\n\n pci_conf[0x09] = 0x00;\n\n pci_conf[0x3d] = 0x01; // interrupt pin 1\n\n\n\n /* APM */\n\n apm_init(dev, &s->apm, apm_ctrl_changed, s);\n\n\n\n if (!s->smm_enabled) {\n\n /* Mark SMM as already inited to prevent SMM from running. KVM does not\n\n * support SMM mode. */\n\n pci_conf[0x5B] = 0x02;\n\n }\n\n\n\n /* XXX: which specification is used ? The i82731AB has different\n\n mappings */\n\n pci_conf[0x90] = s->smb_io_base | 1;\n\n pci_conf[0x91] = s->smb_io_base >> 8;\n\n pci_conf[0xd2] = 0x09;\n\n pm_smbus_init(DEVICE(dev), &s->smb);\n\n memory_region_set_enabled(&s->smb.io, pci_conf[0xd2] & 1);\n\n memory_region_add_subregion(pci_address_space_io(dev),\n\n s->smb_io_base, &s->smb.io);\n\n\n\n memory_region_init(&s->io, OBJECT(s), \"piix4-pm\", 64);\n\n memory_region_set_enabled(&s->io, false);\n\n memory_region_add_subregion(pci_address_space_io(dev),\n\n 0, &s->io);\n\n\n\n acpi_pm_tmr_init(&s->ar, pm_tmr_timer, &s->io);\n\n acpi_pm1_evt_init(&s->ar, pm_tmr_timer, &s->io);\n\n acpi_pm1_cnt_init(&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val);\n\n acpi_gpe_init(&s->ar, GPE_LEN);\n\n\n\n s->powerdown_notifier.notify = piix4_pm_powerdown_req;\n\n qemu_register_powerdown_notifier(&s->powerdown_notifier);\n\n\n\n s->machine_ready.notify = piix4_pm_machine_ready;\n\n qemu_add_machine_init_done_notifier(&s->machine_ready);\n\n qemu_register_reset(piix4_reset, s);\n\n\n\n piix4_acpi_system_hot_add_init(pci_address_space_io(dev), dev->bus, s);\n\n\n\n piix4_pm_add_propeties(s);\n\n}\n", + "output": "0", + "index": 16601 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)\n\n{\n\n ByteIOContext pb;\n\n uint8_t *buf;\n\n int len;\n\n int rtcp_bytes;\n\n\n\n if (!s->rtp_ctx || (count < 1))\n\n return -1;\n\n\n\n /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */\n\n s->octet_count += count;\n\n rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /\n\n RTCP_TX_RATIO_DEN;\n\n rtcp_bytes /= 50; // mmu_man: that's enough for me... VLC sends much less btw !?\n\n if (rtcp_bytes < 28)\n\n return -1;\n\n s->last_octet_count = s->octet_count;\n\n\n\n if (url_open_dyn_buf(&pb) < 0)\n\n return -1;\n\n\n\n // Receiver Report\n\n put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */\n\n put_byte(&pb, 201);\n\n put_be16(&pb, 7); /* length in words - 1 */\n\n put_be32(&pb, s->ssrc); // our own SSRC\n\n put_be32(&pb, s->ssrc); // XXX: should be the server's here!\n\n // some placeholders we should really fill...\n\n put_be32(&pb, ((0 << 24) | (0 & 0x0ffffff))); /* 0% lost, total 0 lost */\n\n put_be32(&pb, (0 << 16) | s->seq);\n\n put_be32(&pb, 0x68); /* jitter */\n\n put_be32(&pb, -1); /* last SR timestamp */\n\n put_be32(&pb, 1); /* delay since last SR */\n\n\n\n // CNAME\n\n put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */\n\n put_byte(&pb, 202);\n\n len = strlen(s->hostname);\n\n put_be16(&pb, (6 + len + 3) / 4); /* length in words - 1 */\n\n put_be32(&pb, s->ssrc);\n\n put_byte(&pb, 0x01);\n\n put_byte(&pb, len);\n\n put_buffer(&pb, s->hostname, len);\n\n // padding\n\n for (len = (6 + len) % 4; len % 4; len++) {\n\n put_byte(&pb, 0);\n\n }\n\n\n\n put_flush_packet(&pb);\n\n len = url_close_dyn_buf(&pb, &buf);\n\n if ((len > 0) && buf) {\n\n#if defined(DEBUG)\n\n printf(\"sending %d bytes of RR\\n\", len);\n\n#endif\n\n url_write(s->rtp_ctx, buf, len);\n\n av_free(buf);\n\n }\n\n return 0;\n\n}\n", + "output": "0", + "index": 6732 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int kvm_arch_put_registers(CPUState *cs, int level)\n\n{\n\n S390CPU *cpu = S390_CPU(cs);\n\n CPUS390XState *env = &cpu->env;\n\n struct kvm_sregs sregs;\n\n struct kvm_regs regs;\n\n struct kvm_fpu fpu;\n\n int r;\n\n int i;\n\n\n\n /* always save the PSW and the GPRS*/\n\n cs->kvm_run->psw_addr = env->psw.addr;\n\n cs->kvm_run->psw_mask = env->psw.mask;\n\n\n\n if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_GPRS) {\n\n for (i = 0; i < 16; i++) {\n\n cs->kvm_run->s.regs.gprs[i] = env->regs[i];\n\n cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_GPRS;\n\n }\n\n } else {\n\n for (i = 0; i < 16; i++) {\n\n regs.gprs[i] = env->regs[i];\n\n }\n\n r = kvm_vcpu_ioctl(cs, KVM_SET_REGS, ®s);\n\n if (r < 0) {\n\n return r;\n\n }\n\n }\n\n\n\n /* Floating point */\n\n for (i = 0; i < 16; i++) {\n\n fpu.fprs[i] = env->fregs[i].ll;\n\n }\n\n fpu.fpc = env->fpc;\n\n\n\n r = kvm_vcpu_ioctl(cs, KVM_SET_FPU, &fpu);\n\n if (r < 0) {\n\n return r;\n\n }\n\n\n\n /* Do we need to save more than that? */\n\n if (level == KVM_PUT_RUNTIME_STATE) {\n\n return 0;\n\n }\n\n\n\n /*\n\n * These ONE_REGS are not protected by a capability. As they are only\n\n * necessary for migration we just trace a possible error, but don't\n\n * return with an error return code.\n\n */\n\n kvm_set_one_reg(cs, KVM_REG_S390_CPU_TIMER, &env->cputm);\n\n kvm_set_one_reg(cs, KVM_REG_S390_CLOCK_COMP, &env->ckc);\n\n kvm_set_one_reg(cs, KVM_REG_S390_TODPR, &env->todpr);\n\n kvm_set_one_reg(cs, KVM_REG_S390_GBEA, &env->gbea);\n\n kvm_set_one_reg(cs, KVM_REG_S390_PP, &env->pp);\n\n\n\n if (cap_async_pf) {\n\n r = kvm_set_one_reg(cs, KVM_REG_S390_PFTOKEN, &env->pfault_token);\n\n if (r < 0) {\n\n return r;\n\n }\n\n r = kvm_set_one_reg(cs, KVM_REG_S390_PFCOMPARE, &env->pfault_compare);\n\n if (r < 0) {\n\n return r;\n\n }\n\n r = kvm_set_one_reg(cs, KVM_REG_S390_PFSELECT, &env->pfault_select);\n\n if (r < 0) {\n\n return r;\n\n }\n\n }\n\n\n\n if (cap_sync_regs &&\n\n cs->kvm_run->kvm_valid_regs & KVM_SYNC_ACRS &&\n\n cs->kvm_run->kvm_valid_regs & KVM_SYNC_CRS) {\n\n for (i = 0; i < 16; i++) {\n\n cs->kvm_run->s.regs.acrs[i] = env->aregs[i];\n\n cs->kvm_run->s.regs.crs[i] = env->cregs[i];\n\n }\n\n cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_ACRS;\n\n cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_CRS;\n\n } else {\n\n for (i = 0; i < 16; i++) {\n\n sregs.acrs[i] = env->aregs[i];\n\n sregs.crs[i] = env->cregs[i];\n\n }\n\n r = kvm_vcpu_ioctl(cs, KVM_SET_SREGS, &sregs);\n\n if (r < 0) {\n\n return r;\n\n }\n\n }\n\n\n\n /* Finally the prefix */\n\n if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_PREFIX) {\n\n cs->kvm_run->s.regs.prefix = env->psa;\n\n cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_PREFIX;\n\n } else {\n\n /* prefix is only supported via sync regs */\n\n }\n\n return 0;\n\n}\n", + "output": "0", + "index": 12853 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int coroutine_fn copy_sectors(BlockDriverState *bs,\n uint64_t start_sect,\n uint64_t cluster_offset,\n int n_start, int n_end)\n{\n BDRVQcowState *s = bs->opaque;\n QEMUIOVector qiov;\n struct iovec iov;\n int n, ret;\n /*\n * If this is the last cluster and it is only partially used, we must only\n * copy until the end of the image, or bdrv_check_request will fail for the\n * bdrv_read/write calls below.\n */\n if (start_sect + n_end > bs->total_sectors) {\n n_end = bs->total_sectors - start_sect;\n n = n_end - n_start;\n if (n <= 0) {\n return 0;\n iov.iov_len = n * BDRV_SECTOR_SIZE;\n iov.iov_base = qemu_blockalign(bs, iov.iov_len);\n qemu_iovec_init_external(&qiov, &iov, 1);\n BLKDBG_EVENT(bs->file, BLKDBG_COW_READ);\n /* Call .bdrv_co_readv() directly instead of using the public block-layer\n * interface. This avoids double I/O throttling and request tracking,\n * which can lead to deadlock when block layer copy-on-read is enabled.\n */\n ret = bs->drv->bdrv_co_readv(bs, start_sect + n_start, n, &qiov);\n if (ret < 0) {\n goto out;\n if (s->crypt_method) {\n qcow2_encrypt_sectors(s, start_sect + n_start,\n iov.iov_base, iov.iov_base, n, 1,\n &s->aes_encrypt_key);\n ret = qcow2_pre_write_overlap_check(bs, 0,\n cluster_offset + n_start * BDRV_SECTOR_SIZE, n * BDRV_SECTOR_SIZE);\n if (ret < 0) {\n goto out;\n BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);\n ret = bdrv_co_writev(bs->file, (cluster_offset >> 9) + n_start, n, &qiov);\n if (ret < 0) {\n goto out;\n ret = 0;\nout:\n qemu_vfree(iov.iov_base);\n return ret;", + "output": "1", + "index": 19445 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int thp_read_header(AVFormatContext *s,\n\n AVFormatParameters *ap)\n\n{\n\n ThpDemuxContext *thp = s->priv_data;\n\n AVStream *st;\n\n AVIOContext *pb = s->pb;\n\n int64_t fsize= avio_size(pb);\n\n int i;\n\n\n\n /* Read the file header. */\n\n avio_rb32(pb); /* Skip Magic. */\n\n thp->version = avio_rb32(pb);\n\n\n\n avio_rb32(pb); /* Max buf size. */\n\n avio_rb32(pb); /* Max samples. */\n\n\n\n thp->fps = av_d2q(av_int2float(avio_rb32(pb)), INT_MAX);\n\n thp->framecnt = avio_rb32(pb);\n\n thp->first_framesz = avio_rb32(pb);\n\n thp->data_size = avio_rb32(pb);\n\n if(fsize>0 && (!thp->data_size || fsize < thp->data_size))\n\n thp->data_size= fsize;\n\n\n\n thp->compoff = avio_rb32(pb);\n\n avio_rb32(pb); /* offsetDataOffset. */\n\n thp->first_frame = avio_rb32(pb);\n\n thp->last_frame = avio_rb32(pb);\n\n\n\n thp->next_framesz = thp->first_framesz;\n\n thp->next_frame = thp->first_frame;\n\n\n\n /* Read the component structure. */\n\n avio_seek (pb, thp->compoff, SEEK_SET);\n\n thp->compcount = avio_rb32(pb);\n\n\n\n /* Read the list of component types. */\n\n avio_read(pb, thp->components, 16);\n\n\n\n for (i = 0; i < thp->compcount; i++) {\n\n if (thp->components[i] == 0) {\n\n if (thp->vst != 0)\n\n break;\n\n\n\n /* Video component. */\n\n st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n\n\n /* The denominator and numerator are switched because 1/fps\n\n is required. */\n\n avpriv_set_pts_info(st, 64, thp->fps.den, thp->fps.num);\n\n st->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n\n st->codec->codec_id = CODEC_ID_THP;\n\n st->codec->codec_tag = 0; /* no fourcc */\n\n st->codec->width = avio_rb32(pb);\n\n st->codec->height = avio_rb32(pb);\n\n st->codec->sample_rate = av_q2d(thp->fps);\n\n thp->vst = st;\n\n thp->video_stream_index = st->index;\n\n\n\n if (thp->version == 0x11000)\n\n avio_rb32(pb); /* Unknown. */\n\n } else if (thp->components[i] == 1) {\n\n if (thp->has_audio != 0)\n\n break;\n\n\n\n /* Audio component. */\n\n st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n\n\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n st->codec->codec_id = CODEC_ID_ADPCM_THP;\n\n st->codec->codec_tag = 0; /* no fourcc */\n\n st->codec->channels = avio_rb32(pb); /* numChannels. */\n\n st->codec->sample_rate = avio_rb32(pb); /* Frequency. */\n\n\n\n avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);\n\n\n\n thp->audio_stream_index = st->index;\n\n thp->has_audio = 1;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 13549 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void cpu_loop(CPUUniCore32State *env)\n\n{\n\n CPUState *cs = CPU(uc32_env_get_cpu(env));\n\n int trapnr;\n\n unsigned int n, insn;\n\n target_siginfo_t info;\n\n\n\n for (;;) {\n\n cpu_exec_start(cs);\n\n trapnr = uc32_cpu_exec(cs);\n\n cpu_exec_end(cs);\n\n switch (trapnr) {\n\n case UC32_EXCP_PRIV:\n\n {\n\n /* system call */\n\n get_user_u32(insn, env->regs[31] - 4);\n\n n = insn & 0xffffff;\n\n\n\n if (n >= UC32_SYSCALL_BASE) {\n\n /* linux syscall */\n\n n -= UC32_SYSCALL_BASE;\n\n if (n == UC32_SYSCALL_NR_set_tls) {\n\n cpu_set_tls(env, env->regs[0]);\n\n env->regs[0] = 0;\n\n } else {\n\n env->regs[0] = do_syscall(env,\n\n n,\n\n env->regs[0],\n\n env->regs[1],\n\n env->regs[2],\n\n env->regs[3],\n\n env->regs[4],\n\n env->regs[5],\n\n 0, 0);\n\n }\n\n } else {\n\n goto error;\n\n }\n\n }\n\n break;\n\n case UC32_EXCP_DTRAP:\n\n case UC32_EXCP_ITRAP:\n\n info.si_signo = TARGET_SIGSEGV;\n\n info.si_errno = 0;\n\n /* XXX: check env->error_code */\n\n info.si_code = TARGET_SEGV_MAPERR;\n\n info._sifields._sigfault._addr = env->cp0.c4_faultaddr;\n\n queue_signal(env, info.si_signo, &info);\n\n break;\n\n case EXCP_INTERRUPT:\n\n /* just indicate that signals should be handled asap */\n\n break;\n\n case EXCP_DEBUG:\n\n {\n\n int sig;\n\n\n\n sig = gdb_handlesig(cs, TARGET_SIGTRAP);\n\n if (sig) {\n\n info.si_signo = sig;\n\n info.si_errno = 0;\n\n info.si_code = TARGET_TRAP_BRKPT;\n\n queue_signal(env, info.si_signo, &info);\n\n }\n\n }\n\n break;\n\n default:\n\n goto error;\n\n }\n\n process_pending_signals(env);\n\n }\n\n\n\nerror:\n\n fprintf(stderr, \"qemu: unhandled CPU exception 0x%x - aborting\\n\", trapnr);\n\n cpu_dump_state(cs, stderr, fprintf, 0);\n\n abort();\n\n}\n", + "output": "0", + "index": 3319 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static uint64_t get_cluster_offset(BlockDriverState *bs,\n uint64_t offset, int *num)\n{\n BDRVQcowState *s = bs->opaque;\n int l1_index, l2_index;\n uint64_t l2_offset, *l2_table, cluster_offset;\n int l1_bits, c;\n int index_in_cluster, nb_available, nb_needed, nb_clusters;\n index_in_cluster = (offset >> 9) & (s->cluster_sectors - 1);\n nb_needed = *num + index_in_cluster;\n l1_bits = s->l2_bits + s->cluster_bits;\n /* compute how many bytes there are between the offset and\n * the end of the l1 entry\n */\n nb_available = (1 << l1_bits) - (offset & ((1 << l1_bits) - 1));\n /* compute the number of available sectors */\n nb_available = (nb_available >> 9) + index_in_cluster;\n cluster_offset = 0;\n /* seek the the l2 offset in the l1 table */\n l1_index = offset >> l1_bits;\n if (l1_index >= s->l1_size)\n goto out;\n l2_offset = s->l1_table[l1_index];\n /* seek the l2 table of the given l2 offset */\n if (!l2_offset)\n goto out;\n /* load the l2 table in memory */\n l2_offset &= ~QCOW_OFLAG_COPIED;\n l2_table = l2_load(bs, l2_offset);\n if (l2_table == NULL)\n return 0;\n /* find the cluster offset for the given disk offset */\n l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1);\n cluster_offset = be64_to_cpu(l2_table[l2_index]);\n nb_clusters = size_to_clusters(s, nb_needed << 9);\n if (!cluster_offset) {\n /* how many empty clusters ? */\n c = count_contiguous_free_clusters(nb_clusters, &l2_table[l2_index]);\n } else {\n /* how many allocated clusters ? */\n c = count_contiguous_clusters(nb_clusters, s->cluster_size,\n &l2_table[l2_index], 0, QCOW_OFLAG_COPIED);\n nb_available = (c * s->cluster_sectors);\nout:\n if (nb_available > nb_needed)\n nb_available = nb_needed;\n *num = nb_available - index_in_cluster;\n return cluster_offset & ~QCOW_OFLAG_COPIED;", + "output": "1", + "index": 24791 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)\n\n{\n\n CPUState *cs = CPU(cpu);\n\n CPUX86State *env = &cpu->env;\n\n VAPICHandlers *handlers;\n\n uint8_t opcode[2];\n\n uint32_t imm32 = 0;\n\n target_ulong current_pc = 0;\n\n target_ulong current_cs_base = 0;\n\n uint32_t current_flags = 0;\n\n\n\n if (smp_cpus == 1) {\n\n handlers = &s->rom_state.up;\n\n } else {\n\n handlers = &s->rom_state.mp;\n\n }\n\n\n\n if (!kvm_enabled()) {\n\n cpu_get_tb_cpu_state(env, ¤t_pc, ¤t_cs_base,\n\n ¤t_flags);\n\n }\n\n\n\n pause_all_vcpus();\n\n\n\n cpu_memory_rw_debug(cs, ip, opcode, sizeof(opcode), 0);\n\n\n\n switch (opcode[0]) {\n\n case 0x89: /* mov r32 to r/m32 */\n\n patch_byte(cpu, ip, 0x50 + modrm_reg(opcode[1])); /* push reg */\n\n patch_call(s, cpu, ip + 1, handlers->set_tpr);\n\n break;\n\n case 0x8b: /* mov r/m32 to r32 */\n\n patch_byte(cpu, ip, 0x90);\n\n patch_call(s, cpu, ip + 1, handlers->get_tpr[modrm_reg(opcode[1])]);\n\n break;\n\n case 0xa1: /* mov abs to eax */\n\n patch_call(s, cpu, ip, handlers->get_tpr[0]);\n\n break;\n\n case 0xa3: /* mov eax to abs */\n\n patch_call(s, cpu, ip, handlers->set_tpr_eax);\n\n break;\n\n case 0xc7: /* mov imm32, r/m32 (c7/0) */\n\n patch_byte(cpu, ip, 0x68); /* push imm32 */\n\n cpu_memory_rw_debug(cs, ip + 6, (void *)&imm32, sizeof(imm32), 0);\n\n cpu_memory_rw_debug(cs, ip + 1, (void *)&imm32, sizeof(imm32), 1);\n\n patch_call(s, cpu, ip + 5, handlers->set_tpr);\n\n break;\n\n case 0xff: /* push r/m32 */\n\n patch_byte(cpu, ip, 0x50); /* push eax */\n\n patch_call(s, cpu, ip + 1, handlers->get_tpr_stack);\n\n break;\n\n default:\n\n abort();\n\n }\n\n\n\n resume_all_vcpus();\n\n\n\n if (!kvm_enabled()) {\n\n tb_gen_code(cs, current_pc, current_cs_base, current_flags, 1);\n\n cpu_resume_from_signal(cs, NULL);\n\n }\n\n}\n", + "output": "0", + "index": 2480 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int http_open_cnx(URLContext *h)\n\n{\n\n const char *path, *proxy_path, *lower_proto = \"tcp\", *local_path;\n\n char hostname[1024], hoststr[1024], proto[10];\n\n char auth[1024], proxyauth[1024];\n\n char path1[1024];\n\n char buf[1024], urlbuf[1024];\n\n int port, use_proxy, err, location_changed = 0, redirects = 0;\n\n HTTPAuthType cur_auth_type, cur_proxy_auth_type;\n\n HTTPContext *s = h->priv_data;\n\n URLContext *hd = NULL;\n\n\n\n proxy_path = getenv(\"http_proxy\");\n\n use_proxy = (proxy_path != NULL) && !getenv(\"no_proxy\") &&\n\n av_strstart(proxy_path, \"http://\", NULL);\n\n\n\n /* fill the dest addr */\n\n redo:\n\n /* needed in any case to build the host string */\n\n av_url_split(proto, sizeof(proto), auth, sizeof(auth),\n\n hostname, sizeof(hostname), &port,\n\n path1, sizeof(path1), s->location);\n\n ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);\n\n\n\n if (!strcmp(proto, \"https\")) {\n\n lower_proto = \"tls\";\n\n use_proxy = 0;\n\n if (port < 0)\n\n port = 443;\n\n }\n\n if (port < 0)\n\n port = 80;\n\n\n\n if (path1[0] == '\\0')\n\n path = \"/\";\n\n else\n\n path = path1;\n\n local_path = path;\n\n if (use_proxy) {\n\n /* Reassemble the request URL without auth string - we don't\n\n * want to leak the auth to the proxy. */\n\n ff_url_join(urlbuf, sizeof(urlbuf), proto, NULL, hostname, port, \"%s\",\n\n path1);\n\n path = urlbuf;\n\n av_url_split(NULL, 0, proxyauth, sizeof(proxyauth),\n\n hostname, sizeof(hostname), &port, NULL, 0, proxy_path);\n\n }\n\n\n\n ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);\n\n err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE,\n\n &h->interrupt_callback, NULL);\n\n if (err < 0)\n\n goto fail;\n\n\n\n s->hd = hd;\n\n cur_auth_type = s->auth_state.auth_type;\n\n cur_proxy_auth_type = s->auth_state.auth_type;\n\n if (http_connect(h, path, local_path, hoststr, auth, proxyauth, &location_changed) < 0)\n\n goto fail;\n\n if (s->http_code == 401) {\n\n if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) {\n\n ffurl_close(hd);\n\n goto redo;\n\n } else\n\n goto fail;\n\n }\n\n if (s->http_code == 407) {\n\n if (cur_proxy_auth_type == HTTP_AUTH_NONE &&\n\n s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) {\n\n ffurl_close(hd);\n\n goto redo;\n\n } else\n\n goto fail;\n\n }\n\n if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307)\n\n && location_changed == 1) {\n\n /* url moved, get next */\n\n ffurl_close(hd);\n\n if (redirects++ >= MAX_REDIRECTS)\n\n return AVERROR(EIO);\n\n location_changed = 0;\n\n goto redo;\n\n }\n\n return 0;\n\n fail:\n\n if (hd)\n\n ffurl_close(hd);\n\n s->hd = NULL;\n\n return AVERROR(EIO);\n\n}\n", + "output": "1", + "index": 22370 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "DeviceState *qdev_device_add(QemuOpts *opts)\n\n{\n\n ObjectClass *oc;\n\n DeviceClass *dc;\n\n const char *driver, *path, *id;\n\n DeviceState *dev;\n\n BusState *bus = NULL;\n\n Error *err = NULL;\n\n\n\n driver = qemu_opt_get(opts, \"driver\");\n\n if (!driver) {\n\n qerror_report(QERR_MISSING_PARAMETER, \"driver\");\n\n return NULL;\n\n }\n\n\n\n /* find driver */\n\n oc = object_class_by_name(driver);\n\n if (!oc) {\n\n const char *typename = find_typename_by_alias(driver);\n\n\n\n if (typename) {\n\n driver = typename;\n\n oc = object_class_by_name(driver);\n\n }\n\n }\n\n\n\n if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {\n\n qerror_report(ERROR_CLASS_GENERIC_ERROR,\n\n \"'%s' is not a valid device model name\", driver);\n\n return NULL;\n\n }\n\n\n\n if (object_class_is_abstract(oc)) {\n\n qerror_report(QERR_INVALID_PARAMETER_VALUE, \"driver\",\n\n \"non-abstract device type\");\n\n return NULL;\n\n }\n\n\n\n dc = DEVICE_CLASS(oc);\n\n if (dc->cannot_instantiate_with_device_add_yet) {\n\n qerror_report(QERR_INVALID_PARAMETER_VALUE, \"driver\",\n\n \"pluggable device type\");\n\n return NULL;\n\n }\n\n\n\n /* find bus */\n\n path = qemu_opt_get(opts, \"bus\");\n\n if (path != NULL) {\n\n bus = qbus_find(path);\n\n if (!bus) {\n\n return NULL;\n\n }\n\n if (!object_dynamic_cast(OBJECT(bus), dc->bus_type)) {\n\n qerror_report(QERR_BAD_BUS_FOR_DEVICE,\n\n driver, object_get_typename(OBJECT(bus)));\n\n return NULL;\n\n }\n\n } else if (dc->bus_type != NULL) {\n\n bus = qbus_find_recursive(sysbus_get_default(), NULL, dc->bus_type);\n\n if (!bus) {\n\n qerror_report(QERR_NO_BUS_FOR_DEVICE,\n\n dc->bus_type, driver);\n\n return NULL;\n\n }\n\n }\n\n if (qdev_hotplug && bus && !bus->allow_hotplug) {\n\n qerror_report(QERR_BUS_NO_HOTPLUG, bus->name);\n\n return NULL;\n\n }\n\n\n\n /* create device, set properties */\n\n dev = DEVICE(object_new(driver));\n\n\n\n if (bus) {\n\n qdev_set_parent_bus(dev, bus);\n\n }\n\n\n\n id = qemu_opts_id(opts);\n\n if (id) {\n\n dev->id = id;\n\n }\n\n if (qemu_opt_foreach(opts, set_property, dev, 1) != 0) {\n\n object_unparent(OBJECT(dev));\n\n object_unref(OBJECT(dev));\n\n return NULL;\n\n }\n\n if (dev->id) {\n\n object_property_add_child(qdev_get_peripheral(), dev->id,\n\n OBJECT(dev), NULL);\n\n } else {\n\n static int anon_count;\n\n gchar *name = g_strdup_printf(\"device[%d]\", anon_count++);\n\n object_property_add_child(qdev_get_peripheral_anon(), name,\n\n OBJECT(dev), NULL);\n\n g_free(name);\n\n }\n\n\n\n dev->opts = opts;\n\n object_property_set_bool(OBJECT(dev), true, \"realized\", &err);\n\n if (err != NULL) {\n\n qerror_report_err(err);\n\n error_free(err);\n\n dev->opts = NULL;\n\n object_unparent(OBJECT(dev));\n\n object_unref(OBJECT(dev));\n\n qerror_report(QERR_DEVICE_INIT_FAILED, driver);\n\n return NULL;\n\n }\n\n return dev;\n\n}\n", + "output": "1", + "index": 491 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)\n\n{\n\n uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;\n\n\n\n assert(kvm_enabled());\n\n\n\n x86_cpu_def->name = \"host\";\n\n host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx);\n\n x86_cpu_def->level = eax;\n\n x86_cpu_def->vendor1 = ebx;\n\n x86_cpu_def->vendor2 = edx;\n\n x86_cpu_def->vendor3 = ecx;\n\n\n\n host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx);\n\n x86_cpu_def->family = ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF);\n\n x86_cpu_def->model = ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12);\n\n x86_cpu_def->stepping = eax & 0x0F;\n\n x86_cpu_def->ext_features = ecx;\n\n x86_cpu_def->features = edx;\n\n\n\n if (x86_cpu_def->level >= 7) {\n\n x86_cpu_def->cpuid_7_0_ebx_features = kvm_arch_get_supported_cpuid(kvm_state, 0x7, 0, R_EBX);\n\n } else {\n\n x86_cpu_def->cpuid_7_0_ebx_features = 0;\n\n }\n\n\n\n host_cpuid(0x80000000, 0, &eax, &ebx, &ecx, &edx);\n\n x86_cpu_def->xlevel = eax;\n\n\n\n host_cpuid(0x80000001, 0, &eax, &ebx, &ecx, &edx);\n\n x86_cpu_def->ext2_features = edx;\n\n x86_cpu_def->ext3_features = ecx;\n\n cpu_x86_fill_model_id(x86_cpu_def->model_id);\n\n x86_cpu_def->vendor_override = 0;\n\n\n\n /* Call Centaur's CPUID instruction. */\n\n if (x86_cpu_def->vendor1 == CPUID_VENDOR_VIA_1 &&\n\n x86_cpu_def->vendor2 == CPUID_VENDOR_VIA_2 &&\n\n x86_cpu_def->vendor3 == CPUID_VENDOR_VIA_3) {\n\n host_cpuid(0xC0000000, 0, &eax, &ebx, &ecx, &edx);\n\n if (eax >= 0xC0000001) {\n\n /* Support VIA max extended level */\n\n x86_cpu_def->xlevel2 = eax;\n\n host_cpuid(0xC0000001, 0, &eax, &ebx, &ecx, &edx);\n\n x86_cpu_def->ext4_features = edx;\n\n }\n\n }\n\n\n\n /*\n\n * Every SVM feature requires emulation support in KVM - so we can't just\n\n * read the host features here. KVM might even support SVM features not\n\n * available on the host hardware. Just set all bits and mask out the\n\n * unsupported ones later.\n\n */\n\n x86_cpu_def->svm_features = -1;\n\n}\n", + "output": "0", + "index": 8259 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_h264_decode_extradata(H264Context *h)\n\n{\n\n AVCodecContext *avctx = h->s.avctx;\n\n\n\n if (avctx->extradata[0] == 1) {\n\n int i, cnt, nalsize;\n\n unsigned char *p = avctx->extradata;\n\n\n\n h->is_avc = 1;\n\n\n\n if (avctx->extradata_size < 7) {\n\n av_log(avctx, AV_LOG_ERROR, \"avcC too short\\n\");\n\n return -1;\n\n }\n\n /* sps and pps in the avcC always have length coded with 2 bytes,\n\n * so put a fake nal_length_size = 2 while parsing them */\n\n h->nal_length_size = 2;\n\n // Decode sps from avcC\n\n cnt = *(p + 5) & 0x1f; // Number of sps\n\n p += 6;\n\n for (i = 0; i < cnt; i++) {\n\n nalsize = AV_RB16(p) + 2;\n\n if (p - avctx->extradata + nalsize > avctx->extradata_size)\n\n return -1;\n\n if (decode_nal_units(h, p, nalsize) < 0) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Decoding sps %d from avcC failed\\n\", i);\n\n return -1;\n\n }\n\n p += nalsize;\n\n }\n\n // Decode pps from avcC\n\n cnt = *(p++); // Number of pps\n\n for (i = 0; i < cnt; i++) {\n\n nalsize = AV_RB16(p) + 2;\n\n if (p - avctx->extradata + nalsize > avctx->extradata_size)\n\n return -1;\n\n if (decode_nal_units(h, p, nalsize) < 0) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Decoding pps %d from avcC failed\\n\", i);\n\n return -1;\n\n }\n\n p += nalsize;\n\n }\n\n // Now store right nal length size, that will be used to parse all other nals\n\n h->nal_length_size = (avctx->extradata[4] & 0x03) + 1;\n\n } else {\n\n h->is_avc = 0;\n\n if (decode_nal_units(h, avctx->extradata, avctx->extradata_size) < 0)\n\n return -1;\n\n }\n\n return 0;\n\n}\n", + "output": "1", + "index": 1395 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)\n\n{\n\n SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req);\n\n SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);\n\n uint32_t len;\n\n uint8_t command;\n\n\n\n command = buf[0];\n\n\n\n if (s->tray_open || !bdrv_is_inserted(s->qdev.conf.bs)) {\n\n scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));\n\n return 0;\n\n }\n\n\n\n len = scsi_data_cdb_length(r->req.cmd.buf);\n\n switch (command) {\n\n case READ_6:\n\n case READ_10:\n\n case READ_12:\n\n case READ_16:\n\n DPRINTF(\"Read (sector %\" PRId64 \", count %u)\\n\", r->req.cmd.lba, len);\n\n if (r->req.cmd.buf[1] & 0xe0) {\n\n goto illegal_request;\n\n }\n\n if (!check_lba_range(s, r->req.cmd.lba, len)) {\n\n goto illegal_lba;\n\n }\n\n r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);\n\n r->sector_count = len * (s->qdev.blocksize / 512);\n\n break;\n\n case WRITE_6:\n\n case WRITE_10:\n\n case WRITE_12:\n\n case WRITE_16:\n\n case WRITE_VERIFY_10:\n\n case WRITE_VERIFY_12:\n\n case WRITE_VERIFY_16:\n\n if (bdrv_is_read_only(s->qdev.conf.bs)) {\n\n scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED));\n\n return 0;\n\n }\n\n DPRINTF(\"Write %s(sector %\" PRId64 \", count %u)\\n\",\n\n (command & 0xe) == 0xe ? \"And Verify \" : \"\",\n\n r->req.cmd.lba, len);\n\n if (r->req.cmd.buf[1] & 0xe0) {\n\n goto illegal_request;\n\n }\n\n if (!check_lba_range(s, r->req.cmd.lba, len)) {\n\n goto illegal_lba;\n\n }\n\n r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);\n\n r->sector_count = len * (s->qdev.blocksize / 512);\n\n break;\n\n default:\n\n abort();\n\n illegal_request:\n\n scsi_check_condition(r, SENSE_CODE(INVALID_FIELD));\n\n return 0;\n\n illegal_lba:\n\n scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE));\n\n return 0;\n\n }\n\n if (r->sector_count == 0) {\n\n scsi_req_complete(&r->req, GOOD);\n\n }\n\n assert(r->iov.iov_len == 0);\n\n if (r->req.cmd.mode == SCSI_XFER_TO_DEV) {\n\n return -r->sector_count * 512;\n\n } else {\n\n return r->sector_count * 512;\n\n }\n\n}\n", + "output": "0", + "index": 23852 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void *mpc8544_load_device_tree(target_phys_addr_t addr,\n\n uint32_t ramsize,\n\n target_phys_addr_t initrd_base,\n\n target_phys_addr_t initrd_size,\n\n const char *kernel_cmdline)\n\n{\n\n void *fdt = NULL;\n\n#ifdef CONFIG_FDT\n\n uint32_t mem_reg_property[] = {0, ramsize};\n\n char *filename;\n\n int fdt_size;\n\n int ret;\n\n\n\n filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);\n\n if (!filename) {\n\n goto out;\n\n }\n\n fdt = load_device_tree(filename, &fdt_size);\n\n qemu_free(filename);\n\n if (fdt == NULL) {\n\n goto out;\n\n }\n\n\n\n /* Manipulate device tree in memory. */\n\n ret = qemu_devtree_setprop(fdt, \"/memory\", \"reg\", mem_reg_property,\n\n sizeof(mem_reg_property));\n\n if (ret < 0)\n\n fprintf(stderr, \"couldn't set /memory/reg\\n\");\n\n\n\n ret = qemu_devtree_setprop_cell(fdt, \"/chosen\", \"linux,initrd-start\",\n\n initrd_base);\n\n if (ret < 0)\n\n fprintf(stderr, \"couldn't set /chosen/linux,initrd-start\\n\");\n\n\n\n ret = qemu_devtree_setprop_cell(fdt, \"/chosen\", \"linux,initrd-end\",\n\n (initrd_base + initrd_size));\n\n if (ret < 0)\n\n fprintf(stderr, \"couldn't set /chosen/linux,initrd-end\\n\");\n\n\n\n ret = qemu_devtree_setprop_string(fdt, \"/chosen\", \"bootargs\",\n\n kernel_cmdline);\n\n if (ret < 0)\n\n fprintf(stderr, \"couldn't set /chosen/bootargs\\n\");\n\n\n\n if (kvm_enabled()) {\n\n struct dirent *dirp;\n\n DIR *dp;\n\n char buf[128];\n\n\n\n if ((dp = opendir(\"/proc/device-tree/cpus/\")) == NULL) {\n\n printf(\"Can't open directory /proc/device-tree/cpus/\\n\");\n\n goto out;\n\n }\n\n\n\n buf[0] = '\\0';\n\n while ((dirp = readdir(dp)) != NULL) {\n\n if (strncmp(dirp->d_name, \"PowerPC\", 7) == 0) {\n\n snprintf(buf, 128, \"/cpus/%s\", dirp->d_name);\n\n break;\n\n }\n\n }\n\n closedir(dp);\n\n if (buf[0] == '\\0') {\n\n printf(\"Unknow host!\\n\");\n\n goto out;\n\n }\n\n\n\n mpc8544_copy_soc_cell(fdt, buf, \"clock-frequency\");\n\n mpc8544_copy_soc_cell(fdt, buf, \"timebase-frequency\");\n\n }\n\n\n\n cpu_physical_memory_write (addr, (void *)fdt, fdt_size);\n\n\n\nout:\n\n#endif\n\n\n\n return fdt;\n\n}\n", + "output": "0", + "index": 27266 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void init_fps(int bf, int audio_preroll, int fps)\n\n{\n\n AVStream *st;\n\n ctx = avformat_alloc_context();\n\n if (!ctx)\n\n exit(1);\n\n ctx->oformat = av_guess_format(format, NULL, NULL);\n\n if (!ctx->oformat)\n\n exit(1);\n\n ctx->pb = avio_alloc_context(iobuf, sizeof(iobuf), AVIO_FLAG_WRITE, NULL, NULL, io_write, NULL);\n\n if (!ctx->pb)\n\n exit(1);\n\n ctx->flags |= AVFMT_FLAG_BITEXACT;\n\n\n\n st = avformat_new_stream(ctx, NULL);\n\n if (!st)\n\n exit(1);\n\n st->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n\n st->codec->codec_id = AV_CODEC_ID_H264;\n\n st->codec->width = 640;\n\n st->codec->height = 480;\n\n st->time_base.num = 1;\n\n st->time_base.den = 30;\n\n st->codec->extradata_size = sizeof(h264_extradata);\n\n st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);\n\n if (!st->codec->extradata)\n\n exit(1);\n\n memcpy(st->codec->extradata, h264_extradata, sizeof(h264_extradata));\n\n st->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;\n\n video_st = st;\n\n\n\n st = avformat_new_stream(ctx, NULL);\n\n if (!st)\n\n exit(1);\n\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n st->codec->codec_id = AV_CODEC_ID_AAC;\n\n st->codec->sample_rate = 44100;\n\n st->codec->channels = 2;\n\n st->time_base.num = 1;\n\n st->time_base.den = 44100;\n\n st->codec->extradata_size = sizeof(aac_extradata);\n\n st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);\n\n if (!st->codec->extradata)\n\n exit(1);\n\n memcpy(st->codec->extradata, aac_extradata, sizeof(aac_extradata));\n\n st->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;\n\n audio_st = st;\n\n\n\n if (avformat_write_header(ctx, &opts) < 0)\n\n exit(1);\n\n av_dict_free(&opts);\n\n\n\n frames = 0;\n\n gop_size = 30;\n\n duration = video_st->time_base.den / fps;\n\n audio_duration = 1024 * audio_st->time_base.den / audio_st->codec->sample_rate;\n\n if (audio_preroll)\n\n audio_preroll = 2048 * audio_st->time_base.den / audio_st->codec->sample_rate;\n\n\n\n bframes = bf;\n\n video_dts = bframes ? -duration : 0;\n\n audio_dts = -audio_preroll;\n\n}\n", + "output": "1", + "index": 5951 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void FUNC(sao_band_filter)(uint8_t *_dst, uint8_t *_src,\n\n ptrdiff_t stride, SAOParams *sao,\n\n int *borders, int width, int height,\n\n int c_idx, int class)\n\n{\n\n pixel *dst = (pixel *)_dst;\n\n pixel *src = (pixel *)_src;\n\n int offset_table[32] = { 0 };\n\n int k, y, x;\n\n int chroma = !!c_idx;\n\n int shift = BIT_DEPTH - 5;\n\n int *sao_offset_val = sao->offset_val[c_idx];\n\n int sao_left_class = sao->band_position[c_idx];\n\n int init_y = 0, init_x = 0;\n\n\n\n stride /= sizeof(pixel);\n\n\n\n switch (class) {\n\n case 0:\n\n if (!borders[2])\n\n width -= (8 >> chroma) + 2;\n\n if (!borders[3])\n\n height -= (4 >> chroma) + 2;\n\n break;\n\n case 1:\n\n init_y = -(4 >> chroma) - 2;\n\n if (!borders[2])\n\n width -= (8 >> chroma) + 2;\n\n height = (4 >> chroma) + 2;\n\n break;\n\n case 2:\n\n init_x = -(8 >> chroma) - 2;\n\n width = (8 >> chroma) + 2;\n\n if (!borders[3])\n\n height -= (4 >> chroma) + 2;\n\n break;\n\n case 3:\n\n init_y = -(4 >> chroma) - 2;\n\n init_x = -(8 >> chroma) - 2;\n\n width = (8 >> chroma) + 2;\n\n height = (4 >> chroma) + 2;\n\n break;\n\n }\n\n\n\n dst = dst + (init_y * stride + init_x);\n\n src = src + (init_y * stride + init_x);\n\n for (k = 0; k < 4; k++)\n\n offset_table[(k + sao_left_class) & 31] = sao_offset_val[k + 1];\n\n for (y = 0; y < height; y++) {\n\n for (x = 0; x < width; x++)\n\n dst[x] = av_clip_pixel(src[x] + offset_table[av_clip_pixel(src[x] >> shift)]);\n\n dst += stride;\n\n src += stride;\n\n }\n\n}\n", + "output": "0", + "index": 5396 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void init_band_stepsize(AVCodecContext *avctx,\n\n Jpeg2000Band *band,\n\n Jpeg2000CodingStyle *codsty,\n\n Jpeg2000QuantStyle *qntsty,\n\n int bandno, int gbandno, int reslevelno,\n\n int cbps)\n\n{\n\n /* TODO: Implementation of quantization step not finished,\n\n * see ISO/IEC 15444-1:2002 E.1 and A.6.4. */\n\n switch (qntsty->quantsty) {\n\n uint8_t gain;\n\n case JPEG2000_QSTY_NONE:\n\n /* TODO: to verify. No quantization in this case */\n\n band->f_stepsize = 1;\n\n break;\n\n case JPEG2000_QSTY_SI:\n\n /*TODO: Compute formula to implement. */\n\n// numbps = cbps +\n\n// lut_gain[codsty->transform == FF_DWT53][bandno + (reslevelno > 0)];\n\n// band->f_stepsize = SHL(2048 + qntsty->mant[gbandno],\n\n// 2 + numbps - qntsty->expn[gbandno]);\n\n// break;\n\n case JPEG2000_QSTY_SE:\n\n /* Exponent quantization step.\n\n * Formula:\n\n * delta_b = 2 ^ (R_b - expn_b) * (1 + (mant_b / 2 ^ 11))\n\n * R_b = R_I + log2 (gain_b )\n\n * see ISO/IEC 15444-1:2002 E.1.1 eqn. E-3 and E-4 */\n\n gain = cbps;\n\n band->f_stepsize = pow(2.0, gain - qntsty->expn[gbandno]);\n\n band->f_stepsize *= qntsty->mant[gbandno] / 2048.0 + 1.0;\n\n break;\n\n default:\n\n band->f_stepsize = 0;\n\n av_log(avctx, AV_LOG_ERROR, \"Unknown quantization format\\n\");\n\n break;\n\n }\n\n if (codsty->transform != FF_DWT53) {\n\n int lband = 0;\n\n switch (bandno + (reslevelno > 0)) {\n\n case 1:\n\n case 2:\n\n band->f_stepsize *= F_LFTG_X * 2;\n\n lband = 1;\n\n break;\n\n case 3:\n\n band->f_stepsize *= F_LFTG_X * F_LFTG_X * 4;\n\n break;\n\n }\n\n if (codsty->transform == FF_DWT97) {\n\n band->f_stepsize *= pow(F_LFTG_K, 2*(codsty->nreslevels2decode - reslevelno) + lband - 2);\n\n }\n\n }\n\n\n\n band->i_stepsize = band->f_stepsize * (1 << 15);\n\n\n\n /* FIXME: In openjepg code stespize = stepsize * 0.5. Why?\n\n * If not set output of entropic decoder is not correct. */\n\n if (!av_codec_is_encoder(avctx->codec))\n\n band->f_stepsize *= 0.5;\n\n}\n", + "output": "1", + "index": 13689 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void test_acpi_fadt_table(test_data *data)\n\n{\n\n AcpiFadtDescriptorRev1 *fadt_table = &data->fadt_table;\n\n uint32_t addr;\n\n\n\n /* FADT table comes first */\n\n addr = data->rsdt_tables_addr[0];\n\n ACPI_READ_TABLE_HEADER(fadt_table, addr);\n\n\n\n ACPI_READ_FIELD(fadt_table->firmware_ctrl, addr);\n\n ACPI_READ_FIELD(fadt_table->dsdt, addr);\n\n ACPI_READ_FIELD(fadt_table->model, addr);\n\n ACPI_READ_FIELD(fadt_table->reserved1, addr);\n\n ACPI_READ_FIELD(fadt_table->sci_int, addr);\n\n ACPI_READ_FIELD(fadt_table->smi_cmd, addr);\n\n ACPI_READ_FIELD(fadt_table->acpi_enable, addr);\n\n ACPI_READ_FIELD(fadt_table->acpi_disable, addr);\n\n ACPI_READ_FIELD(fadt_table->S4bios_req, addr);\n\n ACPI_READ_FIELD(fadt_table->reserved2, addr);\n\n ACPI_READ_FIELD(fadt_table->pm1a_evt_blk, addr);\n\n ACPI_READ_FIELD(fadt_table->pm1b_evt_blk, addr);\n\n ACPI_READ_FIELD(fadt_table->pm1a_cnt_blk, addr);\n\n ACPI_READ_FIELD(fadt_table->pm1b_cnt_blk, addr);\n\n ACPI_READ_FIELD(fadt_table->pm2_cnt_blk, addr);\n\n ACPI_READ_FIELD(fadt_table->pm_tmr_blk, addr);\n\n ACPI_READ_FIELD(fadt_table->gpe0_blk, addr);\n\n ACPI_READ_FIELD(fadt_table->gpe1_blk, addr);\n\n ACPI_READ_FIELD(fadt_table->pm1_evt_len, addr);\n\n ACPI_READ_FIELD(fadt_table->pm1_cnt_len, addr);\n\n ACPI_READ_FIELD(fadt_table->pm2_cnt_len, addr);\n\n ACPI_READ_FIELD(fadt_table->pm_tmr_len, addr);\n\n ACPI_READ_FIELD(fadt_table->gpe0_blk_len, addr);\n\n ACPI_READ_FIELD(fadt_table->gpe1_blk_len, addr);\n\n ACPI_READ_FIELD(fadt_table->gpe1_base, addr);\n\n ACPI_READ_FIELD(fadt_table->reserved3, addr);\n\n ACPI_READ_FIELD(fadt_table->plvl2_lat, addr);\n\n ACPI_READ_FIELD(fadt_table->plvl3_lat, addr);\n\n ACPI_READ_FIELD(fadt_table->flush_size, addr);\n\n ACPI_READ_FIELD(fadt_table->flush_stride, addr);\n\n ACPI_READ_FIELD(fadt_table->duty_offset, addr);\n\n ACPI_READ_FIELD(fadt_table->duty_width, addr);\n\n ACPI_READ_FIELD(fadt_table->day_alrm, addr);\n\n ACPI_READ_FIELD(fadt_table->mon_alrm, addr);\n\n ACPI_READ_FIELD(fadt_table->century, addr);\n\n ACPI_READ_FIELD(fadt_table->reserved4, addr);\n\n ACPI_READ_FIELD(fadt_table->reserved4a, addr);\n\n ACPI_READ_FIELD(fadt_table->reserved4b, addr);\n\n ACPI_READ_FIELD(fadt_table->flags, addr);\n\n\n\n ACPI_ASSERT_CMP(fadt_table->signature, \"FACP\");\n\n g_assert(!acpi_calc_checksum((uint8_t *)fadt_table, fadt_table->length));\n\n}\n", + "output": "0", + "index": 16626 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "build_srat(GArray *table_data, GArray *linker, MachineState *machine)\n\n{\n\n AcpiSystemResourceAffinityTable *srat;\n\n AcpiSratProcessorAffinity *core;\n\n AcpiSratMemoryAffinity *numamem;\n\n\n\n int i;\n\n uint64_t curnode;\n\n int srat_start, numa_start, slots;\n\n uint64_t mem_len, mem_base, next_base;\n\n MachineClass *mc = MACHINE_GET_CLASS(machine);\n\n CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(machine);\n\n PCMachineState *pcms = PC_MACHINE(machine);\n\n ram_addr_t hotplugabble_address_space_size =\n\n object_property_get_int(OBJECT(pcms), PC_MACHINE_MEMHP_REGION_SIZE,\n\n NULL);\n\n\n\n srat_start = table_data->len;\n\n\n\n srat = acpi_data_push(table_data, sizeof *srat);\n\n srat->reserved1 = cpu_to_le32(1);\n\n\n\n for (i = 0; i < apic_ids->len; i++) {\n\n int apic_id = apic_ids->cpus[i].arch_id;\n\n\n\n core = acpi_data_push(table_data, sizeof *core);\n\n core->type = ACPI_SRAT_PROCESSOR_APIC;\n\n core->length = sizeof(*core);\n\n core->local_apic_id = apic_id;\n\n curnode = pcms->node_cpu[apic_id];\n\n core->proximity_lo = curnode;\n\n memset(core->proximity_hi, 0, 3);\n\n core->local_sapic_eid = 0;\n\n core->flags = cpu_to_le32(1);\n\n }\n\n\n\n\n\n /* the memory map is a bit tricky, it contains at least one hole\n\n * from 640k-1M and possibly another one from 3.5G-4G.\n\n */\n\n next_base = 0;\n\n numa_start = table_data->len;\n\n\n\n numamem = acpi_data_push(table_data, sizeof *numamem);\n\n build_srat_memory(numamem, 0, 640 * 1024, 0, MEM_AFFINITY_ENABLED);\n\n next_base = 1024 * 1024;\n\n for (i = 1; i < pcms->numa_nodes + 1; ++i) {\n\n mem_base = next_base;\n\n mem_len = pcms->node_mem[i - 1];\n\n if (i == 1) {\n\n mem_len -= 1024 * 1024;\n\n }\n\n next_base = mem_base + mem_len;\n\n\n\n /* Cut out the ACPI_PCI hole */\n\n if (mem_base <= pcms->below_4g_mem_size &&\n\n next_base > pcms->below_4g_mem_size) {\n\n mem_len -= next_base - pcms->below_4g_mem_size;\n\n if (mem_len > 0) {\n\n numamem = acpi_data_push(table_data, sizeof *numamem);\n\n build_srat_memory(numamem, mem_base, mem_len, i - 1,\n\n MEM_AFFINITY_ENABLED);\n\n }\n\n mem_base = 1ULL << 32;\n\n mem_len = next_base - pcms->below_4g_mem_size;\n\n next_base += (1ULL << 32) - pcms->below_4g_mem_size;\n\n }\n\n numamem = acpi_data_push(table_data, sizeof *numamem);\n\n build_srat_memory(numamem, mem_base, mem_len, i - 1,\n\n MEM_AFFINITY_ENABLED);\n\n }\n\n slots = (table_data->len - numa_start) / sizeof *numamem;\n\n for (; slots < pcms->numa_nodes + 2; slots++) {\n\n numamem = acpi_data_push(table_data, sizeof *numamem);\n\n build_srat_memory(numamem, 0, 0, 0, MEM_AFFINITY_NOFLAGS);\n\n }\n\n\n\n /*\n\n * Entry is required for Windows to enable memory hotplug in OS.\n\n * Memory devices may override proximity set by this entry,\n\n * providing _PXM method if necessary.\n\n */\n\n if (hotplugabble_address_space_size) {\n\n numamem = acpi_data_push(table_data, sizeof *numamem);\n\n build_srat_memory(numamem, pcms->hotplug_memory.base,\n\n hotplugabble_address_space_size, 0,\n\n MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED);\n\n }\n\n\n\n build_header(linker, table_data,\n\n (void *)(table_data->data + srat_start),\n\n \"SRAT\",\n\n table_data->len - srat_start, 1, NULL, NULL);\n\n g_free(apic_ids);\n\n}\n", + "output": "0", + "index": 10927 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed){\n int i, ret= -1;\n int av_unused mm_flags = av_get_cpu_flags();\n int need_emms= 0;\n if (c->compensation_distance)\n dst_size = FFMIN(dst_size, c->compensation_distance);\n for(i=0; ich_count; i++){\n#if HAVE_MMXEXT_INLINE\n#if HAVE_SSE2_INLINE\n if(c->format == AV_SAMPLE_FMT_S16P && (mm_flags&AV_CPU_FLAG_SSE2)) ret= swri_resample_int16_sse2 (c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);\n else\n#endif\n if(c->format == AV_SAMPLE_FMT_S16P && (mm_flags&AV_CPU_FLAG_MMX2 )){\n ret= swri_resample_int16_mmx2 (c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);\n need_emms= 1;\n } else\n#endif\n if(c->format == AV_SAMPLE_FMT_S16P) ret= swri_resample_int16(c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);\n else if(c->format == AV_SAMPLE_FMT_S32P) ret= swri_resample_int32(c, (int32_t*)dst->ch[i], (const int32_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);\n#if HAVE_AVX_INLINE\n else if(c->format == AV_SAMPLE_FMT_FLTP && (mm_flags&AV_CPU_FLAG_AVX))\n ret= swri_resample_float_avx (c, (float*)dst->ch[i], (const float*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);\n#endif\n#if HAVE_SSE_INLINE\n else if(c->format == AV_SAMPLE_FMT_FLTP && (mm_flags&AV_CPU_FLAG_SSE))\n ret= swri_resample_float_sse (c, (float*)dst->ch[i], (const float*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);\n#endif\n else if(c->format == AV_SAMPLE_FMT_FLTP) ret= swri_resample_float(c, (float *)dst->ch[i], (const float *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);\n#if HAVE_SSE2_INLINE\n else if(c->format == AV_SAMPLE_FMT_DBLP && (mm_flags&AV_CPU_FLAG_SSE2))\n ret= swri_resample_double_sse2(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);\n#endif\n else if(c->format == AV_SAMPLE_FMT_DBLP) ret= swri_resample_double(c,(double *)dst->ch[i], (const double *)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count);\n if(need_emms)\n emms_c();\n return ret;", + "output": "1", + "index": 17907 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void ioinst_handle_stsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)\n\n{\n\n int cssid, ssid, schid, m;\n\n SubchDev *sch;\n\n uint64_t addr;\n\n int cc;\n\n SCHIB schib;\n\n CPUS390XState *env = &cpu->env;\n\n uint8_t ar;\n\n\n\n addr = decode_basedisp_s(env, ipb, &ar);\n\n if (addr & 3) {\n\n program_interrupt(env, PGM_SPECIFICATION, 2);\n\n return;\n\n }\n\n\n\n if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) {\n\n /*\n\n * As operand exceptions have a lower priority than access exceptions,\n\n * we check whether the memory area is writeable (injecting the\n\n * access execption if it is not) first.\n\n */\n\n if (!s390_cpu_virt_mem_check_write(cpu, addr, ar, sizeof(schib))) {\n\n program_interrupt(env, PGM_OPERAND, 2);\n\n }\n\n return;\n\n }\n\n trace_ioinst_sch_id(\"stsch\", cssid, ssid, schid);\n\n sch = css_find_subch(m, cssid, ssid, schid);\n\n if (sch) {\n\n if (css_subch_visible(sch)) {\n\n css_do_stsch(sch, &schib);\n\n cc = 0;\n\n } else {\n\n /* Indicate no more subchannels in this css/ss */\n\n cc = 3;\n\n }\n\n } else {\n\n if (css_schid_final(m, cssid, ssid, schid)) {\n\n cc = 3; /* No more subchannels in this css/ss */\n\n } else {\n\n /* Store an empty schib. */\n\n memset(&schib, 0, sizeof(schib));\n\n cc = 0;\n\n }\n\n }\n\n if (cc != 3) {\n\n if (s390_cpu_virt_mem_write(cpu, addr, ar, &schib,\n\n sizeof(schib)) != 0) {\n\n return;\n\n }\n\n } else {\n\n /* Access exceptions have a higher priority than cc3 */\n\n if (s390_cpu_virt_mem_check_write(cpu, addr, ar, sizeof(schib)) != 0) {\n\n return;\n\n }\n\n }\n\n setcc(cpu, cc);\n\n}\n", + "output": "0", + "index": 9866 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void spapr_phb_placement(sPAPRMachineState *spapr, uint32_t index,\n\n uint64_t *buid, hwaddr *pio,\n\n hwaddr *mmio32, hwaddr *mmio64,\n\n unsigned n_dma, uint32_t *liobns, Error **errp)\n\n{\n\n /*\n\n * New-style PHB window placement.\n\n *\n\n * Goals: Gives large (1TiB), naturally aligned 64-bit MMIO window\n\n * for each PHB, in addition to 2GiB 32-bit MMIO and 64kiB PIO\n\n * windows.\n\n *\n\n * Some guest kernels can't work with MMIO windows above 1<<46\n\n * (64TiB), so we place up to 31 PHBs in the area 32TiB..64TiB\n\n *\n\n * 32TiB..(33TiB+1984kiB) contains the 64kiB PIO windows for each\n\n * PHB stacked together. (32TiB+2GiB)..(32TiB+64GiB) contains the\n\n * 2GiB 32-bit MMIO windows for each PHB. Then 33..64TiB has the\n\n * 1TiB 64-bit MMIO windows for each PHB.\n\n */\n\n const uint64_t base_buid = 0x800000020000000ULL;\n\n const int max_phbs =\n\n (SPAPR_PCI_LIMIT - SPAPR_PCI_BASE) / SPAPR_PCI_MEM64_WIN_SIZE - 1;\n\n int i;\n\n\n\n /* Sanity check natural alignments */\n\n QEMU_BUILD_BUG_ON((SPAPR_PCI_BASE % SPAPR_PCI_MEM64_WIN_SIZE) != 0);\n\n QEMU_BUILD_BUG_ON((SPAPR_PCI_LIMIT % SPAPR_PCI_MEM64_WIN_SIZE) != 0);\n\n QEMU_BUILD_BUG_ON((SPAPR_PCI_MEM64_WIN_SIZE % SPAPR_PCI_MEM32_WIN_SIZE) != 0);\n\n QEMU_BUILD_BUG_ON((SPAPR_PCI_MEM32_WIN_SIZE % SPAPR_PCI_IO_WIN_SIZE) != 0);\n\n /* Sanity check bounds */\n\n QEMU_BUILD_BUG_ON((max_phbs * SPAPR_PCI_IO_WIN_SIZE) > SPAPR_PCI_MEM32_WIN_SIZE);\n\n QEMU_BUILD_BUG_ON((max_phbs * SPAPR_PCI_MEM32_WIN_SIZE) > SPAPR_PCI_MEM64_WIN_SIZE);\n\n\n\n if (index >= max_phbs) {\n\n error_setg(errp, \"\\\"index\\\" for PAPR PHB is too large (max %u)\",\n\n max_phbs - 1);\n\n return;\n\n }\n\n\n\n *buid = base_buid + index;\n\n for (i = 0; i < n_dma; ++i) {\n\n liobns[i] = SPAPR_PCI_LIOBN(index, i);\n\n }\n\n\n\n *pio = SPAPR_PCI_BASE + index * SPAPR_PCI_IO_WIN_SIZE;\n\n *mmio32 = SPAPR_PCI_BASE + (index + 1) * SPAPR_PCI_MEM32_WIN_SIZE;\n\n *mmio64 = SPAPR_PCI_BASE + (index + 1) * SPAPR_PCI_MEM64_WIN_SIZE;\n\n}\n", + "output": "1", + "index": 8154 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs)\n\n{\n\n TCGOpcode op;\n\n TCGOpDef *def;\n\n const char *ct_str;\n\n int i, nb_args;\n\n\n\n for(;;) {\n\n if (tdefs->op == (TCGOpcode)-1)\n\n break;\n\n op = tdefs->op;\n\n assert(op >= 0 && op < NB_OPS);\n\n def = &tcg_op_defs[op];\n\n#if defined(CONFIG_DEBUG_TCG)\n\n /* Duplicate entry in op definitions? */\n\n assert(!def->used);\n\n def->used = 1;\n\n#endif\n\n nb_args = def->nb_iargs + def->nb_oargs;\n\n for(i = 0; i < nb_args; i++) {\n\n ct_str = tdefs->args_ct_str[i];\n\n /* Incomplete TCGTargetOpDef entry? */\n\n assert(ct_str != NULL);\n\n tcg_regset_clear(def->args_ct[i].u.regs);\n\n def->args_ct[i].ct = 0;\n\n if (ct_str[0] >= '0' && ct_str[0] <= '9') {\n\n int oarg;\n\n oarg = ct_str[0] - '0';\n\n assert(oarg < def->nb_oargs);\n\n assert(def->args_ct[oarg].ct & TCG_CT_REG);\n\n /* TCG_CT_ALIAS is for the output arguments. The input\n\n argument is tagged with TCG_CT_IALIAS. */\n\n def->args_ct[i] = def->args_ct[oarg];\n\n def->args_ct[oarg].ct = TCG_CT_ALIAS;\n\n def->args_ct[oarg].alias_index = i;\n\n def->args_ct[i].ct |= TCG_CT_IALIAS;\n\n def->args_ct[i].alias_index = oarg;\n\n } else {\n\n for(;;) {\n\n if (*ct_str == '\\0')\n\n break;\n\n switch(*ct_str) {\n\n case 'i':\n\n def->args_ct[i].ct |= TCG_CT_CONST;\n\n ct_str++;\n\n break;\n\n default:\n\n if (target_parse_constraint(&def->args_ct[i], &ct_str) < 0) {\n\n fprintf(stderr, \"Invalid constraint '%s' for arg %d of operation '%s'\\n\",\n\n ct_str, i, def->name);\n\n exit(1);\n\n }\n\n }\n\n }\n\n }\n\n }\n\n\n\n /* TCGTargetOpDef entry with too much information? */\n\n assert(i == TCG_MAX_OP_ARGS || tdefs->args_ct_str[i] == NULL);\n\n\n\n /* sort the constraints (XXX: this is just an heuristic) */\n\n sort_constraints(def, 0, def->nb_oargs);\n\n sort_constraints(def, def->nb_oargs, def->nb_iargs);\n\n\n\n#if 0\n\n {\n\n int i;\n\n\n\n printf(\"%s: sorted=\", def->name);\n\n for(i = 0; i < def->nb_oargs + def->nb_iargs; i++)\n\n printf(\" %d\", def->sorted_args[i]);\n\n printf(\"\\n\");\n\n }\n\n#endif\n\n tdefs++;\n\n }\n\n\n\n#if defined(CONFIG_DEBUG_TCG)\n\n i = 0;\n\n for (op = 0; op < ARRAY_SIZE(tcg_op_defs); op++) {\n\n if (op < INDEX_op_call || op == INDEX_op_debug_insn_start) {\n\n /* Wrong entry in op definitions? */\n\n if (tcg_op_defs[op].used) {\n\n fprintf(stderr, \"Invalid op definition for %s\\n\",\n\n tcg_op_defs[op].name);\n\n i = 1;\n\n }\n\n } else {\n\n /* Missing entry in op definitions? */\n\n if (!tcg_op_defs[op].used) {\n\n fprintf(stderr, \"Missing op definition for %s\\n\",\n\n tcg_op_defs[op].name);\n\n i = 1;\n\n }\n\n }\n\n }\n\n if (i == 1) {\n\n tcg_abort();\n\n }\n\n#endif\n\n}\n", + "output": "1", + "index": 22053 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,\n BlockDriver *drv)\n{\n int ret, open_flags;\n char tmp_filename[PATH_MAX];\n char backing_filename[PATH_MAX];\n bs->read_only = 0;\n bs->is_temporary = 0;\n bs->encrypted = 0;\n if (flags & BDRV_O_SNAPSHOT) {\n BlockDriverState *bs1;\n int64_t total_size;\n /* if snapshot, we create a temporary backing file and open it\n instead of opening 'filename' directly */\n /* if there is a backing file, use it */\n bs1 = bdrv_new(\"\");\n if (!bs1) {\n return -ENOMEM;\n }\n if (bdrv_open(bs1, filename, 0) < 0) {\n bdrv_delete(bs1);\n return -1;\n }\n total_size = bdrv_getlength(bs1) >> SECTOR_BITS;\n bdrv_delete(bs1);\n get_tmp_filename(tmp_filename, sizeof(tmp_filename));\n realpath(filename, backing_filename);\n if (bdrv_create(&bdrv_qcow2, tmp_filename,\n total_size, backing_filename, 0) < 0) {\n return -1;\n }\n filename = tmp_filename;\n bs->is_temporary = 1;\n }\n pstrcpy(bs->filename, sizeof(bs->filename), filename);\n if (flags & BDRV_O_FILE) {\n drv = find_protocol(filename);\n if (!drv)\n return -ENOENT;\n } else {\n if (!drv) {\n drv = find_image_format(filename);\n if (!drv)\n return -1;\n }\n }\n bs->drv = drv;\n bs->opaque = qemu_mallocz(drv->instance_size);\n bs->total_sectors = 0; /* driver will set if it does not do getlength */\n if (bs->opaque == NULL && drv->instance_size > 0)\n return -1;\n /* Note: for compatibility, we open disk image files as RDWR, and\n RDONLY as fallback */\n if (!(flags & BDRV_O_FILE))\n open_flags = BDRV_O_RDWR | (flags & BDRV_O_DIRECT);\n else\n open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);\n ret = drv->bdrv_open(bs, filename, open_flags);\n if (ret == -EACCES && !(flags & BDRV_O_FILE)) {\n ret = drv->bdrv_open(bs, filename, BDRV_O_RDONLY);\n bs->read_only = 1;\n }\n if (ret < 0) {\n qemu_free(bs->opaque);\n bs->opaque = NULL;\n bs->drv = NULL;\n return ret;\n }\n if (drv->bdrv_getlength) {\n bs->total_sectors = bdrv_getlength(bs) >> SECTOR_BITS;\n }\n#ifndef _WIN32\n if (bs->is_temporary) {\n unlink(filename);\n }\n#endif\n if (bs->backing_file[0] != '\\0') {\n /* if there is a backing file, use it */\n bs->backing_hd = bdrv_new(\"\");\n if (!bs->backing_hd) {\n fail:\n bdrv_close(bs);\n return -ENOMEM;\n }\n path_combine(backing_filename, sizeof(backing_filename),\n filename, bs->backing_file);\n if (bdrv_open(bs->backing_hd, backing_filename, 0) < 0)\n goto fail;\n }\n /* call the change callback */\n bs->media_changed = 1;\n if (bs->change_cb)\n bs->change_cb(bs->change_opaque);\n return 0;\n}", + "output": "1", + "index": 2131 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void ppc_tlb_invalidate_one(CPUPPCState *env, target_ulong addr)\n\n{\n\n#if !defined(FLUSH_ALL_TLBS)\n\n PowerPCCPU *cpu = ppc_env_get_cpu(env);\n\n CPUState *cs;\n\n\n\n addr &= TARGET_PAGE_MASK;\n\n switch (env->mmu_model) {\n\n case POWERPC_MMU_SOFT_6xx:\n\n case POWERPC_MMU_SOFT_74xx:\n\n ppc6xx_tlb_invalidate_virt(env, addr, 0);\n\n if (env->id_tlbs == 1) {\n\n ppc6xx_tlb_invalidate_virt(env, addr, 1);\n\n }\n\n break;\n\n case POWERPC_MMU_SOFT_4xx:\n\n case POWERPC_MMU_SOFT_4xx_Z:\n\n ppc4xx_tlb_invalidate_virt(env, addr, env->spr[SPR_40x_PID]);\n\n break;\n\n case POWERPC_MMU_REAL:\n\n cpu_abort(CPU(cpu), \"No TLB for PowerPC 4xx in real mode\\n\");\n\n break;\n\n case POWERPC_MMU_MPC8xx:\n\n /* XXX: TODO */\n\n cpu_abort(CPU(cpu), \"MPC8xx MMU model is not implemented\\n\");\n\n break;\n\n case POWERPC_MMU_BOOKE:\n\n /* XXX: TODO */\n\n cpu_abort(CPU(cpu), \"BookE MMU model is not implemented\\n\");\n\n break;\n\n case POWERPC_MMU_BOOKE206:\n\n /* XXX: TODO */\n\n cpu_abort(CPU(cpu), \"BookE 2.06 MMU model is not implemented\\n\");\n\n break;\n\n case POWERPC_MMU_32B:\n\n case POWERPC_MMU_601:\n\n /* tlbie invalidate TLBs for all segments */\n\n addr &= ~((target_ulong)-1ULL << 28);\n\n cs = CPU(cpu);\n\n /* XXX: this case should be optimized,\n\n * giving a mask to tlb_flush_page\n\n */\n\n tlb_flush_page(cs, addr | (0x0 << 28));\n\n tlb_flush_page(cs, addr | (0x1 << 28));\n\n tlb_flush_page(cs, addr | (0x2 << 28));\n\n tlb_flush_page(cs, addr | (0x3 << 28));\n\n tlb_flush_page(cs, addr | (0x4 << 28));\n\n tlb_flush_page(cs, addr | (0x5 << 28));\n\n tlb_flush_page(cs, addr | (0x6 << 28));\n\n tlb_flush_page(cs, addr | (0x7 << 28));\n\n tlb_flush_page(cs, addr | (0x8 << 28));\n\n tlb_flush_page(cs, addr | (0x9 << 28));\n\n tlb_flush_page(cs, addr | (0xA << 28));\n\n tlb_flush_page(cs, addr | (0xB << 28));\n\n tlb_flush_page(cs, addr | (0xC << 28));\n\n tlb_flush_page(cs, addr | (0xD << 28));\n\n tlb_flush_page(cs, addr | (0xE << 28));\n\n tlb_flush_page(cs, addr | (0xF << 28));\n\n break;\n\n#if defined(TARGET_PPC64)\n\n case POWERPC_MMU_64B:\n\n case POWERPC_MMU_2_03:\n\n case POWERPC_MMU_2_06:\n\n case POWERPC_MMU_2_06a:\n\n case POWERPC_MMU_2_07:\n\n case POWERPC_MMU_2_07a:\n\n /* tlbie invalidate TLBs for all segments */\n\n /* XXX: given the fact that there are too many segments to invalidate,\n\n * and we still don't have a tlb_flush_mask(env, n, mask) in QEMU,\n\n * we just invalidate all TLBs\n\n */\n\n tlb_flush(CPU(cpu), 1);\n\n break;\n\n#endif /* defined(TARGET_PPC64) */\n\n default:\n\n /* XXX: TODO */\n\n cpu_abort(CPU(cpu), \"Unknown MMU model\\n\");\n\n break;\n\n }\n\n#else\n\n ppc_tlb_invalidate_all(env);\n\n#endif\n\n}\n", + "output": "0", + "index": 2067 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int seek_frame_generic(AVFormatContext *s,\n\n int stream_index, int64_t timestamp, int flags)\n\n{\n\n int index;\n\n int64_t ret;\n\n AVStream *st;\n\n AVIndexEntry *ie;\n\n\n\n st = s->streams[stream_index];\n\n\n\n index = av_index_search_timestamp(st, timestamp, flags);\n\n\n\n if(index < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp)\n\n return -1;\n\n\n\n if(index < 0 || index==st->nb_index_entries-1){\n\n AVPacket pkt;\n\n int nonkey=0;\n\n\n\n if(st->nb_index_entries){\n\n assert(st->index_entries);\n\n ie= &st->index_entries[st->nb_index_entries-1];\n\n if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)\n\n return ret;\n\n ff_update_cur_dts(s, st, ie->timestamp);\n\n }else{\n\n if ((ret = avio_seek(s->pb, s->data_offset, SEEK_SET)) < 0)\n\n return ret;\n\n }\n\n for (;;) {\n\n int read_status;\n\n do{\n\n read_status = av_read_frame(s, &pkt);\n\n } while (read_status == AVERROR(EAGAIN));\n\n if (read_status < 0)\n\n break;\n\n av_free_packet(&pkt);\n\n if(stream_index == pkt.stream_index && pkt.dts > timestamp){\n\n if(pkt.flags & AV_PKT_FLAG_KEY)\n\n break;\n\n if(nonkey++ > 1000){\n\n av_log(s, AV_LOG_ERROR,\"seek_frame_generic failed as this stream seems to contain no keyframes after the target timestamp, %d non keyframes found\\n\", nonkey);\n\n break;\n\n }\n\n }\n\n }\n\n index = av_index_search_timestamp(st, timestamp, flags);\n\n }\n\n if (index < 0)\n\n return -1;\n\n\n\n ff_read_frame_flush(s);\n\n AV_NOWARN_DEPRECATED(\n\n if (s->iformat->read_seek){\n\n if(s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0)\n\n return 0;\n\n }\n\n )\n\n ie = &st->index_entries[index];\n\n if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)\n\n return ret;\n\n ff_update_cur_dts(s, st, ie->timestamp);\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 21497 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "av_cold int ff_h264_decode_init(AVCodecContext *avctx)\n\n{\n\n H264Context *h = avctx->priv_data;\n\n int i;\n\n int ret;\n\n\n\n h->avctx = avctx;\n\n\n\n h->bit_depth_luma = 8;\n\n h->chroma_format_idc = 1;\n\n\n\n h->cur_chroma_format_idc = 1;\n\n\n\n ff_h264dsp_init(&h->h264dsp, 8, 1);\n\n av_assert0(h->sps.bit_depth_chroma == 0);\n\n ff_h264chroma_init(&h->h264chroma, h->sps.bit_depth_chroma);\n\n ff_h264qpel_init(&h->h264qpel, 8);\n\n ff_h264_pred_init(&h->hpc, h->avctx->codec_id, 8, 1);\n\n\n\n h->dequant_coeff_pps = -1;\n\n h->current_sps_id = -1;\n\n\n\n /* needed so that IDCT permutation is known early */\n\n ff_videodsp_init(&h->vdsp, 8);\n\n\n\n memset(h->pps.scaling_matrix4, 16, 6 * 16 * sizeof(uint8_t));\n\n memset(h->pps.scaling_matrix8, 16, 2 * 64 * sizeof(uint8_t));\n\n\n\n h->picture_structure = PICT_FRAME;\n\n h->slice_context_count = 1;\n\n h->workaround_bugs = avctx->workaround_bugs;\n\n h->flags = avctx->flags;\n\n\n\n /* set defaults */\n\n // s->decode_mb = ff_h263_decode_mb;\n\n if (!avctx->has_b_frames)\n\n h->low_delay = 1;\n\n\n\n avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;\n\n\n\n ff_h264_decode_init_vlc();\n\n\n\n ff_init_cabac_states();\n\n\n\n h->pixel_shift = 0;\n\n h->cur_bit_depth_luma =\n\n h->sps.bit_depth_luma = avctx->bits_per_raw_sample = 8;\n\n\n\n h->nb_slice_ctx = (avctx->active_thread_type & FF_THREAD_SLICE) ? H264_MAX_THREADS : 1;\n\n h->slice_ctx = av_mallocz_array(h->nb_slice_ctx, sizeof(*h->slice_ctx));\n\n if (!h->slice_ctx) {\n\n h->nb_slice_ctx = 0;\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n for (i = 0; i < h->nb_slice_ctx; i++)\n\n h->slice_ctx[i].h264 = h;\n\n\n\n h->outputed_poc = h->next_outputed_poc = INT_MIN;\n\n for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)\n\n h->last_pocs[i] = INT_MIN;\n\n h->prev_poc_msb = 1 << 16;\n\n h->prev_frame_num = -1;\n\n h->x264_build = -1;\n\n h->sei_fpa.frame_packing_arrangement_cancel_flag = -1;\n\n ff_h264_reset_sei(h);\n\n if (avctx->codec_id == AV_CODEC_ID_H264) {\n\n if (avctx->ticks_per_frame == 1) {\n\n if(h->avctx->time_base.den < INT_MAX/2) {\n\n h->avctx->time_base.den *= 2;\n\n } else\n\n h->avctx->time_base.num /= 2;\n\n }\n\n avctx->ticks_per_frame = 2;\n\n }\n\n\n\n if (avctx->extradata_size > 0 && avctx->extradata) {\n\n ret = ff_h264_decode_extradata(h, avctx->extradata, avctx->extradata_size);\n\n if (ret < 0) {\n\n ff_h264_free_context(h);\n\n return ret;\n\n }\n\n }\n\n\n\n if (h->sps.bitstream_restriction_flag &&\n\n h->avctx->has_b_frames < h->sps.num_reorder_frames) {\n\n h->avctx->has_b_frames = h->sps.num_reorder_frames;\n\n h->low_delay = 0;\n\n }\n\n\n\n avctx->internal->allocate_progress = 1;\n\n\n\n ff_h264_flush_change(h);\n\n\n\n if (h->enable_er) {\n\n av_log(avctx, AV_LOG_WARNING,\n\n \"Error resilience is enabled. It is unsafe and unsupported and may crash. \"\n\n \"Use it at your own risk\\n\");\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 21926 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void init_excp_POWER7 (CPUPPCState *env)\n\n{\n\n#if !defined(CONFIG_USER_ONLY)\n\n env->excp_vectors[POWERPC_EXCP_RESET] = 0x00000100;\n\n env->excp_vectors[POWERPC_EXCP_MCHECK] = 0x00000200;\n\n env->excp_vectors[POWERPC_EXCP_DSI] = 0x00000300;\n\n env->excp_vectors[POWERPC_EXCP_DSEG] = 0x00000380;\n\n env->excp_vectors[POWERPC_EXCP_ISI] = 0x00000400;\n\n env->excp_vectors[POWERPC_EXCP_ISEG] = 0x00000480;\n\n env->excp_vectors[POWERPC_EXCP_EXTERNAL] = 0x00000500;\n\n env->excp_vectors[POWERPC_EXCP_ALIGN] = 0x00000600;\n\n env->excp_vectors[POWERPC_EXCP_PROGRAM] = 0x00000700;\n\n env->excp_vectors[POWERPC_EXCP_FPU] = 0x00000800;\n\n env->excp_vectors[POWERPC_EXCP_DECR] = 0x00000900;\n\n env->excp_vectors[POWERPC_EXCP_HDECR] = 0x00000980;\n\n env->excp_vectors[POWERPC_EXCP_SYSCALL] = 0x00000C00;\n\n env->excp_vectors[POWERPC_EXCP_TRACE] = 0x00000D00;\n\n env->excp_vectors[POWERPC_EXCP_PERFM] = 0x00000F00;\n\n env->excp_vectors[POWERPC_EXCP_VPU] = 0x00000F20;\n\n env->excp_vectors[POWERPC_EXCP_VSXU] = 0x00000F40;\n\n env->excp_vectors[POWERPC_EXCP_FU] = 0x00000F60;\n\n env->excp_vectors[POWERPC_EXCP_IABR] = 0x00001300;\n\n env->excp_vectors[POWERPC_EXCP_MAINT] = 0x00001600;\n\n env->excp_vectors[POWERPC_EXCP_VPUA] = 0x00001700;\n\n env->excp_vectors[POWERPC_EXCP_THERM] = 0x00001800;\n\n /* Hardware reset vector */\n\n env->hreset_vector = 0x0000000000000100ULL;\n\n#endif\n\n}\n", + "output": "1", + "index": 22640 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)\n\n{\n\n CPUM68KState *env = cs->env_ptr;\n\n DisasContext dc1, *dc = &dc1;\n\n target_ulong pc_start;\n\n int pc_offset;\n\n int num_insns;\n\n int max_insns;\n\n\n\n /* generate intermediate code */\n\n pc_start = tb->pc;\n\n\n\n dc->tb = tb;\n\n\n\n dc->env = env;\n\n dc->is_jmp = DISAS_NEXT;\n\n dc->pc = pc_start;\n\n dc->cc_op = CC_OP_DYNAMIC;\n\n dc->cc_op_synced = 1;\n\n dc->singlestep_enabled = cs->singlestep_enabled;\n\n dc->user = (env->sr & SR_S) == 0;\n\n dc->done_mac = 0;\n\n dc->writeback_mask = 0;\n\n num_insns = 0;\n\n max_insns = tb->cflags & CF_COUNT_MASK;\n\n if (max_insns == 0) {\n\n max_insns = CF_COUNT_MASK;\n\n }\n\n if (max_insns > TCG_MAX_INSNS) {\n\n max_insns = TCG_MAX_INSNS;\n\n }\n\n\n\n gen_tb_start(tb);\n\n do {\n\n pc_offset = dc->pc - pc_start;\n\n gen_throws_exception = NULL;\n\n tcg_gen_insn_start(dc->pc, dc->cc_op);\n\n num_insns++;\n\n\n\n if (unlikely(cpu_breakpoint_test(cs, dc->pc, BP_ANY))) {\n\n gen_exception(dc, dc->pc, EXCP_DEBUG);\n\n dc->is_jmp = DISAS_JUMP;\n\n /* The address covered by the breakpoint must be included in\n\n [tb->pc, tb->pc + tb->size) in order to for it to be\n\n properly cleared -- thus we increment the PC here so that\n\n the logic setting tb->size below does the right thing. */\n\n dc->pc += 2;\n\n break;\n\n }\n\n\n\n if (num_insns == max_insns && (tb->cflags & CF_LAST_IO)) {\n\n gen_io_start();\n\n }\n\n\n\n dc->insn_pc = dc->pc;\n\n\tdisas_m68k_insn(env, dc);\n\n } while (!dc->is_jmp && !tcg_op_buf_full() &&\n\n !cs->singlestep_enabled &&\n\n !singlestep &&\n\n (pc_offset) < (TARGET_PAGE_SIZE - 32) &&\n\n num_insns < max_insns);\n\n\n\n if (tb->cflags & CF_LAST_IO)\n\n gen_io_end();\n\n if (unlikely(cs->singlestep_enabled)) {\n\n /* Make sure the pc is updated, and raise a debug exception. */\n\n if (!dc->is_jmp) {\n\n update_cc_op(dc);\n\n tcg_gen_movi_i32(QREG_PC, dc->pc);\n\n }\n\n gen_helper_raise_exception(cpu_env, tcg_const_i32(EXCP_DEBUG));\n\n } else {\n\n switch(dc->is_jmp) {\n\n case DISAS_NEXT:\n\n update_cc_op(dc);\n\n gen_jmp_tb(dc, 0, dc->pc);\n\n break;\n\n default:\n\n case DISAS_JUMP:\n\n case DISAS_UPDATE:\n\n update_cc_op(dc);\n\n /* indicate that the hash table must be used to find the next TB */\n\n tcg_gen_exit_tb(0);\n\n break;\n\n case DISAS_TB_JUMP:\n\n /* nothing more to generate */\n\n break;\n\n }\n\n }\n\n gen_tb_end(tb, num_insns);\n\n\n\n#ifdef DEBUG_DISAS\n\n if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)\n\n && qemu_log_in_addr_range(pc_start)) {\n\n qemu_log_lock();\n\n qemu_log(\"----------------\\n\");\n\n qemu_log(\"IN: %s\\n\", lookup_symbol(pc_start));\n\n log_target_disas(cs, pc_start, dc->pc - pc_start, 0);\n\n qemu_log(\"\\n\");\n\n qemu_log_unlock();\n\n }\n\n#endif\n\n tb->size = dc->pc - pc_start;\n\n tb->icount = num_insns;\n\n}\n", + "output": "1", + "index": 1278 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size)\n\n{\n\n const uint16_t *end;\n\n#if COMPILE_TEMPLATE_MMX\n\n const uint16_t *mm_end;\n\n#endif\n\n uint8_t *d = dst;\n\n const uint16_t *s = (const uint16_t*)src;\n\n end = s + src_size/2;\n\n#if COMPILE_TEMPLATE_MMX\n\n __asm__ volatile(PREFETCH\" %0\"::\"m\"(*s):\"memory\");\n\n __asm__ volatile(\"pxor %%mm7,%%mm7 \\n\\t\":::\"memory\");\n\n __asm__ volatile(\"pcmpeqd %%mm6,%%mm6 \\n\\t\":::\"memory\");\n\n mm_end = end - 3;\n\n while (s < mm_end) {\n\n __asm__ volatile(\n\n PREFETCH\" 32%1 \\n\\t\"\n\n \"movq %1, %%mm0 \\n\\t\"\n\n \"movq %1, %%mm1 \\n\\t\"\n\n \"movq %1, %%mm2 \\n\\t\"\n\n \"pand %2, %%mm0 \\n\\t\"\n\n \"pand %3, %%mm1 \\n\\t\"\n\n \"pand %4, %%mm2 \\n\\t\"\n\n \"psllq $3, %%mm0 \\n\\t\"\n\n \"psrlq $3, %%mm1 \\n\\t\"\n\n \"psrlq $8, %%mm2 \\n\\t\"\n\n PACK_RGB32\n\n :\"=m\"(*d)\n\n :\"m\"(*s),\"m\"(mask16b),\"m\"(mask16g),\"m\"(mask16r)\n\n :\"memory\");\n\n d += 16;\n\n s += 4;\n\n }\n\n __asm__ volatile(SFENCE:::\"memory\");\n\n __asm__ volatile(EMMS:::\"memory\");\n\n#endif\n\n while (s < end) {\n\n register uint16_t bgr;\n\n bgr = *s++;\n\n#if HAVE_BIGENDIAN\n\n *d++ = 255;\n\n *d++ = (bgr&0xF800)>>8;\n\n *d++ = (bgr&0x7E0)>>3;\n\n *d++ = (bgr&0x1F)<<3;\n\n#else\n\n *d++ = (bgr&0x1F)<<3;\n\n *d++ = (bgr&0x7E0)>>3;\n\n *d++ = (bgr&0xF800)>>8;\n\n *d++ = 255;\n\n#endif\n\n }\n\n}\n", + "output": "0", + "index": 995 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,\n\n void *opaque, QJSON *vmdesc)\n\n{\n\n VMStateField *field = vmsd->fields;\n\n\n\n trace_vmstate_save_state_top(vmsd->name);\n\n\n\n if (vmsd->pre_save) {\n\n vmsd->pre_save(opaque);\n\n }\n\n\n\n if (vmdesc) {\n\n json_prop_str(vmdesc, \"vmsd_name\", vmsd->name);\n\n json_prop_int(vmdesc, \"version\", vmsd->version_id);\n\n json_start_array(vmdesc, \"fields\");\n\n }\n\n\n\n while (field->name) {\n\n if (!field->field_exists ||\n\n field->field_exists(opaque, vmsd->version_id)) {\n\n void *first_elem = opaque + field->offset;\n\n int i, n_elems = vmstate_n_elems(opaque, field);\n\n int size = vmstate_size(opaque, field);\n\n int64_t old_offset, written_bytes;\n\n QJSON *vmdesc_loop = vmdesc;\n\n\n\n trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems);\n\n if (field->flags & VMS_POINTER) {\n\n first_elem = *(void **)first_elem;\n\n assert(first_elem || !n_elems);\n\n }\n\n for (i = 0; i < n_elems; i++) {\n\n void *curr_elem = first_elem + size * i;\n\n\n\n vmsd_desc_field_start(vmsd, vmdesc_loop, field, i, n_elems);\n\n old_offset = qemu_ftell_fast(f);\n\n if (field->flags & VMS_ARRAY_OF_POINTER) {\n\n assert(curr_elem);\n\n curr_elem = *(void **)curr_elem;\n\n }\n\n if (field->flags & VMS_STRUCT) {\n\n vmstate_save_state(f, field->vmsd, curr_elem, vmdesc_loop);\n\n } else {\n\n field->info->put(f, curr_elem, size, field, vmdesc_loop);\n\n }\n\n\n\n written_bytes = qemu_ftell_fast(f) - old_offset;\n\n vmsd_desc_field_end(vmsd, vmdesc_loop, field, written_bytes, i);\n\n\n\n /* Compressed arrays only care about the first element */\n\n if (vmdesc_loop && vmsd_can_compress(field)) {\n\n vmdesc_loop = NULL;\n\n }\n\n }\n\n } else {\n\n if (field->flags & VMS_MUST_EXIST) {\n\n error_report(\"Output state validation failed: %s/%s\",\n\n vmsd->name, field->name);\n\n assert(!(field->flags & VMS_MUST_EXIST));\n\n }\n\n }\n\n field++;\n\n }\n\n\n\n if (vmdesc) {\n\n json_end_array(vmdesc);\n\n }\n\n\n\n vmstate_subsection_save(f, vmsd, opaque, vmdesc);\n\n}\n", + "output": "1", + "index": 24960 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void virtio_gpu_set_scanout(VirtIOGPU *g,\n\n struct virtio_gpu_ctrl_command *cmd)\n\n{\n\n struct virtio_gpu_simple_resource *res;\n\n struct virtio_gpu_scanout *scanout;\n\n pixman_format_code_t format;\n\n uint32_t offset;\n\n int bpp;\n\n struct virtio_gpu_set_scanout ss;\n\n\n\n VIRTIO_GPU_FILL_CMD(ss);\n\n trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id,\n\n ss.r.width, ss.r.height, ss.r.x, ss.r.y);\n\n\n\n if (ss.scanout_id >= g->conf.max_outputs) {\n\n qemu_log_mask(LOG_GUEST_ERROR, \"%s: illegal scanout id specified %d\",\n\n __func__, ss.scanout_id);\n\n cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID;\n\n return;\n\n }\n\n\n\n g->enable = 1;\n\n if (ss.resource_id == 0) {\n\n scanout = &g->scanout[ss.scanout_id];\n\n if (scanout->resource_id) {\n\n res = virtio_gpu_find_resource(g, scanout->resource_id);\n\n if (res) {\n\n res->scanout_bitmask &= ~(1 << ss.scanout_id);\n\n }\n\n }\n\n if (ss.scanout_id == 0) {\n\n qemu_log_mask(LOG_GUEST_ERROR,\n\n \"%s: illegal scanout id specified %d\",\n\n __func__, ss.scanout_id);\n\n cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID;\n\n return;\n\n }\n\n dpy_gfx_replace_surface(g->scanout[ss.scanout_id].con, NULL);\n\n scanout->ds = NULL;\n\n scanout->width = 0;\n\n scanout->height = 0;\n\n return;\n\n }\n\n\n\n /* create a surface for this scanout */\n\n res = virtio_gpu_find_resource(g, ss.resource_id);\n\n if (!res) {\n\n qemu_log_mask(LOG_GUEST_ERROR, \"%s: illegal resource specified %d\\n\",\n\n __func__, ss.resource_id);\n\n cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;\n\n return;\n\n }\n\n\n\n if (ss.r.x > res->width ||\n\n ss.r.y > res->height ||\n\n ss.r.width > res->width ||\n\n ss.r.height > res->height ||\n\n ss.r.x + ss.r.width > res->width ||\n\n ss.r.y + ss.r.height > res->height) {\n\n qemu_log_mask(LOG_GUEST_ERROR, \"%s: illegal scanout %d bounds for\"\n\n \" resource %d, (%d,%d)+%d,%d vs %d %d\\n\",\n\n __func__, ss.scanout_id, ss.resource_id, ss.r.x, ss.r.y,\n\n ss.r.width, ss.r.height, res->width, res->height);\n\n cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;\n\n return;\n\n }\n\n\n\n scanout = &g->scanout[ss.scanout_id];\n\n\n\n format = pixman_image_get_format(res->image);\n\n bpp = (PIXMAN_FORMAT_BPP(format) + 7) / 8;\n\n offset = (ss.r.x * bpp) + ss.r.y * pixman_image_get_stride(res->image);\n\n if (!scanout->ds || surface_data(scanout->ds)\n\n != ((uint8_t *)pixman_image_get_data(res->image) + offset) ||\n\n scanout->width != ss.r.width ||\n\n scanout->height != ss.r.height) {\n\n pixman_image_t *rect;\n\n void *ptr = (uint8_t *)pixman_image_get_data(res->image) + offset;\n\n rect = pixman_image_create_bits(format, ss.r.width, ss.r.height, ptr,\n\n pixman_image_get_stride(res->image));\n\n pixman_image_ref(res->image);\n\n pixman_image_set_destroy_function(rect, virtio_unref_resource,\n\n res->image);\n\n /* realloc the surface ptr */\n\n scanout->ds = qemu_create_displaysurface_pixman(rect);\n\n if (!scanout->ds) {\n\n cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;\n\n return;\n\n }\n\n\n dpy_gfx_replace_surface(g->scanout[ss.scanout_id].con, scanout->ds);\n\n }\n\n\n\n res->scanout_bitmask |= (1 << ss.scanout_id);\n\n scanout->resource_id = ss.resource_id;\n\n scanout->x = ss.r.x;\n\n scanout->y = ss.r.y;\n\n scanout->width = ss.r.width;\n\n scanout->height = ss.r.height;\n\n}", + "output": "1", + "index": 21243 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_frame_thread_init(AVCodecContext *avctx)\n\n{\n\n int thread_count = avctx->thread_count;\n\n const AVCodec *codec = avctx->codec;\n\n AVCodecContext *src = avctx;\n\n FrameThreadContext *fctx;\n\n int i, err = 0;\n\n\n\n#if HAVE_W32THREADS\n\n w32thread_init();\n\n#endif\n\n\n\n if (!thread_count) {\n\n int nb_cpus = av_cpu_count();\n\n av_log(avctx, AV_LOG_DEBUG, \"detected %d logical cores\\n\", nb_cpus);\n\n // use number of cores + 1 as thread count if there is more than one\n\n if (nb_cpus > 1)\n\n thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);\n\n else\n\n thread_count = avctx->thread_count = 1;\n\n }\n\n\n\n if (thread_count <= 1) {\n\n avctx->active_thread_type = 0;\n\n return 0;\n\n }\n\n\n\n avctx->internal->thread_ctx = fctx = av_mallocz(sizeof(FrameThreadContext));\n\n\n\n fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count);\n\n pthread_mutex_init(&fctx->buffer_mutex, NULL);\n\n fctx->delaying = 1;\n\n\n\n for (i = 0; i < thread_count; i++) {\n\n AVCodecContext *copy = av_malloc(sizeof(AVCodecContext));\n\n PerThreadContext *p = &fctx->threads[i];\n\n\n\n pthread_mutex_init(&p->mutex, NULL);\n\n pthread_mutex_init(&p->progress_mutex, NULL);\n\n pthread_cond_init(&p->input_cond, NULL);\n\n pthread_cond_init(&p->progress_cond, NULL);\n\n pthread_cond_init(&p->output_cond, NULL);\n\n\n\n p->frame = av_frame_alloc();\n\n if (!p->frame) {\n\n\n err = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n\n\n p->parent = fctx;\n\n p->avctx = copy;\n\n\n\n if (!copy) {\n\n err = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n\n\n *copy = *src;\n\n\n\n copy->internal = av_malloc(sizeof(AVCodecInternal));\n\n if (!copy->internal) {\n\n err = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n *copy->internal = *src->internal;\n\n copy->internal->thread_ctx = p;\n\n copy->internal->pkt = &p->avpkt;\n\n\n\n if (!i) {\n\n src = copy;\n\n\n\n if (codec->init)\n\n err = codec->init(copy);\n\n\n\n update_context_from_thread(avctx, copy, 1);\n\n } else {\n\n copy->priv_data = av_malloc(codec->priv_data_size);\n\n if (!copy->priv_data) {\n\n err = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n memcpy(copy->priv_data, src->priv_data, codec->priv_data_size);\n\n copy->internal->is_copy = 1;\n\n\n\n if (codec->init_thread_copy)\n\n err = codec->init_thread_copy(copy);\n\n }\n\n\n\n if (err) goto error;\n\n\n\n if (!pthread_create(&p->thread, NULL, frame_worker_thread, p))\n\n p->thread_init = 1;\n\n }\n\n\n\n return 0;\n\n\n\nerror:\n\n ff_frame_thread_free(avctx, i+1);\n\n\n\n return err;\n\n}", + "output": "1", + "index": 1465 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void compute_default_clut(AVSubtitleRect *rect, int w, int h)\n\n{\n\n uint8_t list[256] = {0};\n\n uint8_t list_inv[256];\n\n int counttab[256] = {0};\n\n int count, i, x, y;\n\n\n\n#define V(x,y) rect->data[0][(x) + (y)*rect->linesize[0]]\n\n for (y = 0; ydata[0][(x) + (y)*rect->linesize[0]] ]\n\n\n\n for (i = 0; i<256; i++) {\n\n int scoretab[256] = {0};\n\n int bestscore = 0;\n\n int bestv = 0;\n\n for (y = 0; ydata[0][x + y*rect->linesize[0]];\n\n int l_m = list[v];\n\n int l_l = x ? L(x-1, y) : 1;\n\n int l_r = x+1 bestscore) {\n\n bestscore = score;\n\n bestv = v;\n\n }\n\n }\n\n }\n\n if (!bestscore)\n\n break;\n\n list [ bestv ] = 1;\n\n list_inv[ i ] = bestv;\n\n }\n\n\n\n count = FFMAX(i - 1, 1);\n\n for (i--; i>=0; i--) {\n\n int v = i*255/count;\n\n AV_WN32(rect->data[1] + 4*list_inv[i], RGBA(v/2,v,v/2,v));\n\n }\n\n}\n", + "output": "0", + "index": 12103 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void musicpal_init(ram_addr_t ram_size, int vga_ram_size,\n\n const char *boot_device, DisplayState *ds,\n\n const char *kernel_filename, const char *kernel_cmdline,\n\n const char *initrd_filename, const char *cpu_model)\n\n{\n\n CPUState *env;\n\n qemu_irq *pic;\n\n int index;\n\n int iomemtype;\n\n unsigned long flash_size;\n\n\n\n if (!cpu_model)\n\n cpu_model = \"arm926\";\n\n\n\n env = cpu_init(cpu_model);\n\n if (!env) {\n\n fprintf(stderr, \"Unable to find CPU definition\\n\");\n\n exit(1);\n\n }\n\n pic = arm_pic_init_cpu(env);\n\n\n\n /* For now we use a fixed - the original - RAM size */\n\n cpu_register_physical_memory(0, MP_RAM_DEFAULT_SIZE,\n\n qemu_ram_alloc(MP_RAM_DEFAULT_SIZE));\n\n\n\n sram_off = qemu_ram_alloc(MP_SRAM_SIZE);\n\n cpu_register_physical_memory(MP_SRAM_BASE, MP_SRAM_SIZE, sram_off);\n\n\n\n /* Catch various stuff not handled by separate subsystems */\n\n iomemtype = cpu_register_io_memory(0, musicpal_readfn,\n\n musicpal_writefn, env);\n\n cpu_register_physical_memory(0x80000000, 0x10000, iomemtype);\n\n\n\n pic = mv88w8618_pic_init(MP_PIC_BASE, pic[ARM_PIC_CPU_IRQ]);\n\n mv88w8618_pit_init(MP_PIT_BASE, pic, MP_TIMER1_IRQ);\n\n\n\n if (serial_hds[0])\n\n serial_mm_init(MP_UART1_BASE, 2, pic[MP_UART1_IRQ], 1825000,\n\n serial_hds[0], 1);\n\n if (serial_hds[1])\n\n serial_mm_init(MP_UART2_BASE, 2, pic[MP_UART2_IRQ], 1825000,\n\n serial_hds[1], 1);\n\n\n\n /* Register flash */\n\n index = drive_get_index(IF_PFLASH, 0, 0);\n\n if (index != -1) {\n\n flash_size = bdrv_getlength(drives_table[index].bdrv);\n\n if (flash_size != 8*1024*1024 && flash_size != 16*1024*1024 &&\n\n flash_size != 32*1024*1024) {\n\n fprintf(stderr, \"Invalid flash image size\\n\");\n\n exit(1);\n\n }\n\n\n\n /*\n\n * The original U-Boot accesses the flash at 0xFE000000 instead of\n\n * 0xFF800000 (if there is 8 MB flash). So remap flash access if the\n\n * image is smaller than 32 MB.\n\n */\n\n pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(flash_size),\n\n drives_table[index].bdrv, 0x10000,\n\n (flash_size + 0xffff) >> 16,\n\n MP_FLASH_SIZE_MAX / flash_size,\n\n 2, 0x00BF, 0x236D, 0x0000, 0x0000,\n\n 0x5555, 0x2AAA);\n\n }\n\n mv88w8618_flashcfg_init(MP_FLASHCFG_BASE);\n\n\n\n musicpal_lcd_init(ds, MP_LCD_BASE);\n\n\n\n qemu_add_kbd_event_handler(musicpal_key_event, pic[MP_GPIO_IRQ]);\n\n\n\n /*\n\n * Wait a bit to catch menu button during U-Boot start-up\n\n * (to trigger emergency update).\n\n */\n\n sleep(1);\n\n\n\n mv88w8618_eth_init(&nd_table[0], MP_ETH_BASE, pic[MP_ETH_IRQ]);\n\n\n\n mixer_i2c = musicpal_audio_init(MP_AUDIO_BASE, pic[MP_AUDIO_IRQ]);\n\n\n\n musicpal_binfo.ram_size = MP_RAM_DEFAULT_SIZE;\n\n musicpal_binfo.kernel_filename = kernel_filename;\n\n musicpal_binfo.kernel_cmdline = kernel_cmdline;\n\n musicpal_binfo.initrd_filename = initrd_filename;\n\n arm_load_kernel(env, &musicpal_binfo);\n\n}\n", + "output": "0", + "index": 20739 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)\n\n{\n\n int frame_size_code;\n\n\n\n memset(hdr, 0, sizeof(*hdr));\n\n\n\n hdr->sync_word = get_bits(gbc, 16);\n\n if(hdr->sync_word != 0x0B77)\n\n return AAC_AC3_PARSE_ERROR_SYNC;\n\n\n\n /* read ahead to bsid to distinguish between AC-3 and E-AC-3 */\n\n hdr->bitstream_id = show_bits_long(gbc, 29) & 0x1F;\n\n if(hdr->bitstream_id > 16)\n\n return AAC_AC3_PARSE_ERROR_BSID;\n\n\n\n hdr->num_blocks = 6;\n\n\n\n /* set default mix levels */\n\n hdr->center_mix_level = 1; // -4.5dB\n\n hdr->surround_mix_level = 1; // -6.0dB\n\n\n\n if(hdr->bitstream_id <= 10) {\n\n /* Normal AC-3 */\n\n hdr->crc1 = get_bits(gbc, 16);\n\n hdr->sr_code = get_bits(gbc, 2);\n\n if(hdr->sr_code == 3)\n\n return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;\n\n\n\n frame_size_code = get_bits(gbc, 6);\n\n if(frame_size_code > 37)\n\n return AAC_AC3_PARSE_ERROR_FRAME_SIZE;\n\n\n\n skip_bits(gbc, 5); // skip bsid, already got it\n\n\n\n hdr->bitstream_mode = get_bits(gbc, 3);\n\n hdr->channel_mode = get_bits(gbc, 3);\n\n\n\n if(hdr->channel_mode == AC3_CHMODE_STEREO) {\n\n skip_bits(gbc, 2); // skip dsurmod\n\n } else {\n\n if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO)\n\n hdr->center_mix_level = get_bits(gbc, 2);\n\n if(hdr->channel_mode & 4)\n\n hdr->surround_mix_level = get_bits(gbc, 2);\n\n }\n\n hdr->lfe_on = get_bits1(gbc);\n\n\n\n hdr->sr_shift = FFMAX(hdr->bitstream_id, 8) - 8;\n\n hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >> hdr->sr_shift;\n\n hdr->bit_rate = (ff_ac3_bitrate_tab[frame_size_code>>1] * 1000) >> hdr->sr_shift;\n\n hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on;\n\n hdr->frame_size = ff_ac3_frame_size_tab[frame_size_code][hdr->sr_code] * 2;\n\n hdr->frame_type = EAC3_FRAME_TYPE_AC3_CONVERT; //EAC3_FRAME_TYPE_INDEPENDENT;\n\n hdr->substreamid = 0;\n\n } else {\n\n /* Enhanced AC-3 */\n\n hdr->crc1 = 0;\n\n hdr->frame_type = get_bits(gbc, 2);\n\n if(hdr->frame_type == EAC3_FRAME_TYPE_RESERVED)\n\n return AAC_AC3_PARSE_ERROR_FRAME_TYPE;\n\n\n\n hdr->substreamid = get_bits(gbc, 3);\n\n\n\n hdr->frame_size = (get_bits(gbc, 11) + 1) << 1;\n\n if(hdr->frame_size < AC3_HEADER_SIZE)\n\n return AAC_AC3_PARSE_ERROR_FRAME_SIZE;\n\n\n\n hdr->sr_code = get_bits(gbc, 2);\n\n if (hdr->sr_code == 3) {\n\n int sr_code2 = get_bits(gbc, 2);\n\n if(sr_code2 == 3)\n\n return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;\n\n hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2;\n\n hdr->sr_shift = 1;\n\n } else {\n\n hdr->num_blocks = eac3_blocks[get_bits(gbc, 2)];\n\n hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code];\n\n hdr->sr_shift = 0;\n\n }\n\n\n\n hdr->channel_mode = get_bits(gbc, 3);\n\n hdr->lfe_on = get_bits1(gbc);\n\n\n\n hdr->bit_rate = (uint32_t)(8.0 * hdr->frame_size * hdr->sample_rate /\n\n (hdr->num_blocks * 256.0));\n\n hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on;\n\n }\n\n hdr->channel_layout = ff_ac3_channel_layout_tab[hdr->channel_mode];\n\n if (hdr->lfe_on)\n\n hdr->channel_layout |= AV_CH_LOW_FREQUENCY;\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 2610 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,\n\n int n_start, int n_end, int *num, uint64_t *host_offset, QCowL2Meta **m)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n uint64_t start, remaining;\n\n uint64_t cluster_offset;\n\n uint64_t cur_bytes;\n\n int ret;\n\n\n\n trace_qcow2_alloc_clusters_offset(qemu_coroutine_self(), offset,\n\n n_start, n_end);\n\n\n\n assert(n_start * BDRV_SECTOR_SIZE == offset_into_cluster(s, offset));\n\n offset = start_of_cluster(s, offset);\n\n\n\nagain:\n\n start = offset + (n_start << BDRV_SECTOR_BITS);\n\n remaining = (n_end - n_start) << BDRV_SECTOR_BITS;\n\n cluster_offset = 0;\n\n *host_offset = 0;\n\n\n\n /*\n\n * Now start gathering as many contiguous clusters as possible:\n\n *\n\n * 1. Check for overlaps with in-flight allocations\n\n *\n\n * a) Overlap not in the first cluster -> shorten this request and let\n\n * the caller handle the rest in its next loop iteration.\n\n *\n\n * b) Real overlaps of two requests. Yield and restart the search for\n\n * contiguous clusters (the situation could have changed while we\n\n * were sleeping)\n\n *\n\n * c) TODO: Request starts in the same cluster as the in-flight\n\n * allocation ends. Shorten the COW of the in-fight allocation, set\n\n * cluster_offset to write to the same cluster and set up the right\n\n * synchronisation between the in-flight request and the new one.\n\n */\n\n cur_bytes = remaining;\n\n ret = handle_dependencies(bs, start, &cur_bytes);\n\n if (ret == -EAGAIN) {\n\n goto again;\n\n } else if (ret < 0) {\n\n return ret;\n\n } else {\n\n /* handle_dependencies() may have decreased cur_bytes (shortened\n\n * the allocations below) so that the next dependency is processed\n\n * correctly during the next loop iteration. */\n\n }\n\n\n\n /*\n\n * 2. Count contiguous COPIED clusters.\n\n */\n\n ret = handle_copied(bs, start, &cluster_offset, &cur_bytes, m);\n\n if (ret < 0) {\n\n return ret;\n\n } else if (ret) {\n\n if (!*host_offset) {\n\n *host_offset = start_of_cluster(s, cluster_offset);\n\n }\n\n\n\n start += cur_bytes;\n\n remaining -= cur_bytes;\n\n cluster_offset += cur_bytes;\n\n\n\n cur_bytes = remaining;\n\n } else if (cur_bytes == 0) {\n\n goto done;\n\n }\n\n\n\n /* If there is something left to allocate, do that now */\n\n if (remaining == 0) {\n\n goto done;\n\n }\n\n\n\n /*\n\n * 3. If the request still hasn't completed, allocate new clusters,\n\n * considering any cluster_offset of steps 1c or 2.\n\n */\n\n ret = handle_alloc(bs, start, &cluster_offset, &cur_bytes, m);\n\n if (ret < 0) {\n\n return ret;\n\n } else if (ret) {\n\n if (!*host_offset) {\n\n *host_offset = start_of_cluster(s, cluster_offset);\n\n }\n\n\n\n start += cur_bytes;\n\n remaining -= cur_bytes;\n\n cluster_offset += cur_bytes;\n\n }\n\n\n\n /* Some cleanup work */\n\ndone:\n\n *num = (n_end - n_start) - (remaining >> BDRV_SECTOR_BITS);\n\n assert(*num > 0);\n\n assert(*host_offset != 0);\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 14910 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static bool migrate_params_check(MigrationParameters *params, Error **errp)\n\n{\n\n if (params->has_compress_level &&\n\n (params->compress_level < 0 || params->compress_level > 9)) {\n\n error_setg(errp, QERR_INVALID_PARAMETER_VALUE, \"compress_level\",\n\n \"is invalid, it should be in the range of 0 to 9\");\n\n return false;\n\n }\n\n\n\n if (params->has_compress_threads &&\n\n (params->compress_threads < 1 || params->compress_threads > 255)) {\n\n error_setg(errp, QERR_INVALID_PARAMETER_VALUE,\n\n \"compress_threads\",\n\n \"is invalid, it should be in the range of 1 to 255\");\n\n return false;\n\n }\n\n\n\n if (params->has_decompress_threads &&\n\n (params->decompress_threads < 1 || params->decompress_threads > 255)) {\n\n error_setg(errp, QERR_INVALID_PARAMETER_VALUE,\n\n \"decompress_threads\",\n\n \"is invalid, it should be in the range of 1 to 255\");\n\n return false;\n\n }\n\n\n\n if (params->has_cpu_throttle_initial &&\n\n (params->cpu_throttle_initial < 1 ||\n\n params->cpu_throttle_initial > 99)) {\n\n error_setg(errp, QERR_INVALID_PARAMETER_VALUE,\n\n \"cpu_throttle_initial\",\n\n \"an integer in the range of 1 to 99\");\n\n return false;\n\n }\n\n\n\n if (params->has_cpu_throttle_increment &&\n\n (params->cpu_throttle_increment < 1 ||\n\n params->cpu_throttle_increment > 99)) {\n\n error_setg(errp, QERR_INVALID_PARAMETER_VALUE,\n\n \"cpu_throttle_increment\",\n\n \"an integer in the range of 1 to 99\");\n\n return false;\n\n }\n\n\n\n if (params->has_max_bandwidth &&\n\n (params->max_bandwidth < 0 || params->max_bandwidth > SIZE_MAX)) {\n\n error_setg(errp, \"Parameter 'max_bandwidth' expects an integer in the\"\n\n \" range of 0 to %zu bytes/second\", SIZE_MAX);\n\n return false;\n\n }\n\n\n\n if (params->has_downtime_limit &&\n\n (params->downtime_limit < 0 ||\n\n params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {\n\n error_setg(errp, \"Parameter 'downtime_limit' expects an integer in \"\n\n \"the range of 0 to %d milliseconds\",\n\n MAX_MIGRATE_DOWNTIME);\n\n return false;\n\n }\n\n\n\n if (params->has_x_checkpoint_delay && (params->x_checkpoint_delay < 0)) {\n\n error_setg(errp, QERR_INVALID_PARAMETER_VALUE,\n\n \"x_checkpoint_delay\",\n\n \"is invalid, it should be positive\");\n\n return false;\n\n }\n\n if (params->has_x_multifd_channels &&\n\n (params->x_multifd_channels < 1 || params->x_multifd_channels > 255)) {\n\n error_setg(errp, QERR_INVALID_PARAMETER_VALUE,\n\n \"multifd_channels\",\n\n \"is invalid, it should be in the range of 1 to 255\");\n\n return false;\n\n }\n\n if (params->has_x_multifd_page_count &&\n\n (params->x_multifd_page_count < 1 ||\n\n params->x_multifd_page_count > 10000)) {\n\n error_setg(errp, QERR_INVALID_PARAMETER_VALUE,\n\n \"multifd_page_count\",\n\n \"is invalid, it should be in the range of 1 to 10000\");\n\n return false;\n\n }\n\n\n\n if (params->has_xbzrle_cache_size &&\n\n (params->xbzrle_cache_size < qemu_target_page_size() ||\n\n !is_power_of_2(params->xbzrle_cache_size))) {\n\n error_setg(errp, QERR_INVALID_PARAMETER_VALUE,\n\n \"xbzrle_cache_size\",\n\n \"is invalid, it should be bigger than target page size\"\n\n \" and a power of two\");\n\n return false;\n\n }\n\n\n\n return true;\n\n}\n", + "output": "0", + "index": 15090 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void spapr_finalize_fdt(sPAPRMachineState *spapr,\n\n hwaddr fdt_addr,\n\n hwaddr rtas_addr,\n\n hwaddr rtas_size)\n\n{\n\n MachineState *machine = MACHINE(qdev_get_machine());\n\n sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);\n\n const char *boot_device = machine->boot_order;\n\n int ret, i;\n\n size_t cb = 0;\n\n char *bootlist;\n\n void *fdt;\n\n sPAPRPHBState *phb;\n\n\n\n fdt = g_malloc(FDT_MAX_SIZE);\n\n\n\n /* open out the base tree into a temp buffer for the final tweaks */\n\n _FDT((fdt_open_into(spapr->fdt_skel, fdt, FDT_MAX_SIZE)));\n\n\n\n ret = spapr_populate_memory(spapr, fdt);\n\n if (ret < 0) {\n\n fprintf(stderr, \"couldn't setup memory nodes in fdt\\n\");\n\n exit(1);\n\n }\n\n\n\n ret = spapr_populate_vdevice(spapr->vio_bus, fdt);\n\n if (ret < 0) {\n\n fprintf(stderr, \"couldn't setup vio devices in fdt\\n\");\n\n exit(1);\n\n }\n\n\n\n if (object_resolve_path_type(\"\", TYPE_SPAPR_RNG, NULL)) {\n\n ret = spapr_rng_populate_dt(fdt);\n\n if (ret < 0) {\n\n fprintf(stderr, \"could not set up rng device in the fdt\\n\");\n\n exit(1);\n\n }\n\n }\n\n\n\n QLIST_FOREACH(phb, &spapr->phbs, list) {\n\n ret = spapr_populate_pci_dt(phb, PHANDLE_XICP, fdt);\n\n if (ret < 0) {\n\n error_report(\"couldn't setup PCI devices in fdt\");\n\n exit(1);\n\n }\n\n }\n\n\n\n /* RTAS */\n\n ret = spapr_rtas_device_tree_setup(fdt, rtas_addr, rtas_size);\n\n if (ret < 0) {\n\n fprintf(stderr, \"Couldn't set up RTAS device tree properties\\n\");\n\n }\n\n\n\n /* cpus */\n\n spapr_populate_cpus_dt_node(fdt, spapr);\n\n\n\n bootlist = get_boot_devices_list(&cb, true);\n\n if (cb && bootlist) {\n\n int offset = fdt_path_offset(fdt, \"/chosen\");\n\n if (offset < 0) {\n\n exit(1);\n\n }\n\n for (i = 0; i < cb; i++) {\n\n if (bootlist[i] == '\\n') {\n\n bootlist[i] = ' ';\n\n }\n\n\n\n }\n\n ret = fdt_setprop_string(fdt, offset, \"qemu,boot-list\", bootlist);\n\n }\n\n\n\n if (boot_device && strlen(boot_device)) {\n\n int offset = fdt_path_offset(fdt, \"/chosen\");\n\n\n\n if (offset < 0) {\n\n exit(1);\n\n }\n\n fdt_setprop_string(fdt, offset, \"qemu,boot-device\", boot_device);\n\n }\n\n\n\n if (!spapr->has_graphics) {\n\n spapr_populate_chosen_stdout(fdt, spapr->vio_bus);\n\n }\n\n\n\n if (smc->dr_lmb_enabled) {\n\n _FDT(spapr_drc_populate_dt(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB));\n\n }\n\n\n\n if (smc->dr_cpu_enabled) {\n\n int offset = fdt_path_offset(fdt, \"/cpus\");\n\n ret = spapr_drc_populate_dt(fdt, offset, NULL,\n\n SPAPR_DR_CONNECTOR_TYPE_CPU);\n\n if (ret < 0) {\n\n error_report(\"Couldn't set up CPU DR device tree properties\");\n\n exit(1);\n\n }\n\n }\n\n\n\n _FDT((fdt_pack(fdt)));\n\n\n\n if (fdt_totalsize(fdt) > FDT_MAX_SIZE) {\n\n error_report(\"FDT too big ! 0x%x bytes (max is 0x%x)\",\n\n fdt_totalsize(fdt), FDT_MAX_SIZE);\n\n exit(1);\n\n }\n\n\n\n qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt));\n\n cpu_physical_memory_write(fdt_addr, fdt, fdt_totalsize(fdt));\n\n\n\n g_free(bootlist);\n\n g_free(fdt);\n\n}\n", + "output": "1", + "index": 12064 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int qcow_open(BlockDriverState *bs, QDict *options, int flags,\n Error **errp)\n{\n BDRVQcowState *s = bs->opaque;\n int len, i, shift, ret;\n QCowHeader header;\n ret = bdrv_pread(bs->file, 0, &header, sizeof(header));\n if (ret < 0) {\n be32_to_cpus(&header.magic);\n be32_to_cpus(&header.version);\n be64_to_cpus(&header.backing_file_offset);\n be32_to_cpus(&header.backing_file_size);\n be32_to_cpus(&header.mtime);\n be64_to_cpus(&header.size);\n be32_to_cpus(&header.crypt_method);\n be64_to_cpus(&header.l1_table_offset);\n if (header.magic != QCOW_MAGIC) {\n error_setg(errp, \"Image not in qcow format\");\n if (header.version != QCOW_VERSION) {\n char version[64];\n snprintf(version, sizeof(version), \"QCOW version %\" PRIu32,\n header.version);\n error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,\n bs->device_name, \"qcow\", version);\n ret = -ENOTSUP;\n if (header.size <= 1) {\n error_setg(errp, \"Image size is too small (must be at least 2 bytes)\");\n if (header.cluster_bits < 9 || header.cluster_bits > 16) {\n error_setg(errp, \"Cluster size must be between 512 and 64k\");\n if (header.crypt_method > QCOW_CRYPT_AES) {\n error_setg(errp, \"invalid encryption method in qcow header\");\n s->crypt_method_header = header.crypt_method;\n if (s->crypt_method_header) {\n bs->encrypted = 1;\n s->cluster_bits = header.cluster_bits;\n s->cluster_size = 1 << s->cluster_bits;\n s->cluster_sectors = 1 << (s->cluster_bits - 9);\n s->l2_bits = header.l2_bits;\n s->l2_size = 1 << s->l2_bits;\n bs->total_sectors = header.size / 512;\n s->cluster_offset_mask = (1LL << (63 - s->cluster_bits)) - 1;\n /* read the level 1 table */\n shift = s->cluster_bits + s->l2_bits;\n s->l1_size = (header.size + (1LL << shift) - 1) >> shift;\n s->l1_table_offset = header.l1_table_offset;\n s->l1_table = g_malloc(s->l1_size * sizeof(uint64_t));\n ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table,\n s->l1_size * sizeof(uint64_t));\n if (ret < 0) {\n for(i = 0;i < s->l1_size; i++) {\n be64_to_cpus(&s->l1_table[i]);\n /* alloc L2 cache */\n s->l2_cache = g_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));\n s->cluster_cache = g_malloc(s->cluster_size);\n s->cluster_data = g_malloc(s->cluster_size);\n s->cluster_cache_offset = -1;\n /* read the backing file name */\n if (header.backing_file_offset != 0) {\n len = header.backing_file_size;\n if (len > 1023) {\n len = 1023;\n ret = bdrv_pread(bs->file, header.backing_file_offset,\n bs->backing_file, len);\n if (ret < 0) {\n bs->backing_file[len] = '\\0';\n /* Disable migration when qcow images are used */\n error_set(&s->migration_blocker,\n QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,\n \"qcow\", bs->device_name, \"live migration\");\n migrate_add_blocker(s->migration_blocker);\n qemu_co_mutex_init(&s->lock);\n return 0;\n fail:\n g_free(s->l1_table);\n g_free(s->l2_cache);\n g_free(s->cluster_cache);\n g_free(s->cluster_data);\n return ret;", + "output": "1", + "index": 14448 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int img_map(int argc, char **argv)\n\n{\n\n int c;\n\n OutputFormat output_format = OFORMAT_HUMAN;\n\n BlockBackend *blk;\n\n BlockDriverState *bs;\n\n const char *filename, *fmt, *output;\n\n int64_t length;\n\n MapEntry curr = { .length = 0 }, next;\n\n int ret = 0;\n\n bool image_opts = false;\n\n\n\n fmt = NULL;\n\n output = NULL;\n\n for (;;) {\n\n int option_index = 0;\n\n static const struct option long_options[] = {\n\n {\"help\", no_argument, 0, 'h'},\n\n {\"format\", required_argument, 0, 'f'},\n\n {\"output\", required_argument, 0, OPTION_OUTPUT},\n\n {\"object\", required_argument, 0, OPTION_OBJECT},\n\n {\"image-opts\", no_argument, 0, OPTION_IMAGE_OPTS},\n\n {0, 0, 0, 0}\n\n };\n\n c = getopt_long(argc, argv, \"f:h\",\n\n long_options, &option_index);\n\n if (c == -1) {\n\n break;\n\n }\n\n switch (c) {\n\n case '?':\n\n case 'h':\n\n help();\n\n break;\n\n case 'f':\n\n fmt = optarg;\n\n break;\n\n case OPTION_OUTPUT:\n\n output = optarg;\n\n break;\n\n case OPTION_OBJECT: {\n\n QemuOpts *opts;\n\n opts = qemu_opts_parse_noisily(&qemu_object_opts,\n\n optarg, true);\n\n if (!opts) {\n\n return 1;\n\n }\n\n } break;\n\n case OPTION_IMAGE_OPTS:\n\n image_opts = true;\n\n break;\n\n }\n\n }\n\n if (optind != argc - 1) {\n\n error_exit(\"Expecting one image file name\");\n\n }\n\n filename = argv[optind];\n\n\n\n if (output && !strcmp(output, \"json\")) {\n\n output_format = OFORMAT_JSON;\n\n } else if (output && !strcmp(output, \"human\")) {\n\n output_format = OFORMAT_HUMAN;\n\n } else if (output) {\n\n error_report(\"--output must be used with human or json as argument.\");\n\n return 1;\n\n }\n\n\n\n if (qemu_opts_foreach(&qemu_object_opts,\n\n user_creatable_add_opts_foreach,\n\n NULL, NULL)) {\n\n return 1;\n\n }\n\n\n\n blk = img_open(image_opts, filename, fmt, 0, false, false);\n\n if (!blk) {\n\n return 1;\n\n }\n\n bs = blk_bs(blk);\n\n\n\n if (output_format == OFORMAT_HUMAN) {\n\n printf(\"%-16s%-16s%-16s%s\\n\", \"Offset\", \"Length\", \"Mapped to\", \"File\");\n\n }\n\n\n\n length = blk_getlength(blk);\n\n while (curr.start + curr.length < length) {\n\n int64_t nsectors_left;\n\n int64_t sector_num;\n\n int n;\n\n\n\n sector_num = (curr.start + curr.length) >> BDRV_SECTOR_BITS;\n\n\n\n /* Probe up to 1 GiB at a time. */\n\n nsectors_left = DIV_ROUND_UP(length, BDRV_SECTOR_SIZE) - sector_num;\n\n n = MIN(1 << (30 - BDRV_SECTOR_BITS), nsectors_left);\n\n ret = get_block_status(bs, sector_num, n, &next);\n\n\n\n if (ret < 0) {\n\n error_report(\"Could not read file metadata: %s\", strerror(-ret));\n\n goto out;\n\n }\n\n\n\n if (entry_mergeable(&curr, &next)) {\n\n curr.length += next.length;\n\n continue;\n\n }\n\n\n\n if (curr.length > 0) {\n\n dump_map_entry(output_format, &curr, &next);\n\n }\n\n curr = next;\n\n }\n\n\n\n dump_map_entry(output_format, &curr, NULL);\n\n\n\nout:\n\n blk_unref(blk);\n\n return ret < 0;\n\n}\n", + "output": "1", + "index": 18181 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void update_initial_durations(AVFormatContext *s, AVStream *st,\n\n int stream_index, int duration)\n\n{\n\n AVPacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;\n\n int64_t cur_dts = RELATIVE_TS_BASE;\n\n\n\n if (st->first_dts != AV_NOPTS_VALUE) {\n\n if (st->update_initial_durations_done)\n\n return;\n\n st->update_initial_durations_done = 1;\n\n cur_dts = st->first_dts;\n\n for (; pktl; pktl = get_next_pkt(s, st, pktl)) {\n\n if (pktl->pkt.stream_index == stream_index) {\n\n if (pktl->pkt.pts != pktl->pkt.dts ||\n\n pktl->pkt.dts != AV_NOPTS_VALUE ||\n\n pktl->pkt.duration)\n\n break;\n\n cur_dts -= duration;\n\n }\n\n }\n\n if (pktl && pktl->pkt.dts != st->first_dts) {\n\n av_log(s, AV_LOG_DEBUG, \"first_dts %s not matching first dts %s (pts %s, duration %\"PRId64\") in the queue\\n\",\n\n av_ts2str(st->first_dts), av_ts2str(pktl->pkt.dts), av_ts2str(pktl->pkt.pts), pktl->pkt.duration);\n\n return;\n\n }\n\n if (!pktl) {\n\n av_log(s, AV_LOG_DEBUG, \"first_dts %s but no packet with dts in the queue\\n\", av_ts2str(st->first_dts));\n\n return;\n\n }\n\n pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;\n\n st->first_dts = cur_dts;\n\n } else if (st->cur_dts != RELATIVE_TS_BASE)\n\n return;\n\n\n\n for (; pktl; pktl = get_next_pkt(s, st, pktl)) {\n\n if (pktl->pkt.stream_index != stream_index)\n\n continue;\n\n if (pktl->pkt.pts == pktl->pkt.dts &&\n\n (pktl->pkt.dts == AV_NOPTS_VALUE || pktl->pkt.dts == st->first_dts) &&\n\n !pktl->pkt.duration) {\n\n pktl->pkt.dts = cur_dts;\n\n if (!st->internal->avctx->has_b_frames)\n\n pktl->pkt.pts = cur_dts;\n\n// if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)\n\n pktl->pkt.duration = duration;\n\n } else\n\n break;\n\n cur_dts = pktl->pkt.dts + pktl->pkt.duration;\n\n }\n\n if (!pktl)\n\n st->cur_dts = cur_dts;\n\n}\n", + "output": "0", + "index": 25836 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,\n\n int start, int end, int fast_gain, int is_lfe,\n\n int dba_mode, int dba_nsegs, uint8_t *dba_offsets,\n\n uint8_t *dba_lengths, uint8_t *dba_values,\n\n int16_t *mask)\n\n{\n\n int16_t excite[50]; /* excitation */\n\n int bin, k;\n\n int bndstrt, bndend, begin, end1, tmp;\n\n int lowcomp, fastleak, slowleak;\n\n\n\n /* excitation function */\n\n bndstrt = bin_to_band_tab[start];\n\n bndend = bin_to_band_tab[end-1] + 1;\n\n\n\n if (bndstrt == 0) {\n\n lowcomp = 0;\n\n lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384);\n\n excite[0] = band_psd[0] - fast_gain - lowcomp;\n\n lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384);\n\n excite[1] = band_psd[1] - fast_gain - lowcomp;\n\n begin = 7;\n\n for (bin = 2; bin < 7; bin++) {\n\n if (!(is_lfe && bin == 6))\n\n lowcomp = calc_lowcomp1(lowcomp, band_psd[bin], band_psd[bin+1], 384);\n\n fastleak = band_psd[bin] - fast_gain;\n\n slowleak = band_psd[bin] - s->slow_gain;\n\n excite[bin] = fastleak - lowcomp;\n\n if (!(is_lfe && bin == 6)) {\n\n if (band_psd[bin] <= band_psd[bin+1]) {\n\n begin = bin + 1;\n\n break;\n\n }\n\n }\n\n }\n\n\n\n end1=bndend;\n\n if (end1 > 22) end1=22;\n\n\n\n for (bin = begin; bin < end1; bin++) {\n\n if (!(is_lfe && bin == 6))\n\n lowcomp = calc_lowcomp(lowcomp, band_psd[bin], band_psd[bin+1], bin);\n\n\n\n fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);\n\n slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);\n\n excite[bin] = FFMAX(fastleak - lowcomp, slowleak);\n\n }\n\n begin = 22;\n\n } else {\n\n /* coupling channel */\n\n begin = bndstrt;\n\n\n\n fastleak = (s->cpl_fast_leak << 8) + 768;\n\n slowleak = (s->cpl_slow_leak << 8) + 768;\n\n }\n\n\n\n for (bin = begin; bin < bndend; bin++) {\n\n fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);\n\n slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);\n\n excite[bin] = FFMAX(fastleak, slowleak);\n\n }\n\n\n\n /* compute masking curve */\n\n\n\n for (bin = bndstrt; bin < bndend; bin++) {\n\n tmp = s->db_per_bit - band_psd[bin];\n\n if (tmp > 0) {\n\n excite[bin] += tmp >> 2;\n\n }\n\n mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->sr_shift][s->sr_code], excite[bin]);\n\n }\n\n\n\n /* delta bit allocation */\n\n\n\n if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {\n\n int band, seg, delta;\n\n band = 0;\n\n for (seg = 0; seg < dba_nsegs; seg++) {\n\n band += dba_offsets[seg];\n\n if (dba_values[seg] >= 4) {\n\n delta = (dba_values[seg] - 3) << 7;\n\n } else {\n\n delta = (dba_values[seg] - 4) << 7;\n\n }\n\n for (k = 0; k < dba_lengths[seg]; k++) {\n\n mask[band] += delta;\n\n band++;\n\n }\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 8600 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void ff_h261_loop_filter(H261Context * h){\n\n MpegEncContext * const s = &h->s;\n\n int i;\n\n const int linesize = s->linesize;\n\n const int uvlinesize= s->uvlinesize;\n\n uint8_t *dest_y = s->dest[0];\n\n uint8_t *dest_cb= s->dest[1];\n\n uint8_t *dest_cr= s->dest[2];\n\n uint8_t *src;\n\n\n\n CHECKED_ALLOCZ((src),sizeof(uint8_t) * 64 );\n\n\n\n for(i=0; i<8;i++)\n\n memcpy(src+i*8,dest_y+i*linesize,sizeof(uint8_t) * 8 );\n\n s->dsp.h261_v_loop_filter(dest_y, src, linesize);\n\n s->dsp.h261_h_loop_filter(dest_y, src, linesize);\n\n\n\n for(i=0; i<8;i++)\n\n memcpy(src+i*8,dest_y+i*linesize + 8,sizeof(uint8_t) * 8 );\n\n s->dsp.h261_v_loop_filter(dest_y + 8, src, linesize);\n\n s->dsp.h261_h_loop_filter(dest_y + 8, src, linesize);\n\n\n\n for(i=0; i<8;i++)\n\n memcpy(src+i*8,dest_y+(i+8)*linesize,sizeof(uint8_t) * 8 );\n\n s->dsp.h261_v_loop_filter(dest_y + 8 * linesize, src, linesize);\n\n s->dsp.h261_h_loop_filter(dest_y + 8 * linesize, src, linesize);\n\n\n\n for(i=0; i<8;i++)\n\n memcpy(src+i*8,dest_y+(i+8)*linesize + 8,sizeof(uint8_t) * 8 );\n\n s->dsp.h261_v_loop_filter(dest_y + 8 * linesize + 8, src, linesize);\n\n s->dsp.h261_h_loop_filter(dest_y + 8 * linesize + 8, src, linesize);\n\n\n\n for(i=0; i<8;i++)\n\n memcpy(src+i*8,dest_cb+i*uvlinesize,sizeof(uint8_t) * 8 );\n\n s->dsp.h261_v_loop_filter(dest_cb, src, uvlinesize);\n\n s->dsp.h261_h_loop_filter(dest_cb, src, uvlinesize);\n\n\n\n for(i=0; i<8;i++)\n\n memcpy(src+i*8,dest_cr+i*uvlinesize,sizeof(uint8_t) * 8 );\n\n s->dsp.h261_v_loop_filter(dest_cr, src, uvlinesize);\n\n s->dsp.h261_h_loop_filter(dest_cr, src, uvlinesize);\n\n\n\nfail:\n\n av_free(src);\n\n\n\n return;\n\n}\n", + "output": "0", + "index": 23026 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void nand_command(NANDFlashState *s)\n\n{\n\n unsigned int offset;\n\n switch (s->cmd) {\n\n case NAND_CMD_READ0:\n\n s->iolen = 0;\n\n break;\n\n\n\n case NAND_CMD_READID:\n\n s->ioaddr = s->io;\n\n s->iolen = 0;\n\n nand_pushio_byte(s, s->manf_id);\n\n nand_pushio_byte(s, s->chip_id);\n\n nand_pushio_byte(s, 'Q'); /* Don't-care byte (often 0xa5) */\n\n if (nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP) {\n\n /* Page Size, Block Size, Spare Size; bit 6 indicates\n\n * 8 vs 16 bit width NAND.\n\n */\n\n nand_pushio_byte(s, (s->buswidth == 2) ? 0x55 : 0x15);\n\n } else {\n\n nand_pushio_byte(s, 0xc0); /* Multi-plane */\n\n }\n\n break;\n\n\n\n case NAND_CMD_RANDOMREAD2:\n\n case NAND_CMD_NOSERIALREAD2:\n\n if (!(nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP))\n\n break;\n\n offset = s->addr & ((1 << s->addr_shift) - 1);\n\n s->blk_load(s, s->addr, offset);\n\n if (s->gnd)\n\n s->iolen = (1 << s->page_shift) - offset;\n\n else\n\n s->iolen = (1 << s->page_shift) + (1 << s->oob_shift) - offset;\n\n break;\n\n\n\n case NAND_CMD_RESET:\n\n nand_reset(DEVICE(s));\n\n break;\n\n\n\n case NAND_CMD_PAGEPROGRAM1:\n\n s->ioaddr = s->io;\n\n s->iolen = 0;\n\n break;\n\n\n\n case NAND_CMD_PAGEPROGRAM2:\n\n if (s->wp) {\n\n s->blk_write(s);\n\n }\n\n break;\n\n\n\n case NAND_CMD_BLOCKERASE1:\n\n break;\n\n\n\n case NAND_CMD_BLOCKERASE2:\n\n s->addr &= (1ull << s->addrlen * 8) - 1;\n\n s->addr <<= nand_flash_ids[s->chip_id].options & NAND_SAMSUNG_LP ?\n\n 16 : 8;\n\n\n\n if (s->wp) {\n\n s->blk_erase(s);\n\n }\n\n break;\n\n\n\n case NAND_CMD_READSTATUS:\n\n s->ioaddr = s->io;\n\n s->iolen = 0;\n\n nand_pushio_byte(s, s->status);\n\n break;\n\n\n\n default:\n\n printf(\"%s: Unknown NAND command 0x%02x\\n\", __FUNCTION__, s->cmd);\n\n }\n\n}\n", + "output": "0", + "index": 24841 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void main_loop_wait(int timeout)\n\n{\n\n IOHandlerRecord *ioh;\n\n fd_set rfds, wfds, xfds;\n\n int ret, nfds;\n\n struct timeval tv;\n\n\n\n qemu_bh_update_timeout(&timeout);\n\n\n\n host_main_loop_wait(&timeout);\n\n\n\n /* poll any events */\n\n /* XXX: separate device handlers from system ones */\n\n nfds = -1;\n\n FD_ZERO(&rfds);\n\n FD_ZERO(&wfds);\n\n FD_ZERO(&xfds);\n\n for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {\n\n if (ioh->deleted)\n\n continue;\n\n if (ioh->fd_read &&\n\n (!ioh->fd_read_poll ||\n\n ioh->fd_read_poll(ioh->opaque) != 0)) {\n\n FD_SET(ioh->fd, &rfds);\n\n if (ioh->fd > nfds)\n\n nfds = ioh->fd;\n\n }\n\n if (ioh->fd_write) {\n\n FD_SET(ioh->fd, &wfds);\n\n if (ioh->fd > nfds)\n\n nfds = ioh->fd;\n\n }\n\n }\n\n\n\n tv.tv_sec = timeout / 1000;\n\n tv.tv_usec = (timeout % 1000) * 1000;\n\n\n\n slirp_select_fill(&nfds, &rfds, &wfds, &xfds);\n\n\n\n qemu_mutex_unlock_iothread();\n\n ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);\n\n qemu_mutex_lock_iothread();\n\n if (ret > 0) {\n\n IOHandlerRecord **pioh;\n\n\n\n for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {\n\n if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {\n\n ioh->fd_read(ioh->opaque);\n\n }\n\n if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {\n\n ioh->fd_write(ioh->opaque);\n\n }\n\n }\n\n\n\n\t/* remove deleted IO handlers */\n\n\tpioh = &first_io_handler;\n\n\twhile (*pioh) {\n\n ioh = *pioh;\n\n if (ioh->deleted) {\n\n *pioh = ioh->next;\n\n qemu_free(ioh);\n\n } else\n\n pioh = &ioh->next;\n\n }\n\n }\n\n\n\n slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));\n\n\n\n /* rearm timer, if not periodic */\n\n if (alarm_timer->flags & ALARM_FLAG_EXPIRED) {\n\n alarm_timer->flags &= ~ALARM_FLAG_EXPIRED;\n\n qemu_rearm_alarm_timer(alarm_timer);\n\n }\n\n\n\n /* vm time timers */\n\n if (vm_running) {\n\n if (!cur_cpu || likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER)))\n\n qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL],\n\n qemu_get_clock(vm_clock));\n\n }\n\n\n\n /* real time timers */\n\n qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME],\n\n qemu_get_clock(rt_clock));\n\n\n\n /* Check bottom-halves last in case any of the earlier events triggered\n\n them. */\n\n qemu_bh_poll();\n\n\n\n}\n", + "output": "0", + "index": 184 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)\n\n{\n\n struct video_data *s = s1->priv_data;\n\n struct v4l2_input input;\n\n struct v4l2_standard standard;\n\n struct v4l2_streamparm streamparm = { 0 };\n\n struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe;\n\n int i;\n\n\n\n streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;\n\n\n\n#if FF_API_FORMAT_PARAMETERS\n\n if (ap->channel > 0)\n\n s->channel = ap->channel;\n\n#endif\n\n\n\n /* set tv video input */\n\n memset (&input, 0, sizeof (input));\n\n input.index = s->channel;\n\n if (ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {\n\n av_log(s1, AV_LOG_ERROR, \"The V4L2 driver ioctl enum input failed:\\n\");\n\n return AVERROR(EIO);\n\n }\n\n\n\n av_log(s1, AV_LOG_DEBUG, \"The V4L2 driver set input_id: %d, input: %s\\n\",\n\n s->channel, input.name);\n\n if (ioctl(s->fd, VIDIOC_S_INPUT, &input.index) < 0) {\n\n av_log(s1, AV_LOG_ERROR, \"The V4L2 driver ioctl set input(%d) failed\\n\",\n\n s->channel);\n\n return AVERROR(EIO);\n\n }\n\n\n\n#if FF_API_FORMAT_PARAMETERS\n\n if (ap->standard) {\n\n av_freep(&s->standard);\n\n s->standard = av_strdup(ap->standard);\n\n }\n\n#endif\n\n\n\n if (s->standard) {\n\n av_log(s1, AV_LOG_DEBUG, \"The V4L2 driver set standard: %s\\n\",\n\n s->standard);\n\n /* set tv standard */\n\n memset (&standard, 0, sizeof (standard));\n\n for(i=0;;i++) {\n\n standard.index = i;\n\n if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {\n\n av_log(s1, AV_LOG_ERROR, \"The V4L2 driver ioctl set standard(%s) failed\\n\",\n\n s->standard);\n\n return AVERROR(EIO);\n\n }\n\n\n\n if (!strcasecmp(standard.name, s->standard)) {\n\n break;\n\n }\n\n }\n\n\n\n av_log(s1, AV_LOG_DEBUG, \"The V4L2 driver set standard: %s, id: %\"PRIu64\"\\n\",\n\n s->standard, (uint64_t)standard.id);\n\n if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {\n\n av_log(s1, AV_LOG_ERROR, \"The V4L2 driver ioctl set standard(%s) failed\\n\",\n\n s->standard);\n\n return AVERROR(EIO);\n\n }\n\n }\n\n av_freep(&s->standard);\n\n\n\n if (ap->time_base.num && ap->time_base.den) {\n\n av_log(s1, AV_LOG_DEBUG, \"Setting time per frame to %d/%d\\n\",\n\n ap->time_base.num, ap->time_base.den);\n\n tpf->numerator = ap->time_base.num;\n\n tpf->denominator = ap->time_base.den;\n\n if (ioctl(s->fd, VIDIOC_S_PARM, &streamparm) != 0) {\n\n av_log(s1, AV_LOG_ERROR,\n\n \"ioctl set time per frame(%d/%d) failed\\n\",\n\n ap->time_base.num, ap->time_base.den);\n\n return AVERROR(EIO);\n\n }\n\n\n\n if (ap->time_base.den != tpf->denominator ||\n\n ap->time_base.num != tpf->numerator) {\n\n av_log(s1, AV_LOG_INFO,\n\n \"The driver changed the time per frame from %d/%d to %d/%d\\n\",\n\n ap->time_base.num, ap->time_base.den,\n\n tpf->numerator, tpf->denominator);\n\n }\n\n } else {\n\n /* if timebase value is not set in ap, read the timebase value from the driver */\n\n if (ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) {\n\n av_log(s1, AV_LOG_ERROR, \"ioctl(VIDIOC_G_PARM): %s\\n\", strerror(errno));\n\n return AVERROR(errno);\n\n }\n\n }\n\n ap->time_base.num = tpf->numerator;\n\n ap->time_base.den = tpf->denominator;\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 11886 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold void x8_vlc_init(void){\n\n int i;\n\n int offset = 0;\n\n int sizeidx = 0;\n\n static const uint16_t sizes[8*4 + 8*2 + 2 + 4] = {\n\n 576, 548, 582, 618, 546, 616, 560, 642,\n\n 584, 582, 704, 664, 512, 544, 656, 640,\n\n 512, 648, 582, 566, 532, 614, 596, 648,\n\n 586, 552, 584, 590, 544, 578, 584, 624,\n\n\n\n 528, 528, 526, 528, 536, 528, 526, 544,\n\n 544, 512, 512, 528, 528, 544, 512, 544,\n\n\n\n 128, 128, 128, 128, 128, 128};\n\n\n\n static VLC_TYPE table[28150][2];\n\n\n\n#define init_ac_vlc(dst,src) \\\n\n dst.table = &table[offset]; \\\n\n dst.table_allocated = sizes[sizeidx]; \\\n\n offset += sizes[sizeidx++]; \\\n\n init_vlc(&dst, \\\n\n AC_VLC_BITS,77, \\\n\n &src[1],4,2, \\\n\n &src[0],4,2, \\\n\n INIT_VLC_USE_NEW_STATIC)\n\n//set ac tables\n\n for(i=0;i<8;i++){\n\n init_ac_vlc( j_ac_vlc[0][0][i], x8_ac0_highquant_table[i][0] );\n\n init_ac_vlc( j_ac_vlc[0][1][i], x8_ac1_highquant_table[i][0] );\n\n init_ac_vlc( j_ac_vlc[1][0][i], x8_ac0_lowquant_table [i][0] );\n\n init_ac_vlc( j_ac_vlc[1][1][i], x8_ac1_lowquant_table [i][0] );\n\n }\n\n#undef init_ac_vlc\n\n\n\n//set dc tables\n\n#define init_dc_vlc(dst,src) \\\n\n dst.table = &table[offset]; \\\n\n dst.table_allocated = sizes[sizeidx]; \\\n\n offset += sizes[sizeidx++]; \\\n\n init_vlc(&dst, \\\n\n DC_VLC_BITS,34, \\\n\n &src[1],4,2, \\\n\n &src[0],4,2, \\\n\n INIT_VLC_USE_NEW_STATIC);\n\n for(i=0;i<8;i++){\n\n init_dc_vlc( j_dc_vlc[0][i], x8_dc_highquant_table[i][0]);\n\n init_dc_vlc( j_dc_vlc[1][i], x8_dc_lowquant_table [i][0]);\n\n }\n\n#undef init_dc_vlc\n\n\n\n//set orient tables\n\n#define init_or_vlc(dst,src) \\\n\n dst.table = &table[offset]; \\\n\n dst.table_allocated = sizes[sizeidx]; \\\n\n offset += sizes[sizeidx++]; \\\n\n init_vlc(&dst, \\\n\n OR_VLC_BITS,12, \\\n\n &src[1],4,2, \\\n\n &src[0],4,2, \\\n\n INIT_VLC_USE_NEW_STATIC);\n\n for(i=0;i<2;i++){\n\n init_or_vlc( j_orient_vlc[0][i], x8_orient_highquant_table[i][0]);\n\n }\n\n for(i=0;i<4;i++){\n\n init_or_vlc( j_orient_vlc[1][i], x8_orient_lowquant_table [i][0])\n\n }\n\n if (offset != sizeof(table)/sizeof(VLC_TYPE)/2)\n\n av_log(NULL, AV_LOG_ERROR, \"table size %i does not match needed %i\\n\", (int)(sizeof(table)/sizeof(VLC_TYPE)/2), offset);\n\n}\n", + "output": "0", + "index": 9244 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int qemu_rdma_block_for_wrid(RDMAContext *rdma, int wrid_requested,\n\n uint32_t *byte_len)\n\n{\n\n int num_cq_events = 0, ret = 0;\n\n struct ibv_cq *cq;\n\n void *cq_ctx;\n\n uint64_t wr_id = RDMA_WRID_NONE, wr_id_in;\n\n\n\n if (ibv_req_notify_cq(rdma->cq, 0)) {\n\n return -1;\n\n }\n\n /* poll cq first */\n\n while (wr_id != wrid_requested) {\n\n ret = qemu_rdma_poll(rdma, &wr_id_in, byte_len);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n wr_id = wr_id_in & RDMA_WRID_TYPE_MASK;\n\n\n\n if (wr_id == RDMA_WRID_NONE) {\n\n break;\n\n }\n\n if (wr_id != wrid_requested) {\n\n trace_qemu_rdma_block_for_wrid_miss(print_wrid(wrid_requested),\n\n wrid_requested, print_wrid(wr_id), wr_id);\n\n }\n\n }\n\n\n\n if (wr_id == wrid_requested) {\n\n return 0;\n\n }\n\n\n\n while (1) {\n\n /*\n\n * Coroutine doesn't start until migration_fd_process_incoming()\n\n * so don't yield unless we know we're running inside of a coroutine.\n\n */\n\n if (rdma->migration_started_on_destination) {\n\n yield_until_fd_readable(rdma->comp_channel->fd);\n\n }\n\n\n\n ret = ibv_get_cq_event(rdma->comp_channel, &cq, &cq_ctx);\n\n if (ret) {\n\n perror(\"ibv_get_cq_event\");\n\n goto err_block_for_wrid;\n\n }\n\n\n\n num_cq_events++;\n\n\n\n ret = -ibv_req_notify_cq(cq, 0);\n\n if (ret) {\n\n goto err_block_for_wrid;\n\n }\n\n\n\n while (wr_id != wrid_requested) {\n\n ret = qemu_rdma_poll(rdma, &wr_id_in, byte_len);\n\n if (ret < 0) {\n\n goto err_block_for_wrid;\n\n }\n\n\n\n wr_id = wr_id_in & RDMA_WRID_TYPE_MASK;\n\n\n\n if (wr_id == RDMA_WRID_NONE) {\n\n break;\n\n }\n\n if (wr_id != wrid_requested) {\n\n trace_qemu_rdma_block_for_wrid_miss(print_wrid(wrid_requested),\n\n wrid_requested, print_wrid(wr_id), wr_id);\n\n }\n\n }\n\n\n\n if (wr_id == wrid_requested) {\n\n goto success_block_for_wrid;\n\n }\n\n }\n\n\n\nsuccess_block_for_wrid:\n\n if (num_cq_events) {\n\n ibv_ack_cq_events(cq, num_cq_events);\n\n }\n\n return 0;\n\n\n\nerr_block_for_wrid:\n\n if (num_cq_events) {\n\n ibv_ack_cq_events(cq, num_cq_events);\n\n }\n\n\n\n rdma->error_state = ret;\n\n return ret;\n\n}\n", + "output": "0", + "index": 4939 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold int a64multi_encode_init(AVCodecContext *avctx)\n\n{\n\n A64Context *c = avctx->priv_data;\n\n int a;\n\n av_lfg_init(&c->randctx, 1);\n\n\n\n if (avctx->global_quality < 1) {\n\n c->mc_lifetime = 4;\n\n } else {\n\n c->mc_lifetime = avctx->global_quality /= FF_QP2LAMBDA;\n\n }\n\n\n\n av_log(avctx, AV_LOG_INFO, \"charset lifetime set to %d frame(s)\\n\", c->mc_lifetime);\n\n\n\n c->mc_frame_counter = 0;\n\n c->mc_use_5col = avctx->codec->id == AV_CODEC_ID_A64_MULTI5;\n\n c->mc_pal_size = 4 + c->mc_use_5col;\n\n\n\n /* precalc luma values for later use */\n\n for (a = 0; a < c->mc_pal_size; a++) {\n\n c->mc_luma_vals[a]=a64_palette[mc_colors[a]][0] * 0.30 +\n\n a64_palette[mc_colors[a]][1] * 0.59 +\n\n a64_palette[mc_colors[a]][2] * 0.11;\n\n }\n\n\n\n if (!(c->mc_meta_charset = av_malloc(32000 * c->mc_lifetime * sizeof(int))) ||\n\n !(c->mc_best_cb = av_malloc(CHARSET_CHARS * 32 * sizeof(int))) ||\n\n !(c->mc_charmap = av_mallocz(1000 * c->mc_lifetime * sizeof(int))) ||\n\n !(c->mc_colram = av_mallocz(CHARSET_CHARS * sizeof(uint8_t))) ||\n\n !(c->mc_charset = av_malloc(0x800 * (INTERLACED+1) * sizeof(uint8_t)))) {\n\n av_log(avctx, AV_LOG_ERROR, \"Failed to allocate buffer memory.\\n\");\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n /* set up extradata */\n\n if (!(avctx->extradata = av_mallocz(8 * 4 + FF_INPUT_BUFFER_PADDING_SIZE))) {\n\n av_log(avctx, AV_LOG_ERROR, \"Failed to allocate memory for extradata.\\n\");\n\n return AVERROR(ENOMEM);\n\n }\n\n avctx->extradata_size = 8 * 4;\n\n AV_WB32(avctx->extradata, c->mc_lifetime);\n\n AV_WB32(avctx->extradata + 16, INTERLACED);\n\n\n\n avctx->coded_frame = av_frame_alloc();\n\n if (!avctx->coded_frame) {\n\n a64multi_close_encoder(avctx);\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;\n\n avctx->coded_frame->key_frame = 1;\n\n if (!avctx->codec_tag)\n\n avctx->codec_tag = AV_RL32(\"a64m\");\n\n\n\n c->next_pts = AV_NOPTS_VALUE;\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 5300 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int vio_make_devnode(VIOsPAPRDevice *dev,\n\n void *fdt)\n\n{\n\n VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);\n\n int vdevice_off, node_off, ret;\n\n char *dt_name;\n\n\n\n vdevice_off = fdt_path_offset(fdt, \"/vdevice\");\n\n if (vdevice_off < 0) {\n\n return vdevice_off;\n\n }\n\n\n\n dt_name = vio_format_dev_name(dev);\n\n if (!dt_name) {\n\n return -ENOMEM;\n\n }\n\n\n\n node_off = fdt_add_subnode(fdt, vdevice_off, dt_name);\n\n free(dt_name);\n\n if (node_off < 0) {\n\n return node_off;\n\n }\n\n\n\n ret = fdt_setprop_cell(fdt, node_off, \"reg\", dev->reg);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n if (pc->dt_type) {\n\n ret = fdt_setprop_string(fdt, node_off, \"device_type\",\n\n pc->dt_type);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n }\n\n\n\n if (pc->dt_compatible) {\n\n ret = fdt_setprop_string(fdt, node_off, \"compatible\",\n\n pc->dt_compatible);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n }\n\n\n\n if (dev->qirq) {\n\n uint32_t ints_prop[] = {cpu_to_be32(dev->vio_irq_num), 0};\n\n\n\n ret = fdt_setprop(fdt, node_off, \"interrupts\", ints_prop,\n\n sizeof(ints_prop));\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n }\n\n\n\n if (dev->rtce_window_size) {\n\n uint32_t dma_prop[] = {cpu_to_be32(dev->reg),\n\n 0, 0,\n\n 0, cpu_to_be32(dev->rtce_window_size)};\n\n\n\n ret = fdt_setprop_cell(fdt, node_off, \"ibm,#dma-address-cells\", 2);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n ret = fdt_setprop_cell(fdt, node_off, \"ibm,#dma-size-cells\", 2);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n ret = fdt_setprop(fdt, node_off, \"ibm,my-dma-window\", dma_prop,\n\n sizeof(dma_prop));\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n }\n\n\n\n if (pc->devnode) {\n\n ret = (pc->devnode)(dev, fdt, node_off);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n }\n\n\n\n return node_off;\n\n}\n", + "output": "1", + "index": 19559 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int get_segment64(CPUPPCState *env, mmu_ctx_t *ctx,\n\n target_ulong eaddr, int rw, int type)\n\n{\n\n hwaddr hash;\n\n target_ulong vsid;\n\n int pr, target_page_bits;\n\n int ret, ret2;\n\n\n\n pr = msr_pr;\n\n ctx->eaddr = eaddr;\n\n ppc_slb_t *slb;\n\n target_ulong pageaddr;\n\n int segment_bits;\n\n\n\n LOG_MMU(\"Check SLBs\\n\");\n\n slb = slb_lookup(env, eaddr);\n\n if (!slb) {\n\n return -5;\n\n }\n\n\n\n if (slb->vsid & SLB_VSID_B) {\n\n vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT_1T;\n\n segment_bits = 40;\n\n } else {\n\n vsid = (slb->vsid & SLB_VSID_VSID) >> SLB_VSID_SHIFT;\n\n segment_bits = 28;\n\n }\n\n\n\n target_page_bits = (slb->vsid & SLB_VSID_L)\n\n ? TARGET_PAGE_BITS_16M : TARGET_PAGE_BITS;\n\n ctx->key = !!(pr ? (slb->vsid & SLB_VSID_KP)\n\n : (slb->vsid & SLB_VSID_KS));\n\n ctx->nx = !!(slb->vsid & SLB_VSID_N);\n\n\n\n pageaddr = eaddr & ((1ULL << segment_bits)\n\n - (1ULL << target_page_bits));\n\n if (slb->vsid & SLB_VSID_B) {\n\n hash = vsid ^ (vsid << 25) ^ (pageaddr >> target_page_bits);\n\n } else {\n\n hash = vsid ^ (pageaddr >> target_page_bits);\n\n }\n\n /* Only 5 bits of the page index are used in the AVPN */\n\n ctx->ptem = (slb->vsid & SLB_VSID_PTEM) |\n\n ((pageaddr >> 16) & ((1ULL << segment_bits) - 0x80));\n\n\n\n LOG_MMU(\"pte segment: key=%d nx %d vsid \" TARGET_FMT_lx \"\\n\",\n\n ctx->key, ctx->nx, vsid);\n\n ret = -1;\n\n\n\n /* Check if instruction fetch is allowed, if needed */\n\n if (type != ACCESS_CODE || ctx->nx == 0) {\n\n /* Page address translation */\n\n LOG_MMU(\"htab_base \" TARGET_FMT_plx \" htab_mask \" TARGET_FMT_plx\n\n \" hash \" TARGET_FMT_plx \"\\n\",\n\n env->htab_base, env->htab_mask, hash);\n\n ctx->hash[0] = hash;\n\n ctx->hash[1] = ~hash;\n\n\n\n /* Initialize real address with an invalid value */\n\n ctx->raddr = (hwaddr)-1ULL;\n\n LOG_MMU(\"0 htab=\" TARGET_FMT_plx \"/\" TARGET_FMT_plx\n\n \" vsid=\" TARGET_FMT_lx \" ptem=\" TARGET_FMT_lx\n\n \" hash=\" TARGET_FMT_plx \"\\n\",\n\n env->htab_base, env->htab_mask, vsid, ctx->ptem,\n\n ctx->hash[0]);\n\n /* Primary table lookup */\n\n ret = find_pte64(env, ctx, 0, rw, type, target_page_bits);\n\n if (ret < 0) {\n\n /* Secondary table lookup */\n\n LOG_MMU(\"1 htab=\" TARGET_FMT_plx \"/\" TARGET_FMT_plx\n\n \" vsid=\" TARGET_FMT_lx \" api=\" TARGET_FMT_lx\n\n \" hash=\" TARGET_FMT_plx \"\\n\", env->htab_base,\n\n env->htab_mask, vsid, ctx->ptem, ctx->hash[1]);\n\n ret2 = find_pte64(env, ctx, 1, rw, type, target_page_bits);\n\n if (ret2 != -1) {\n\n ret = ret2;\n\n }\n\n }\n\n } else {\n\n LOG_MMU(\"No access allowed\\n\");\n\n ret = -3;\n\n }\n\n\n\n return ret;\n\n}\n", + "output": "0", + "index": 21209 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "av_cold void ff_mpeg1_encode_init(MpegEncContext *s)\n\n{\n\n static int done = 0;\n\n\n\n ff_mpeg12_common_init(s);\n\n\n\n if (!done) {\n\n int f_code;\n\n int mv;\n\n int i;\n\n\n\n done = 1;\n\n ff_rl_init(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]);\n\n ff_rl_init(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]);\n\n\n\n for (i = 0; i < 64; i++) {\n\n mpeg1_max_level[0][i] = ff_rl_mpeg1.max_level[0][i];\n\n mpeg1_index_run[0][i] = ff_rl_mpeg1.index_run[0][i];\n\n }\n\n\n\n init_uni_ac_vlc(&ff_rl_mpeg1, uni_mpeg1_ac_vlc_len);\n\n if (s->intra_vlc_format)\n\n init_uni_ac_vlc(&ff_rl_mpeg2, uni_mpeg2_ac_vlc_len);\n\n\n\n /* build unified dc encoding tables */\n\n for (i = -255; i < 256; i++) {\n\n int adiff, index;\n\n int bits, code;\n\n int diff = i;\n\n\n\n adiff = FFABS(diff);\n\n if (diff < 0)\n\n diff--;\n\n index = av_log2(2 * adiff);\n\n\n\n bits = ff_mpeg12_vlc_dc_lum_bits[index] + index;\n\n code = (ff_mpeg12_vlc_dc_lum_code[index] << index) +\n\n av_mod_uintp2(diff, index);\n\n mpeg1_lum_dc_uni[i + 255] = bits + (code << 8);\n\n\n\n bits = ff_mpeg12_vlc_dc_chroma_bits[index] + index;\n\n code = (ff_mpeg12_vlc_dc_chroma_code[index] << index) +\n\n av_mod_uintp2(diff, index);\n\n mpeg1_chr_dc_uni[i + 255] = bits + (code << 8);\n\n }\n\n\n\n for (f_code = 1; f_code <= MAX_FCODE; f_code++)\n\n for (mv = -MAX_MV; mv <= MAX_MV; mv++) {\n\n int len;\n\n\n\n if (mv == 0) {\n\n len = ff_mpeg12_mbMotionVectorTable[0][1];\n\n } else {\n\n int val, bit_size, code;\n\n\n\n bit_size = f_code - 1;\n\n\n\n val = mv;\n\n if (val < 0)\n\n val = -val;\n\n val--;\n\n code = (val >> bit_size) + 1;\n\n if (code < 17)\n\n len = ff_mpeg12_mbMotionVectorTable[code][1] +\n\n 1 + bit_size;\n\n else\n\n len = ff_mpeg12_mbMotionVectorTable[16][1] +\n\n 2 + bit_size;\n\n }\n\n\n\n mv_penalty[f_code][mv + MAX_MV] = len;\n\n }\n\n\n\n\n\n for (f_code = MAX_FCODE; f_code > 0; f_code--)\n\n for (mv = -(8 << f_code); mv < (8 << f_code); mv++)\n\n fcode_tab[mv + MAX_MV] = f_code;\n\n }\n\n s->me.mv_penalty = mv_penalty;\n\n s->fcode_tab = fcode_tab;\n\n if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO) {\n\n s->min_qcoeff = -255;\n\n s->max_qcoeff = 255;\n\n } else {\n\n s->min_qcoeff = -2047;\n\n s->max_qcoeff = 2047;\n\n }\n\n if (s->intra_vlc_format) {\n\n s->intra_ac_vlc_length =\n\n s->intra_ac_vlc_last_length = uni_mpeg2_ac_vlc_len;\n\n } else {\n\n s->intra_ac_vlc_length =\n\n s->intra_ac_vlc_last_length = uni_mpeg1_ac_vlc_len;\n\n }\n\n s->inter_ac_vlc_length =\n\n s->inter_ac_vlc_last_length = uni_mpeg1_ac_vlc_len;\n\n}\n", + "output": "0", + "index": 19608 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt,\n\n int has_alpha)\n\n{\n\n const PixFmtInfo *pf, *ps;\n\n const AVPixFmtDescriptor *src_desc = &av_pix_fmt_descriptors[src_pix_fmt];\n\n const AVPixFmtDescriptor *dst_desc = &av_pix_fmt_descriptors[dst_pix_fmt];\n\n int loss;\n\n\n\n ps = &pix_fmt_info[src_pix_fmt];\n\n\n\n /* compute loss */\n\n loss = 0;\n\n pf = &pix_fmt_info[dst_pix_fmt];\n\n if (pf->depth < ps->depth ||\n\n ((dst_pix_fmt == PIX_FMT_RGB555BE || dst_pix_fmt == PIX_FMT_RGB555LE ||\n\n dst_pix_fmt == PIX_FMT_BGR555BE || dst_pix_fmt == PIX_FMT_BGR555LE) &&\n\n (src_pix_fmt == PIX_FMT_RGB565BE || src_pix_fmt == PIX_FMT_RGB565LE ||\n\n src_pix_fmt == PIX_FMT_BGR565BE || src_pix_fmt == PIX_FMT_BGR565LE)))\n\n loss |= FF_LOSS_DEPTH;\n\n if (dst_desc->log2_chroma_w > src_desc->log2_chroma_w ||\n\n dst_desc->log2_chroma_h > src_desc->log2_chroma_h)\n\n loss |= FF_LOSS_RESOLUTION;\n\n switch(pf->color_type) {\n\n case FF_COLOR_RGB:\n\n if (ps->color_type != FF_COLOR_RGB &&\n\n ps->color_type != FF_COLOR_GRAY)\n\n loss |= FF_LOSS_COLORSPACE;\n\n break;\n\n case FF_COLOR_GRAY:\n\n if (ps->color_type != FF_COLOR_GRAY)\n\n loss |= FF_LOSS_COLORSPACE;\n\n break;\n\n case FF_COLOR_YUV:\n\n if (ps->color_type != FF_COLOR_YUV)\n\n loss |= FF_LOSS_COLORSPACE;\n\n break;\n\n case FF_COLOR_YUV_JPEG:\n\n if (ps->color_type != FF_COLOR_YUV_JPEG &&\n\n ps->color_type != FF_COLOR_YUV &&\n\n ps->color_type != FF_COLOR_GRAY)\n\n loss |= FF_LOSS_COLORSPACE;\n\n break;\n\n default:\n\n /* fail safe test */\n\n if (ps->color_type != pf->color_type)\n\n loss |= FF_LOSS_COLORSPACE;\n\n break;\n\n }\n\n if (pf->color_type == FF_COLOR_GRAY &&\n\n ps->color_type != FF_COLOR_GRAY)\n\n loss |= FF_LOSS_CHROMA;\n\n if (!pf->is_alpha && (ps->is_alpha && has_alpha))\n\n loss |= FF_LOSS_ALPHA;\n\n if (pf->pixel_type == FF_PIXEL_PALETTE &&\n\n (ps->pixel_type != FF_PIXEL_PALETTE && ps->color_type != FF_COLOR_GRAY))\n\n loss |= FF_LOSS_COLORQUANT;\n\n return loss;\n\n}\n", + "output": "0", + "index": 4584 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "av_cold int ff_dvvideo_init(AVCodecContext *avctx)\n\n{\n\n DVVideoContext *s = avctx->priv_data;\n\n DSPContext dsp;\n\n static int done = 0;\n\n int i, j;\n\n\n\n if (!done) {\n\n VLC dv_vlc;\n\n uint16_t new_dv_vlc_bits[NB_DV_VLC*2];\n\n uint8_t new_dv_vlc_len[NB_DV_VLC*2];\n\n uint8_t new_dv_vlc_run[NB_DV_VLC*2];\n\n int16_t new_dv_vlc_level[NB_DV_VLC*2];\n\n\n\n done = 1;\n\n\n\n /* it's faster to include sign bit in a generic VLC parsing scheme */\n\n for (i = 0, j = 0; i < NB_DV_VLC; i++, j++) {\n\n new_dv_vlc_bits[j] = dv_vlc_bits[i];\n\n new_dv_vlc_len[j] = dv_vlc_len[i];\n\n new_dv_vlc_run[j] = dv_vlc_run[i];\n\n new_dv_vlc_level[j] = dv_vlc_level[i];\n\n\n\n if (dv_vlc_level[i]) {\n\n new_dv_vlc_bits[j] <<= 1;\n\n new_dv_vlc_len[j]++;\n\n\n\n j++;\n\n new_dv_vlc_bits[j] = (dv_vlc_bits[i] << 1) | 1;\n\n new_dv_vlc_len[j] = dv_vlc_len[i] + 1;\n\n new_dv_vlc_run[j] = dv_vlc_run[i];\n\n new_dv_vlc_level[j] = -dv_vlc_level[i];\n\n }\n\n }\n\n\n\n /* NOTE: as a trick, we use the fact the no codes are unused\n\n to accelerate the parsing of partial codes */\n\n init_vlc(&dv_vlc, TEX_VLC_BITS, j,\n\n new_dv_vlc_len, 1, 1, new_dv_vlc_bits, 2, 2, 0);\n\n assert(dv_vlc.table_size == 1184);\n\n\n\n for (i = 0; i < dv_vlc.table_size; i++){\n\n int code = dv_vlc.table[i][0];\n\n int len = dv_vlc.table[i][1];\n\n int level, run;\n\n\n\n if (len < 0){ //more bits needed\n\n run = 0;\n\n level = code;\n\n } else {\n\n run = new_dv_vlc_run [code] + 1;\n\n level = new_dv_vlc_level[code];\n\n }\n\n ff_dv_rl_vlc[i].len = len;\n\n ff_dv_rl_vlc[i].level = level;\n\n ff_dv_rl_vlc[i].run = run;\n\n }\n\n ff_free_vlc(&dv_vlc);\n\n }\n\n\n\n /* Generic DSP setup */\n\n\n ff_dsputil_init(&dsp, avctx);\n\n ff_set_cmp(&dsp, dsp.ildct_cmp, avctx->ildct_cmp);\n\n s->get_pixels = dsp.get_pixels;\n\n s->ildct_cmp = dsp.ildct_cmp[5];\n\n\n\n /* 88DCT setup */\n\n s->fdct[0] = dsp.fdct;\n\n s->idct_put[0] = dsp.idct_put;\n\n for (i = 0; i < 64; i++)\n\n s->dv_zigzag[0][i] = dsp.idct_permutation[ff_zigzag_direct[i]];\n\n\n\n /* 248DCT setup */\n\n s->fdct[1] = dsp.fdct248;\n\n s->idct_put[1] = ff_simple_idct248_put; // FIXME: need to add it to DSP\n\n if (avctx->lowres){\n\n for (i = 0; i < 64; i++){\n\n int j = ff_zigzag248_direct[i];\n\n s->dv_zigzag[1][i] = dsp.idct_permutation[(j & 7) + (j & 8) * 4 + (j & 48) / 2];\n\n }\n\n }else\n\n memcpy(s->dv_zigzag[1], ff_zigzag248_direct, 64);\n\n\n\n avctx->coded_frame = &s->picture;\n\n s->avctx = avctx;\n\n avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;\n\n\n\n return 0;\n\n}", + "output": "1", + "index": 1379 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point_transform){\n\n int i, mb_x, mb_y;\n\n const int nb_components=3;\n\n\n\n for(mb_y = 0; mb_y < s->mb_height; mb_y++) {\n\n for(mb_x = 0; mb_x < s->mb_width; mb_x++) {\n\n if (s->restart_interval && !s->restart_count)\n\n s->restart_count = s->restart_interval;\n\n\n\n if(mb_x==0 || mb_y==0 || s->interlaced){\n\n for(i=0;inb_blocks[i];\n\n c = s->comp_index[i];\n\n h = s->h_scount[i];\n\n v = s->v_scount[i];\n\n x = 0;\n\n y = 0;\n\n linesize= s->linesize[c];\n\n\n\n for(j=0; jpicture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap\n\n if(y==0 && mb_y==0){\n\n if(x==0 && mb_x==0){\n\n pred= 128 << point_transform;\n\n }else{\n\n pred= ptr[-1];\n\n }\n\n }else{\n\n if(x==0 && mb_x==0){\n\n pred= ptr[-linesize];\n\n }else{\n\n PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);\n\n }\n\n }\n\n\n\n if (s->interlaced && s->bottom_field)\n\n ptr += linesize >> 1;\n\n *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);\n\n\n\n if (++x == h) {\n\n x = 0;\n\n y++;\n\n }\n\n }\n\n }\n\n }else{\n\n for(i=0;inb_blocks[i];\n\n c = s->comp_index[i];\n\n h = s->h_scount[i];\n\n v = s->v_scount[i];\n\n x = 0;\n\n y = 0;\n\n linesize= s->linesize[c];\n\n\n\n for(j=0; jpicture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap\n\n PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);\n\n *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);\n\n if (++x == h) {\n\n x = 0;\n\n y++;\n\n }\n\n }\n\n }\n\n }\n\n if (s->restart_interval && !--s->restart_count) {\n\n align_get_bits(&s->gb);\n\n skip_bits(&s->gb, 16); /* skip RSTn */\n\n }\n\n }\n\n }\n\n return 0;\n\n}\n", + "output": "0", + "index": 20121 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt,\n\n uint8_t block_type, AVFormatContext *s)\n\n{\n\n uint8_t * vidbuf_start = NULL;\n\n int vidbuf_nbytes = 0;\n\n int code;\n\n int bytes_copied = 0;\n\n int position, duration, npixels;\n\n unsigned int vidbuf_capacity;\n\n int ret = 0;\n\n AVStream *st;\n\n\n\n if (vid->video_index < 0) {\n\n st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n vid->video_index = st->index;\n\n if (vid->audio_index < 0) {\n\n av_log_ask_for_sample(s, \"No audio packet before first video \"\n\n \"packet. Using default video time base.\\n\");\n\n }\n\n avpriv_set_pts_info(st, 64, 185, vid->sample_rate);\n\n st->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n\n st->codec->codec_id = AV_CODEC_ID_BETHSOFTVID;\n\n st->codec->width = vid->width;\n\n st->codec->height = vid->height;\n\n }\n\n st = s->streams[vid->video_index];\n\n npixels = st->codec->width * st->codec->height;\n\n\n\n vidbuf_start = av_malloc(vidbuf_capacity = BUFFER_PADDING_SIZE);\n\n if(!vidbuf_start)\n\n return AVERROR(ENOMEM);\n\n\n\n // save the file position for the packet, include block type\n\n position = avio_tell(pb) - 1;\n\n\n\n vidbuf_start[vidbuf_nbytes++] = block_type;\n\n\n\n // get the current packet duration\n\n duration = vid->bethsoft_global_delay + avio_rl16(pb);\n\n\n\n // set the y offset if it exists (decoder header data should be in data section)\n\n if(block_type == VIDEO_YOFF_P_FRAME){\n\n if (avio_read(pb, &vidbuf_start[vidbuf_nbytes], 2) != 2) {\n\n ret = AVERROR(EIO);\n\n goto fail;\n\n }\n\n vidbuf_nbytes += 2;\n\n }\n\n\n\n do{\n\n vidbuf_start = av_fast_realloc(vidbuf_start, &vidbuf_capacity, vidbuf_nbytes + BUFFER_PADDING_SIZE);\n\n if(!vidbuf_start)\n\n return AVERROR(ENOMEM);\n\n\n\n code = avio_r8(pb);\n\n vidbuf_start[vidbuf_nbytes++] = code;\n\n\n\n if(code >= 0x80){ // rle sequence\n\n if(block_type == VIDEO_I_FRAME)\n\n vidbuf_start[vidbuf_nbytes++] = avio_r8(pb);\n\n } else if(code){ // plain sequence\n\n if (avio_read(pb, &vidbuf_start[vidbuf_nbytes], code) != code) {\n\n ret = AVERROR(EIO);\n\n goto fail;\n\n }\n\n vidbuf_nbytes += code;\n\n }\n\n bytes_copied += code & 0x7F;\n\n if(bytes_copied == npixels){ // sometimes no stop character is given, need to keep track of bytes copied\n\n // may contain a 0 byte even if read all pixels\n\n if(avio_r8(pb))\n\n avio_seek(pb, -1, SEEK_CUR);\n\n break;\n\n }\n\n if (bytes_copied > npixels) {\n\n ret = AVERROR_INVALIDDATA;\n\n goto fail;\n\n }\n\n } while(code);\n\n\n\n // copy data into packet\n\n if ((ret = av_new_packet(pkt, vidbuf_nbytes)) < 0)\n\n goto fail;\n\n memcpy(pkt->data, vidbuf_start, vidbuf_nbytes);\n\n av_free(vidbuf_start);\n\n\n\n pkt->pos = position;\n\n pkt->stream_index = vid->video_index;\n\n pkt->duration = duration;\n\n if (block_type == VIDEO_I_FRAME)\n\n pkt->flags |= AV_PKT_FLAG_KEY;\n\n\n\n /* if there is a new palette available, add it to packet side data */\n\n if (vid->palette) {\n\n uint8_t *pdata = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,\n\n BVID_PALETTE_SIZE);\n\n memcpy(pdata, vid->palette, BVID_PALETTE_SIZE);\n\n av_freep(&vid->palette);\n\n }\n\n\n\n vid->nframes--; // used to check if all the frames were read\n\n return 0;\n\nfail:\n\n av_free(vidbuf_start);\n\n return ret;\n\n}\n", + "output": "1", + "index": 14001 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int open_f(BlockBackend *blk, int argc, char **argv)\n\n{\n\n int flags = BDRV_O_UNMAP;\n\n int readonly = 0;\n\n bool writethrough = true;\n\n int c;\n\n QemuOpts *qopts;\n\n QDict *opts;\n\n bool force_share = false;\n\n\n\n while ((c = getopt(argc, argv, \"snro:kt:d:U\")) != -1) {\n\n switch (c) {\n\n case 's':\n\n flags |= BDRV_O_SNAPSHOT;\n\n break;\n\n case 'n':\n\n flags |= BDRV_O_NOCACHE;\n\n writethrough = false;\n\n break;\n\n case 'r':\n\n readonly = 1;\n\n break;\n\n case 'k':\n\n flags |= BDRV_O_NATIVE_AIO;\n\n break;\n\n case 't':\n\n if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) {\n\n error_report(\"Invalid cache option: %s\", optarg);\n\n qemu_opts_reset(&empty_opts);\n\n return 0;\n\n }\n\n break;\n\n case 'd':\n\n if (bdrv_parse_discard_flags(optarg, &flags) < 0) {\n\n error_report(\"Invalid discard option: %s\", optarg);\n\n qemu_opts_reset(&empty_opts);\n\n return 0;\n\n }\n\n break;\n\n case 'o':\n\n if (imageOpts) {\n\n printf(\"--image-opts and 'open -o' are mutually exclusive\\n\");\n\n qemu_opts_reset(&empty_opts);\n\n return 0;\n\n }\n\n if (!qemu_opts_parse_noisily(&empty_opts, optarg, false)) {\n\n qemu_opts_reset(&empty_opts);\n\n return 0;\n\n }\n\n break;\n\n case 'U':\n\n force_share = true;\n\n break;\n\n default:\n\n qemu_opts_reset(&empty_opts);\n\n return qemuio_command_usage(&open_cmd);\n\n }\n\n }\n\n\n\n if (!readonly) {\n\n flags |= BDRV_O_RDWR;\n\n }\n\n\n\n if (imageOpts && (optind == argc - 1)) {\n\n if (!qemu_opts_parse_noisily(&empty_opts, argv[optind], false)) {\n\n qemu_opts_reset(&empty_opts);\n\n return 0;\n\n }\n\n optind++;\n\n }\n\n\n\n qopts = qemu_opts_find(&empty_opts, NULL);\n\n opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;\n\n qemu_opts_reset(&empty_opts);\n\n\n\n if (optind == argc - 1) {\n\n openfile(argv[optind], flags, writethrough, force_share, opts);\n\n } else if (optind == argc) {\n\n openfile(NULL, flags, writethrough, force_share, opts);\n\n } else {\n\n QDECREF(opts);\n\n qemuio_command_usage(&open_cmd);\n\n }\n\n return 0;\n\n}\n", + "output": "0", + "index": 23460 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void h264_loop_filter_luma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta)\n\n{\n\n int d;\n\n for( d = 0; d < 16; d++ ) {\n\n const int p2 = pix[-3*xstride];\n\n const int p1 = pix[-2*xstride];\n\n const int p0 = pix[-1*xstride];\n\n\n\n const int q0 = pix[ 0*xstride];\n\n const int q1 = pix[ 1*xstride];\n\n const int q2 = pix[ 2*xstride];\n\n\n\n if( FFABS( p0 - q0 ) < alpha &&\n\n FFABS( p1 - p0 ) < beta &&\n\n FFABS( q1 - q0 ) < beta ) {\n\n\n\n if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){\n\n if( FFABS( p2 - p0 ) < beta)\n\n {\n\n const int p3 = pix[-4*xstride];\n\n /* p0', p1', p2' */\n\n pix[-1*xstride] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;\n\n pix[-2*xstride] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;\n\n pix[-3*xstride] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;\n\n } else {\n\n /* p0' */\n\n pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;\n\n }\n\n if( FFABS( q2 - q0 ) < beta)\n\n {\n\n const int q3 = pix[3*xstride];\n\n /* q0', q1', q2' */\n\n pix[0*xstride] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;\n\n pix[1*xstride] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;\n\n pix[2*xstride] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;\n\n } else {\n\n /* q0' */\n\n pix[0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2;\n\n }\n\n }else{\n\n /* p0', q0' */\n\n pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2;\n\n pix[ 0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2;\n\n }\n\n }\n\n pix += ystride;\n\n }\n\n}\n", + "output": "0", + "index": 2934 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void pxb_dev_realize_common(PCIDevice *dev, bool pcie, Error **errp)\n\n{\n\n PXBDev *pxb = convert_to_pxb(dev);\n\n DeviceState *ds, *bds = NULL;\n\n PCIBus *bus;\n\n const char *dev_name = NULL;\n\n Error *local_err = NULL;\n\n\n\n if (pxb->numa_node != NUMA_NODE_UNASSIGNED &&\n\n pxb->numa_node >= nb_numa_nodes) {\n\n error_setg(errp, \"Illegal numa node %d\", pxb->numa_node);\n\n return;\n\n }\n\n\n\n if (dev->qdev.id && *dev->qdev.id) {\n\n dev_name = dev->qdev.id;\n\n }\n\n\n\n ds = qdev_create(NULL, TYPE_PXB_HOST);\n\n if (pcie) {\n\n bus = pci_root_bus_new(ds, dev_name, NULL, NULL, 0, TYPE_PXB_PCIE_BUS);\n\n } else {\n\n bus = pci_root_bus_new(ds, \"pxb-internal\", NULL, NULL, 0, TYPE_PXB_BUS);\n\n bds = qdev_create(BUS(bus), \"pci-bridge\");\n\n bds->id = dev_name;\n\n qdev_prop_set_uint8(bds, PCI_BRIDGE_DEV_PROP_CHASSIS_NR, pxb->bus_nr);\n\n qdev_prop_set_bit(bds, PCI_BRIDGE_DEV_PROP_SHPC, false);\n\n }\n\n\n\n bus->parent_dev = dev;\n\n bus->address_space_mem = dev->bus->address_space_mem;\n\n bus->address_space_io = dev->bus->address_space_io;\n\n bus->map_irq = pxb_map_irq_fn;\n\n\n\n PCI_HOST_BRIDGE(ds)->bus = bus;\n\n\n\n pxb_register_bus(dev, bus, &local_err);\n\n if (local_err) {\n\n error_propagate(errp, local_err);\n\n goto err_register_bus;\n\n }\n\n\n\n qdev_init_nofail(ds);\n\n if (bds) {\n\n qdev_init_nofail(bds);\n\n }\n\n\n\n pci_word_test_and_set_mask(dev->config + PCI_STATUS,\n\n PCI_STATUS_66MHZ | PCI_STATUS_FAST_BACK);\n\n pci_config_set_class(dev->config, PCI_CLASS_BRIDGE_HOST);\n\n\n\n pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);\n\n return;\n\n\n\nerr_register_bus:\n\n object_unref(OBJECT(bds));\n\n object_unparent(OBJECT(bus));\n\n object_unref(OBJECT(ds));\n\n}\n", + "output": "0", + "index": 14529 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int intel_h263_decode_picture_header(MpegEncContext *s)\n\n{\n\n int format;\n\n\n\n /* picture header */\n\n if (get_bits_long(&s->gb, 22) != 0x20) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"Bad picture start code\\n\");\n\n return -1;\n\n }\n\n s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */\n\n\n\n if (get_bits1(&s->gb) != 1) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"Bad marker\\n\");\n\n return -1;\t/* marker */\n\n }\n\n if (get_bits1(&s->gb) != 0) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"Bad H263 id\\n\");\n\n return -1;\t/* h263 id */\n\n }\n\n skip_bits1(&s->gb);\t/* split screen off */\n\n skip_bits1(&s->gb);\t/* camera off */\n\n skip_bits1(&s->gb);\t/* freeze picture release off */\n\n\n\n format = get_bits(&s->gb, 3);\n\n if (format != 7) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"Intel H263 free format not supported\\n\");\n\n return -1;\n\n }\n\n s->h263_plus = 0;\n\n\n\n s->pict_type = I_TYPE + get_bits1(&s->gb);\n\n \n\n s->unrestricted_mv = get_bits1(&s->gb); \n\n s->h263_long_vectors = s->unrestricted_mv;\n\n\n\n if (get_bits1(&s->gb) != 0) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"SAC not supported\\n\");\n\n return -1;\t/* SAC: off */\n\n }\n\n if (get_bits1(&s->gb) != 0) {\n\n s->obmc= 1;\n\n av_log(s->avctx, AV_LOG_ERROR, \"Advanced Prediction Mode not supported\\n\");\n\n// return -1;\t/* advanced prediction mode: off */\n\n }\n\n if (get_bits1(&s->gb) != 0) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"PB frame mode no supported\\n\");\n\n return -1;\t/* PB frame mode */\n\n }\n\n\n\n /* skip unknown header garbage */\n\n skip_bits(&s->gb, 41);\n\n\n\n s->qscale = get_bits(&s->gb, 5);\n\n skip_bits1(&s->gb);\t/* Continuous Presence Multipoint mode: off */\n\n\n\n /* PEI */\n\n while (get_bits1(&s->gb) != 0) {\n\n skip_bits(&s->gb, 8);\n\n }\n\n s->f_code = 1;\n\n\n\n s->y_dc_scale_table=\n\n s->c_dc_scale_table= ff_mpeg1_dc_scale_table;\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 16020 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,\n\n uint64_t bytes, QEMUIOVector *qiov)\n\n{\n\n BDRVQcow2State *s = bs->opaque;\n\n QEMUIOVector hd_qiov;\n\n struct iovec iov;\n\n z_stream strm;\n\n int ret, out_len;\n\n uint8_t *buf, *out_buf;\n\n uint64_t cluster_offset;\n\n\n\n if (bytes == 0) {\n\n /* align end of file to a sector boundary to ease reading with\n\n sector based I/Os */\n\n cluster_offset = bdrv_getlength(bs->file->bs);\n\n return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, NULL);\n\n }\n\n\n\n buf = qemu_blockalign(bs, s->cluster_size);\n\n if (bytes != s->cluster_size) {\n\n if (bytes > s->cluster_size ||\n\n offset + bytes != bs->total_sectors << BDRV_SECTOR_BITS)\n\n {\n\n qemu_vfree(buf);\n\n return -EINVAL;\n\n }\n\n /* Zero-pad last write if image size is not cluster aligned */\n\n memset(buf + bytes, 0, s->cluster_size - bytes);\n\n }\n\n qemu_iovec_to_buf(qiov, 0, buf, bytes);\n\n\n\n out_buf = g_malloc(s->cluster_size);\n\n\n\n /* best compression, small window, no zlib header */\n\n memset(&strm, 0, sizeof(strm));\n\n ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION,\n\n Z_DEFLATED, -12,\n\n 9, Z_DEFAULT_STRATEGY);\n\n if (ret != 0) {\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n\n\n strm.avail_in = s->cluster_size;\n\n strm.next_in = (uint8_t *)buf;\n\n strm.avail_out = s->cluster_size;\n\n strm.next_out = out_buf;\n\n\n\n ret = deflate(&strm, Z_FINISH);\n\n if (ret != Z_STREAM_END && ret != Z_OK) {\n\n deflateEnd(&strm);\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n out_len = strm.next_out - out_buf;\n\n\n\n deflateEnd(&strm);\n\n\n\n if (ret != Z_STREAM_END || out_len >= s->cluster_size) {\n\n /* could not compress: write normal cluster */\n\n ret = qcow2_co_pwritev(bs, offset, bytes, qiov, 0);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n goto success;\n\n }\n\n\n\n qemu_co_mutex_lock(&s->lock);\n\n cluster_offset =\n\n qcow2_alloc_compressed_cluster_offset(bs, offset, out_len);\n\n if (!cluster_offset) {\n\n qemu_co_mutex_unlock(&s->lock);\n\n ret = -EIO;\n\n goto fail;\n\n }\n\n cluster_offset &= s->cluster_offset_mask;\n\n\n\n ret = qcow2_pre_write_overlap_check(bs, 0, cluster_offset, out_len);\n\n qemu_co_mutex_unlock(&s->lock);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n iov = (struct iovec) {\n\n .iov_base = out_buf,\n\n .iov_len = out_len,\n\n };\n\n qemu_iovec_init_external(&hd_qiov, &iov, 1);\n\n\n\n BLKDBG_EVENT(bs->file, BLKDBG_WRITE_COMPRESSED);\n\n ret = bdrv_co_pwritev(bs->file, cluster_offset, out_len, &hd_qiov, 0);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\nsuccess:\n\n ret = 0;\n\nfail:\n\n qemu_vfree(buf);\n\n g_free(out_buf);\n\n return ret;\n\n}\n", + "output": "1", + "index": 2213 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static AVStream *new_pes_av_stream(PESContext *pes, uint32_t prog_reg_desc, uint32_t code)\n\n{\n\n AVStream *st = av_new_stream(pes->stream, pes->pid);\n\n\n\n if (!st)\n\n return NULL;\n\n\n\n av_set_pts_info(st, 33, 1, 90000);\n\n st->priv_data = pes;\n\n st->codec->codec_type = CODEC_TYPE_DATA;\n\n st->codec->codec_id = CODEC_ID_NONE;\n\n st->need_parsing = AVSTREAM_PARSE_FULL;\n\n pes->st = st;\n\n\n\n dprintf(pes->stream, \"stream_type=%x pid=%x prog_reg_desc=%.4s\\n\",\n\n pes->stream_type, pes->pid, (char*)&prog_reg_desc);\n\n\n\n st->codec->codec_tag = pes->stream_type;\n\n\n\n mpegts_find_stream_type(st, pes->stream_type, ISO_types);\n\n if (prog_reg_desc == AV_RL32(\"HDMV\") &&\n\n st->codec->codec_id == CODEC_ID_NONE) {\n\n mpegts_find_stream_type(st, pes->stream_type, HDMV_types);\n\n if (pes->stream_type == 0x83) {\n\n // HDMV TrueHD streams also contain an AC3 coded version of the\n\n // audio track - add a second stream for this\n\n AVStream *sub_st;\n\n // priv_data cannot be shared between streams\n\n PESContext *sub_pes = av_malloc(sizeof(*sub_pes));\n\n if (!sub_pes)\n\n return NULL;\n\n memcpy(sub_pes, pes, sizeof(*sub_pes));\n\n\n\n sub_st = av_new_stream(pes->stream, pes->pid);\n\n if (!sub_st) {\n\n av_free(sub_pes);\n\n return NULL;\n\n }\n\n\n\n av_set_pts_info(sub_st, 33, 1, 90000);\n\n sub_st->priv_data = sub_pes;\n\n sub_st->codec->codec_type = CODEC_TYPE_AUDIO;\n\n sub_st->codec->codec_id = CODEC_ID_AC3;\n\n sub_st->need_parsing = AVSTREAM_PARSE_FULL;\n\n sub_pes->sub_st = pes->sub_st = sub_st;\n\n }\n\n }\n\n if (st->codec->codec_id == CODEC_ID_NONE)\n\n mpegts_find_stream_type(st, pes->stream_type, MISC_types);\n\n\n\n /* stream was not present in PMT, guess based on PES start code */\n\n if (st->codec->codec_id == CODEC_ID_NONE) {\n\n if (code >= 0x1c0 && code <= 0x1df) {\n\n st->codec->codec_type = CODEC_TYPE_AUDIO;\n\n st->codec->codec_id = CODEC_ID_MP2;\n\n } else if (code == 0x1bd) {\n\n st->codec->codec_type = CODEC_TYPE_AUDIO;\n\n st->codec->codec_id = CODEC_ID_AC3;\n\n }\n\n }\n\n\n\n return st;\n\n}\n", + "output": "0", + "index": 16897 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void armv7m_nvic_set_pending(void *opaque, int irq)\n\n{\n\n NVICState *s = (NVICState *)opaque;\n\n VecInfo *vec;\n\n\n\n assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);\n\n\n\n vec = &s->vectors[irq];\n\n trace_nvic_set_pending(irq, vec->enabled, vec->prio);\n\n\n\n\n\n if (irq >= ARMV7M_EXCP_HARD && irq < ARMV7M_EXCP_PENDSV) {\n\n /* If a synchronous exception is pending then it may be\n\n * escalated to HardFault if:\n\n * * it is equal or lower priority to current execution\n\n * * it is disabled\n\n * (ie we need to take it immediately but we can't do so).\n\n * Asynchronous exceptions (and interrupts) simply remain pending.\n\n *\n\n * For QEMU, we don't have any imprecise (asynchronous) faults,\n\n * so we can assume that PREFETCH_ABORT and DATA_ABORT are always\n\n * synchronous.\n\n * Debug exceptions are awkward because only Debug exceptions\n\n * resulting from the BKPT instruction should be escalated,\n\n * but we don't currently implement any Debug exceptions other\n\n * than those that result from BKPT, so we treat all debug exceptions\n\n * as needing escalation.\n\n *\n\n * This all means we can identify whether to escalate based only on\n\n * the exception number and don't (yet) need the caller to explicitly\n\n * tell us whether this exception is synchronous or not.\n\n */\n\n int running = nvic_exec_prio(s);\n\n bool escalate = false;\n\n\n\n if (vec->prio >= running) {\n\n trace_nvic_escalate_prio(irq, vec->prio, running);\n\n escalate = true;\n\n } else if (!vec->enabled) {\n\n trace_nvic_escalate_disabled(irq);\n\n escalate = true;\n\n }\n\n\n\n if (escalate) {\n\n if (running < 0) {\n\n /* We want to escalate to HardFault but we can't take a\n\n * synchronous HardFault at this point either. This is a\n\n * Lockup condition due to a guest bug. We don't model\n\n * Lockup, so report via cpu_abort() instead.\n\n */\n\n cpu_abort(&s->cpu->parent_obj,\n\n \"Lockup: can't escalate %d to HardFault \"\n\n \"(current priority %d)\\n\", irq, running);\n\n }\n\n\n\n /* We can do the escalation, so we take HardFault instead */\n\n irq = ARMV7M_EXCP_HARD;\n\n vec = &s->vectors[irq];\n\n s->cpu->env.v7m.hfsr |= R_V7M_HFSR_FORCED_MASK;\n\n }\n\n }\n\n\n\n if (!vec->pending) {\n\n vec->pending = 1;\n\n nvic_irq_update(s);\n\n }\n\n}\n", + "output": "0", + "index": 19255 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void imx_gpt_write(void *opaque, hwaddr offset, uint64_t value,\n\n unsigned size)\n\n{\n\n IMXGPTState *s = IMX_GPT(opaque);\n\n uint32_t oldreg;\n\n uint32_t reg = offset >> 2;\n\n\n\n DPRINTF(\"(%s, value = 0x%08x)\\n\", imx_gpt_reg_name(reg),\n\n (uint32_t)value);\n\n\n\n switch (reg) {\n\n case 0:\n\n oldreg = s->cr;\n\n s->cr = value & ~0x7c14;\n\n if (s->cr & GPT_CR_SWR) { /* force reset */\n\n /* handle the reset */\n\n imx_gpt_reset(DEVICE(s));\n\n } else {\n\n /* set our freq, as the source might have changed */\n\n imx_gpt_set_freq(s);\n\n\n\n if ((oldreg ^ s->cr) & GPT_CR_EN) {\n\n if (s->cr & GPT_CR_EN) {\n\n if (s->cr & GPT_CR_ENMOD) {\n\n s->next_timeout = TIMER_MAX;\n\n ptimer_set_count(s->timer, TIMER_MAX);\n\n imx_gpt_compute_next_timeout(s, false);\n\n }\n\n ptimer_run(s->timer, 1);\n\n } else {\n\n /* stop timer */\n\n ptimer_stop(s->timer);\n\n }\n\n }\n\n }\n\n break;\n\n\n\n case 1: /* Prescaler */\n\n s->pr = value & 0xfff;\n\n imx_gpt_set_freq(s);\n\n break;\n\n\n\n case 2: /* SR */\n\n s->sr &= ~(value & 0x3f);\n\n imx_gpt_update_int(s);\n\n break;\n\n\n\n case 3: /* IR -- interrupt register */\n\n s->ir = value & 0x3f;\n\n imx_gpt_update_int(s);\n\n\n\n imx_gpt_compute_next_timeout(s, false);\n\n\n\n break;\n\n\n\n case 4: /* OCR1 -- output compare register */\n\n s->ocr1 = value;\n\n\n\n /* In non-freerun mode, reset count when this register is written */\n\n if (!(s->cr & GPT_CR_FRR)) {\n\n s->next_timeout = TIMER_MAX;\n\n ptimer_set_limit(s->timer, TIMER_MAX, 1);\n\n }\n\n\n\n /* compute the new timeout */\n\n imx_gpt_compute_next_timeout(s, false);\n\n\n\n break;\n\n\n\n case 5: /* OCR2 -- output compare register */\n\n s->ocr2 = value;\n\n\n\n /* compute the new timeout */\n\n imx_gpt_compute_next_timeout(s, false);\n\n\n\n break;\n\n\n\n case 6: /* OCR3 -- output compare register */\n\n s->ocr3 = value;\n\n\n\n /* compute the new timeout */\n\n imx_gpt_compute_next_timeout(s, false);\n\n\n\n break;\n\n\n\n default:\n\n IPRINTF(\"Bad offset %x\\n\", reg);\n\n break;\n\n }\n\n}\n", + "output": "0", + "index": 17019 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int stpcifc_service_call(S390CPU *cpu, uint8_t r1, uint64_t fiba, uint8_t ar)\n\n{\n\n CPUS390XState *env = &cpu->env;\n\n uint32_t fh;\n\n ZpciFib fib;\n\n S390PCIBusDevice *pbdev;\n\n uint32_t data;\n\n uint64_t cc = ZPCI_PCI_LS_OK;\n\n\n\n if (env->psw.mask & PSW_MASK_PSTATE) {\n\n program_interrupt(env, PGM_PRIVILEGED, 6);\n\n return 0;\n\n }\n\n\n\n fh = env->regs[r1] >> 32;\n\n\n\n if (fiba & 0x7) {\n\n program_interrupt(env, PGM_SPECIFICATION, 6);\n\n return 0;\n\n }\n\n\n\n pbdev = s390_pci_find_dev_by_fh(fh);\n\n if (!pbdev) {\n\n setcc(cpu, ZPCI_PCI_LS_INVAL_HANDLE);\n\n return 0;\n\n }\n\n\n\n memset(&fib, 0, sizeof(fib));\n\n stq_p(&fib.pba, pbdev->pba);\n\n stq_p(&fib.pal, pbdev->pal);\n\n stq_p(&fib.iota, pbdev->g_iota);\n\n stq_p(&fib.aibv, pbdev->routes.adapter.ind_addr);\n\n stq_p(&fib.aisb, pbdev->routes.adapter.summary_addr);\n\n stq_p(&fib.fmb_addr, pbdev->fmb_addr);\n\n\n\n data = ((uint32_t)pbdev->isc << 28) | ((uint32_t)pbdev->noi << 16) |\n\n ((uint32_t)pbdev->routes.adapter.ind_offset << 8) |\n\n ((uint32_t)pbdev->sum << 7) | pbdev->routes.adapter.summary_offset;\n\n stl_p(&fib.data, data);\n\n\n\n if (pbdev->fh & FH_MASK_ENABLE) {\n\n fib.fc |= 0x80;\n\n }\n\n\n\n if (pbdev->error_state) {\n\n fib.fc |= 0x40;\n\n }\n\n\n\n if (pbdev->lgstg_blocked) {\n\n fib.fc |= 0x20;\n\n }\n\n\n\n if (pbdev->g_iota) {\n\n fib.fc |= 0x10;\n\n }\n\n\n\n if (s390_cpu_virt_mem_write(cpu, fiba, ar, (uint8_t *)&fib, sizeof(fib))) {\n\n return 0;\n\n }\n\n\n\n setcc(cpu, cc);\n\n return 0;\n\n}\n", + "output": "0", + "index": 22289 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,\n\n tcg_target_long arg, bool in_prologue)\n\n{\n\n intptr_t tb_diff;\n\n tcg_target_long tmp;\n\n int shift;\n\n\n\n tcg_debug_assert(TCG_TARGET_REG_BITS == 64 || type == TCG_TYPE_I32);\n\n\n\n if (TCG_TARGET_REG_BITS == 64 && type == TCG_TYPE_I32) {\n\n arg = (int32_t)arg;\n\n }\n\n\n\n /* Load 16-bit immediates with one insn. */\n\n if (tcg_out_movi_one(s, ret, arg)) {\n\n return;\n\n }\n\n\n\n /* Load addresses within the TB with one insn. */\n\n tb_diff = arg - (intptr_t)s->code_gen_ptr;\n\n if (!in_prologue && USE_REG_TB && tb_diff == (int16_t)tb_diff) {\n\n tcg_out32(s, ADDI | TAI(ret, TCG_REG_TB, tb_diff));\n\n return;\n\n }\n\n\n\n /* Load 32-bit immediates with two insns. Note that we've already\n\n eliminated bare ADDIS, so we know both insns are required. */\n\n if (TCG_TARGET_REG_BITS == 32 || arg == (int32_t)arg) {\n\n tcg_out32(s, ADDIS | TAI(ret, 0, arg >> 16));\n\n tcg_out32(s, ORI | SAI(ret, ret, arg));\n\n return;\n\n }\n\n if (arg == (uint32_t)arg && !(arg & 0x8000)) {\n\n tcg_out32(s, ADDI | TAI(ret, 0, arg));\n\n tcg_out32(s, ORIS | SAI(ret, ret, arg >> 16));\n\n return;\n\n }\n\n\n\n /* Load masked 16-bit value. */\n\n if (arg > 0 && (arg & 0x8000)) {\n\n tmp = arg | 0x7fff;\n\n if ((tmp & (tmp + 1)) == 0) {\n\n int mb = clz64(tmp + 1) + 1;\n\n tcg_out32(s, ADDI | TAI(ret, 0, arg));\n\n tcg_out_rld(s, RLDICL, ret, ret, 0, mb);\n\n return;\n\n }\n\n }\n\n\n\n /* Load common masks with 2 insns. */\n\n shift = ctz64(arg);\n\n tmp = arg >> shift;\n\n if (tmp == (int16_t)tmp) {\n\n tcg_out32(s, ADDI | TAI(ret, 0, tmp));\n\n tcg_out_shli64(s, ret, ret, shift);\n\n return;\n\n }\n\n shift = clz64(arg);\n\n if (tcg_out_movi_one(s, ret, arg << shift)) {\n\n tcg_out_shri64(s, ret, ret, shift);\n\n return;\n\n }\n\n\n\n /* Load addresses within 2GB of TB with 2 (or rarely 3) insns. */\n\n if (!in_prologue && USE_REG_TB && tb_diff == (int32_t)tb_diff) {\n\n tcg_out_mem_long(s, ADDI, ADD, ret, TCG_REG_TB, tb_diff);\n\n return;\n\n }\n\n\n\n /* Use the constant pool, if possible. */\n\n if (!in_prologue && USE_REG_TB) {\n\n new_pool_label(s, arg, R_PPC_ADDR16, s->code_ptr,\n\n -(intptr_t)s->code_gen_ptr);\n\n tcg_out32(s, LD | TAI(ret, TCG_REG_TB, 0));\n\n return;\n\n }\n\n\n\n tmp = arg >> 31 >> 1;\n\n tcg_out_movi(s, TCG_TYPE_I32, ret, tmp);\n\n if (tmp) {\n\n tcg_out_shli64(s, ret, ret, 32);\n\n }\n\n if (arg & 0xffff0000) {\n\n tcg_out32(s, ORIS | SAI(ret, ret, arg >> 16));\n\n }\n\n if (arg & 0xffff) {\n\n tcg_out32(s, ORI | SAI(ret, ret, arg));\n\n }\n\n}\n", + "output": "1", + "index": 6204 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold int hevc_decode_free(AVCodecContext *avctx)\n\n{\n\n HEVCContext *s = avctx->priv_data;\n\n HEVCLocalContext *lc = s->HEVClc;\n\n int i;\n\n\n\n pic_arrays_free(s);\n\n\n\n av_freep(&s->md5_ctx);\n\n\n\n for(i=0; i < s->nals_allocated; i++) {\n\n av_freep(&s->skipped_bytes_pos_nal[i]);\n\n }\n\n av_freep(&s->skipped_bytes_pos_size_nal);\n\n av_freep(&s->skipped_bytes_nal);\n\n av_freep(&s->skipped_bytes_pos_nal);\n\n\n\n av_freep(&s->cabac_state);\n\n\n\n av_frame_free(&s->tmp_frame);\n\n av_frame_free(&s->output_frame);\n\n\n\n for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {\n\n ff_hevc_unref_frame(s, &s->DPB[i], ~0);\n\n av_frame_free(&s->DPB[i].frame);\n\n }\n\n\n\n for (i = 0; i < FF_ARRAY_ELEMS(s->vps_list); i++)\n\n av_buffer_unref(&s->vps_list[i]);\n\n for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++)\n\n av_buffer_unref(&s->sps_list[i]);\n\n for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)\n\n av_buffer_unref(&s->pps_list[i]);\n\n s->sps = NULL;\n\n s->pps = NULL;\n\n s->vps = NULL;\n\n\n\n av_buffer_unref(&s->current_sps);\n\n\n\n av_freep(&s->sh.entry_point_offset);\n\n av_freep(&s->sh.offset);\n\n av_freep(&s->sh.size);\n\n\n\n for (i = 1; i < s->threads_number; i++) {\n\n lc = s->HEVClcList[i];\n\n if (lc) {\n\n av_freep(&s->HEVClcList[i]);\n\n av_freep(&s->sList[i]);\n\n }\n\n }\n\n if (s->HEVClc == s->HEVClcList[0])\n\n s->HEVClc = NULL;\n\n av_freep(&s->HEVClcList[0]);\n\n\n\n for (i = 0; i < s->nals_allocated; i++)\n\n av_freep(&s->nals[i].rbsp_buffer);\n\n av_freep(&s->nals);\n\n s->nals_allocated = 0;\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 2105 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int msrle_decode_frame(AVCodecContext *avctx,\n\n void *data, int *got_frame,\n\n AVPacket *avpkt)\n\n{\n\n const uint8_t *buf = avpkt->data;\n\n int buf_size = avpkt->size;\n\n MsrleContext *s = avctx->priv_data;\n\n int istride = FFALIGN(avctx->width*avctx->bits_per_coded_sample, 32) / 8;\n\n int ret;\n\n\n\n s->buf = buf;\n\n s->size = buf_size;\n\n\n\n if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)\n\n return ret;\n\n\n\n if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) {\n\n const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);\n\n\n\n if (pal) {\n\n s->frame->palette_has_changed = 1;\n\n memcpy(s->pal, pal, AVPALETTE_SIZE);\n\n }\n\n /* make the palette available */\n\n memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE);\n\n }\n\n\n\n /* FIXME how to correctly detect RLE ??? */\n\n if (avctx->height * istride == avpkt->size) { /* assume uncompressed */\n\n int linesize = (avctx->width * avctx->bits_per_coded_sample + 7) / 8;\n\n uint8_t *ptr = s->frame->data[0];\n\n uint8_t *buf = avpkt->data + (avctx->height-1)*istride;\n\n int i, j;\n\n\n\n for (i = 0; i < avctx->height; i++) {\n\n if (avctx->bits_per_coded_sample == 4) {\n\n for (j = 0; j < avctx->width - 1; j += 2) {\n\n ptr[j+0] = buf[j>>1] >> 4;\n\n ptr[j+1] = buf[j>>1] & 0xF;\n\n }\n\n if (avctx->width & 1)\n\n ptr[j+0] = buf[j>>1] >> 4;\n\n } else {\n\n memcpy(ptr, buf, linesize);\n\n }\n\n buf -= istride;\n\n ptr += s->frame->linesize[0];\n\n }\n\n } else {\n\n bytestream2_init(&s->gb, buf, buf_size);\n\n ff_msrle_decode(avctx, (AVPicture*)s->frame, avctx->bits_per_coded_sample, &s->gb);\n\n }\n\n\n\n if ((ret = av_frame_ref(data, s->frame)) < 0)\n\n return ret;\n\n\n\n *got_frame = 1;\n\n\n\n /* report that the buffer was completely consumed */\n\n return buf_size;\n\n}\n", + "output": "0", + "index": 21717 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "qemu_irq *mpic_init (target_phys_addr_t base, int nb_cpus,\n\n qemu_irq **irqs, qemu_irq irq_out)\n\n{\n\n openpic_t *mpp;\n\n int i;\n\n struct {\n\n CPUReadMemoryFunc * const *read;\n\n CPUWriteMemoryFunc * const *write;\n\n target_phys_addr_t start_addr;\n\n ram_addr_t size;\n\n } const list[] = {\n\n {mpic_glb_read, mpic_glb_write, MPIC_GLB_REG_START, MPIC_GLB_REG_SIZE},\n\n {mpic_tmr_read, mpic_tmr_write, MPIC_TMR_REG_START, MPIC_TMR_REG_SIZE},\n\n {mpic_ext_read, mpic_ext_write, MPIC_EXT_REG_START, MPIC_EXT_REG_SIZE},\n\n {mpic_int_read, mpic_int_write, MPIC_INT_REG_START, MPIC_INT_REG_SIZE},\n\n {mpic_msg_read, mpic_msg_write, MPIC_MSG_REG_START, MPIC_MSG_REG_SIZE},\n\n {mpic_msi_read, mpic_msi_write, MPIC_MSI_REG_START, MPIC_MSI_REG_SIZE},\n\n {mpic_cpu_read, mpic_cpu_write, MPIC_CPU_REG_START, MPIC_CPU_REG_SIZE},\n\n };\n\n\n\n /* XXX: for now, only one CPU is supported */\n\n if (nb_cpus != 1)\n\n return NULL;\n\n\n\n mpp = g_malloc0(sizeof(openpic_t));\n\n\n\n for (i = 0; i < sizeof(list)/sizeof(list[0]); i++) {\n\n int mem_index;\n\n\n\n mem_index = cpu_register_io_memory(list[i].read, list[i].write, mpp,\n\n DEVICE_BIG_ENDIAN);\n\n if (mem_index < 0) {\n\n goto free;\n\n }\n\n cpu_register_physical_memory(base + list[i].start_addr,\n\n list[i].size, mem_index);\n\n }\n\n\n\n mpp->nb_cpus = nb_cpus;\n\n mpp->max_irq = MPIC_MAX_IRQ;\n\n mpp->irq_ipi0 = MPIC_IPI_IRQ;\n\n mpp->irq_tim0 = MPIC_TMR_IRQ;\n\n\n\n for (i = 0; i < nb_cpus; i++)\n\n mpp->dst[i].irqs = irqs[i];\n\n mpp->irq_out = irq_out;\n\n\n\n mpp->irq_raise = mpic_irq_raise;\n\n mpp->reset = mpic_reset;\n\n\n\n register_savevm(NULL, \"mpic\", 0, 2, openpic_save, openpic_load, mpp);\n\n qemu_register_reset(mpic_reset, mpp);\n\n\n\n return qemu_allocate_irqs(openpic_set_irq, mpp, mpp->max_irq);\n\n\n\nfree:\n\n g_free(mpp);\n\n return NULL;\n\n}\n", + "output": "1", + "index": 9513 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int vc1_init_common(VC1Context *v)\n\n{\n\n static int done = 0;\n\n int i = 0;\n\n\n\n v->hrd_rate = v->hrd_buffer = NULL;\n\n\n\n /* VLC tables */\n\n if(!done)\n\n {\n\n done = 1;\n\n init_vlc(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23,\n\n ff_vc1_bfraction_bits, 1, 1,\n\n ff_vc1_bfraction_codes, 1, 1, INIT_VLC_USE_STATIC);\n\n init_vlc(&ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4,\n\n ff_vc1_norm2_bits, 1, 1,\n\n ff_vc1_norm2_codes, 1, 1, INIT_VLC_USE_STATIC);\n\n init_vlc(&ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64,\n\n ff_vc1_norm6_bits, 1, 1,\n\n ff_vc1_norm6_codes, 2, 2, INIT_VLC_USE_STATIC);\n\n init_vlc(&ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7,\n\n ff_vc1_imode_bits, 1, 1,\n\n ff_vc1_imode_codes, 1, 1, INIT_VLC_USE_STATIC);\n\n for (i=0; i<3; i++)\n\n {\n\n init_vlc(&ff_vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16,\n\n ff_vc1_ttmb_bits[i], 1, 1,\n\n ff_vc1_ttmb_codes[i], 2, 2, INIT_VLC_USE_STATIC);\n\n init_vlc(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8,\n\n ff_vc1_ttblk_bits[i], 1, 1,\n\n ff_vc1_ttblk_codes[i], 1, 1, INIT_VLC_USE_STATIC);\n\n init_vlc(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15,\n\n ff_vc1_subblkpat_bits[i], 1, 1,\n\n ff_vc1_subblkpat_codes[i], 1, 1, INIT_VLC_USE_STATIC);\n\n }\n\n for(i=0; i<4; i++)\n\n {\n\n init_vlc(&ff_vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16,\n\n ff_vc1_4mv_block_pattern_bits[i], 1, 1,\n\n ff_vc1_4mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_STATIC);\n\n init_vlc(&ff_vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64,\n\n ff_vc1_cbpcy_p_bits[i], 1, 1,\n\n ff_vc1_cbpcy_p_codes[i], 2, 2, INIT_VLC_USE_STATIC);\n\n init_vlc(&ff_vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73,\n\n ff_vc1_mv_diff_bits[i], 1, 1,\n\n ff_vc1_mv_diff_codes[i], 2, 2, INIT_VLC_USE_STATIC);\n\n }\n\n for(i=0; i<8; i++)\n\n init_vlc(&ff_vc1_ac_coeff_table[i], AC_VLC_BITS, vc1_ac_sizes[i],\n\n &vc1_ac_tables[i][0][1], 8, 4,\n\n &vc1_ac_tables[i][0][0], 8, 4, INIT_VLC_USE_STATIC);\n\n init_vlc(&ff_msmp4_mb_i_vlc, MB_INTRA_VLC_BITS, 64,\n\n &ff_msmp4_mb_i_table[0][1], 4, 2,\n\n &ff_msmp4_mb_i_table[0][0], 4, 2, INIT_VLC_USE_STATIC);\n\n }\n\n\n\n /* Other defaults */\n\n v->pq = -1;\n\n v->mvrange = 0; /* 7.1.1.18, p80 */\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 5138 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int main(int argc,char* argv[]){\n\n int i, j;\n\n uint64_t sse=0;\n\n uint64_t dev;\n\n FILE *f[2];\n\n uint8_t buf[2][SIZE];\n\n uint64_t psnr;\n\n int len= argc<4 ? 1 : atoi(argv[3]);\n\n int64_t max= (1<<(8*len))-1;\n\n int shift= argc<5 ? 0 : atoi(argv[4]);\n\n int skip_bytes = argc<6 ? 0 : atoi(argv[5]);\n\n\n\n if(argc<3){\n\n printf(\"tiny_psnr [ [ []]]\\n\");\n\n printf(\"For WAV files use the following:\\n\");\n\n printf(\"./tiny_psnr file1.wav file2.wav 2 0 44 to skip the header.\\n\");\n\n return -1;\n\n }\n\n\n\n f[0]= fopen(argv[1], \"rb\");\n\n f[1]= fopen(argv[2], \"rb\");\n\n if(!f[0] || !f[1]){\n\n fprintf(stderr, \"Could not open input files.\\n\");\n\n return -1;\n\n }\n\n fseek(f[shift<0], shift < 0 ? -shift : shift, SEEK_SET);\n\n\n\n fseek(f[0],skip_bytes,SEEK_CUR);\n\n fseek(f[1],skip_bytes,SEEK_CUR);\n\n\n\n for(i=0;;){\n\n if( fread(buf[0], SIZE, 1, f[0]) != 1) break;\n\n if( fread(buf[1], SIZE, 1, f[1]) != 1) break;\n\n\n\n for(j=0; jmmu_model) {\n\n case POWERPC_MMU_32B:\n\n case POWERPC_MMU_SOFT_6xx:\n\n case POWERPC_MMU_SOFT_74xx:\n\n /* Try to find a BAT */\n\n if (check_BATs)\n\n ret = get_bat(env, ctx, eaddr, rw, access_type);\n\n /* No break here */\n\n#if defined(TARGET_PPC64)\n\n case POWERPC_MMU_64B:\n\n case POWERPC_MMU_64BRIDGE:\n\n#endif\n\n if (ret < 0) {\n\n /* We didn't match any BAT entry or don't have BATs */\n\n ret = get_segment(env, ctx, eaddr, rw, access_type);\n\n }\n\n break;\n\n case POWERPC_MMU_SOFT_4xx:\n\n case POWERPC_MMU_SOFT_4xx_Z:\n\n ret = mmu40x_get_physical_address(env, ctx, eaddr,\n\n rw, access_type);\n\n break;\n\n case POWERPC_MMU_601:\n\n /* XXX: TODO */\n\n cpu_abort(env, \"601 MMU model not implemented\\n\");\n\n return -1;\n\n case POWERPC_MMU_BOOKE:\n\n ret = mmubooke_get_physical_address(env, ctx, eaddr,\n\n rw, access_type);\n\n break;\n\n case POWERPC_MMU_BOOKE_FSL:\n\n /* XXX: TODO */\n\n cpu_abort(env, \"BookE FSL MMU model not implemented\\n\");\n\n return -1;\n\n case POWERPC_MMU_REAL_4xx:\n\n cpu_abort(env, \"PowerPC 401 does not do any translation\\n\");\n\n return -1;\n\n default:\n\n cpu_abort(env, \"Unknown or invalid MMU model\\n\");\n\n return -1;\n\n }\n\n }\n\n#if 0\n\n if (loglevel != 0) {\n\n fprintf(logfile, \"%s address \" ADDRX \" => %d \" PADDRX \"\\n\",\n\n __func__, eaddr, ret, ctx->raddr);\n\n }\n\n#endif\n\n\n\n return ret;\n\n}\n", + "output": "1", + "index": 785 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int h261_decode_picture_header(H261Context *h)\n\n{\n\n MpegEncContext *const s = &h->s;\n\n int format, i;\n\n uint32_t startcode = 0;\n\n\n\n for (i = get_bits_left(&s->gb); i > 24; i -= 1) {\n\n startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;\n\n\n\n if (startcode == 0x10)\n\n break;\n\n }\n\n\n\n if (startcode != 0x10) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"Bad picture start code\\n\");\n\n return -1;\n\n }\n\n\n\n /* temporal reference */\n\n i = get_bits(&s->gb, 5); /* picture timestamp */\n\n if (i < (s->picture_number & 31))\n\n i += 32;\n\n s->picture_number = (s->picture_number & ~31) + i;\n\n\n\n s->avctx->time_base = (AVRational) { 1001, 30000 };\n\n\n\n /* PTYPE starts here */\n\n skip_bits1(&s->gb); /* split screen off */\n\n skip_bits1(&s->gb); /* camera off */\n\n skip_bits1(&s->gb); /* freeze picture release off */\n\n\n\n format = get_bits1(&s->gb);\n\n\n\n // only 2 formats possible\n\n if (format == 0) { // QCIF\n\n s->width = 176;\n\n s->height = 144;\n\n s->mb_width = 11;\n\n s->mb_height = 9;\n\n } else { // CIF\n\n s->width = 352;\n\n s->height = 288;\n\n s->mb_width = 22;\n\n s->mb_height = 18;\n\n }\n\n\n\n s->mb_num = s->mb_width * s->mb_height;\n\n\n\n skip_bits1(&s->gb); /* still image mode off */\n\n skip_bits1(&s->gb); /* Reserved */\n\n\n\n /* PEI */\n\n while (get_bits1(&s->gb) != 0)\n\n skip_bits(&s->gb, 8);\n\n\n\n /* H.261 has no I-frames, but if we pass AV_PICTURE_TYPE_I for the first\n\n * frame, the codec crashes if it does not contain all I-blocks\n\n * (e.g. when a packet is lost). */\n\n s->pict_type = AV_PICTURE_TYPE_P;\n\n\n\n h->gob_number = 0;\n\n return 0;\n\n}\n", + "output": "0", + "index": 15678 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,\n\n const char *model,\n\n const char *name,\n\n int fd, int is_connected)\n\n{\n\n struct sockaddr_in saddr;\n\n int newfd;\n\n socklen_t saddr_len = sizeof(saddr);\n\n NetClientState *nc;\n\n NetSocketState *s;\n\n\n\n /* fd passed: multicast: \"learn\" dgram_dst address from bound address and save it\n\n * Because this may be \"shared\" socket from a \"master\" process, datagrams would be recv()\n\n * by ONLY ONE process: we must \"clone\" this dgram socket --jjo\n\n */\n\n\n\n if (is_connected) {\n\n if (getsockname(fd, (struct sockaddr *) &saddr, &saddr_len) == 0) {\n\n /* must be bound */\n\n if (saddr.sin_addr.s_addr == 0) {\n\n fprintf(stderr, \"qemu: error: init_dgram: fd=%d unbound, \"\n\n \"cannot setup multicast dst addr\\n\", fd);\n\n goto err;\n\n }\n\n /* clone dgram socket */\n\n newfd = net_socket_mcast_create(&saddr, NULL);\n\n if (newfd < 0) {\n\n /* error already reported by net_socket_mcast_create() */\n\n goto err;\n\n }\n\n /* clone newfd to fd, close newfd */\n\n dup2(newfd, fd);\n\n close(newfd);\n\n\n\n } else {\n\n fprintf(stderr,\n\n \"qemu: error: init_dgram: fd=%d failed getsockname(): %s\\n\",\n\n fd, strerror(errno));\n\n goto err;\n\n }\n\n }\n\n\n\n nc = qemu_new_net_client(&net_dgram_socket_info, peer, model, name);\n\n\n\n snprintf(nc->info_str, sizeof(nc->info_str),\n\n \"socket: fd=%d (%s mcast=%s:%d)\",\n\n fd, is_connected ? \"cloned\" : \"\",\n\n inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));\n\n\n\n s = DO_UPCAST(NetSocketState, nc, nc);\n\n\n\n s->fd = fd;\n\n s->listen_fd = -1;\n\n s->send_fn = net_socket_send_dgram;\n\n net_socket_read_poll(s, true);\n\n\n\n /* mcast: save bound address as dst */\n\n if (is_connected) {\n\n s->dgram_dst = saddr;\n\n }\n\n\n\n return s;\n\n\n\nerr:\n\n closesocket(fd);\n\n return NULL;\n\n}\n", + "output": "1", + "index": 25249 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void swap_channel_layouts_on_filter(AVFilterContext *filter)\n\n{\n\n AVFilterLink *link = NULL;\n\n int i, j, k;\n\n\n\n for (i = 0; i < filter->nb_inputs; i++) {\n\n link = filter->inputs[i];\n\n\n\n if (link->type == AVMEDIA_TYPE_AUDIO &&\n\n link->out_channel_layouts->nb_channel_layouts == 1)\n\n break;\n\n }\n\n if (i == filter->nb_inputs)\n\n return;\n\n\n\n for (i = 0; i < filter->nb_outputs; i++) {\n\n AVFilterLink *outlink = filter->outputs[i];\n\n int best_idx, best_score = INT_MIN, best_count_diff = INT_MAX;\n\n\n\n if (outlink->type != AVMEDIA_TYPE_AUDIO ||\n\n outlink->in_channel_layouts->nb_channel_layouts < 2)\n\n continue;\n\n\n\n for (j = 0; j < outlink->in_channel_layouts->nb_channel_layouts; j++) {\n\n uint64_t in_chlayout = link->out_channel_layouts->channel_layouts[0];\n\n uint64_t out_chlayout = outlink->in_channel_layouts->channel_layouts[j];\n\n int in_channels = av_get_channel_layout_nb_channels(in_chlayout);\n\n int out_channels = av_get_channel_layout_nb_channels(out_chlayout);\n\n int count_diff = out_channels - in_channels;\n\n int matched_channels, extra_channels;\n\n int score = 0;\n\n\n\n /* channel substitution */\n\n for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) {\n\n uint64_t cmp0 = ch_subst[k][0];\n\n uint64_t cmp1 = ch_subst[k][1];\n\n if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) &&\n\n (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) {\n\n in_chlayout &= ~cmp0;\n\n out_chlayout &= ~cmp1;\n\n /* add score for channel match, minus a deduction for\n\n having to do the substitution */\n\n score += 10 * av_get_channel_layout_nb_channels(cmp1) - 2;\n\n }\n\n }\n\n\n\n /* no penalty for LFE channel mismatch */\n\n if ( (in_chlayout & AV_CH_LOW_FREQUENCY) &&\n\n (out_chlayout & AV_CH_LOW_FREQUENCY))\n\n score += 10;\n\n in_chlayout &= ~AV_CH_LOW_FREQUENCY;\n\n out_chlayout &= ~AV_CH_LOW_FREQUENCY;\n\n\n\n matched_channels = av_get_channel_layout_nb_channels(in_chlayout &\n\n out_chlayout);\n\n extra_channels = av_get_channel_layout_nb_channels(out_chlayout &\n\n (~in_chlayout));\n\n score += 10 * matched_channels - 5 * extra_channels;\n\n\n\n if (score > best_score ||\n\n (count_diff < best_count_diff && score == best_score)) {\n\n best_score = score;\n\n best_idx = j;\n\n best_count_diff = count_diff;\n\n }\n\n }\n\n FFSWAP(uint64_t, outlink->in_channel_layouts->channel_layouts[0],\n\n outlink->in_channel_layouts->channel_layouts[best_idx]);\n\n }\n\n\n\n}\n", + "output": "1", + "index": 25409 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int check_refcounts_l1(BlockDriverState *bs,\n\n BdrvCheckResult *res,\n\n uint16_t **refcount_table,\n\n int64_t *refcount_table_size,\n\n int64_t l1_table_offset, int l1_size,\n\n int flags)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n uint64_t *l1_table = NULL, l2_offset, l1_size2;\n\n int i, ret;\n\n\n\n l1_size2 = l1_size * sizeof(uint64_t);\n\n\n\n /* Mark L1 table as used */\n\n ret = inc_refcounts(bs, res, refcount_table, refcount_table_size,\n\n l1_table_offset, l1_size2);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n /* Read L1 table entries from disk */\n\n if (l1_size2 > 0) {\n\n l1_table = g_try_malloc(l1_size2);\n\n if (l1_table == NULL) {\n\n ret = -ENOMEM;\n\n res->check_errors++;\n\n goto fail;\n\n }\n\n ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2);\n\n if (ret < 0) {\n\n fprintf(stderr, \"ERROR: I/O error in check_refcounts_l1\\n\");\n\n res->check_errors++;\n\n goto fail;\n\n }\n\n for(i = 0;i < l1_size; i++)\n\n be64_to_cpus(&l1_table[i]);\n\n }\n\n\n\n /* Do the actual checks */\n\n for(i = 0; i < l1_size; i++) {\n\n l2_offset = l1_table[i];\n\n if (l2_offset) {\n\n /* Mark L2 table as used */\n\n l2_offset &= L1E_OFFSET_MASK;\n\n ret = inc_refcounts(bs, res, refcount_table, refcount_table_size,\n\n l2_offset, s->cluster_size);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n /* L2 tables are cluster aligned */\n\n if (offset_into_cluster(s, l2_offset)) {\n\n fprintf(stderr, \"ERROR l2_offset=%\" PRIx64 \": Table is not \"\n\n \"cluster aligned; L1 entry corrupted\\n\", l2_offset);\n\n res->corruptions++;\n\n }\n\n\n\n /* Process and check L2 entries */\n\n ret = check_refcounts_l2(bs, res, refcount_table,\n\n refcount_table_size, l2_offset, flags);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n }\n\n }\n\n g_free(l1_table);\n\n return 0;\n\n\n\nfail:\n\n g_free(l1_table);\n\n return ret;\n\n}\n", + "output": "1", + "index": 8707 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void inner_add_yblock_bw_16_obmc_32_sse2(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h,\n\n int src_x, int src_y, long src_stride, slice_buffer * sb, int add, uint8_t * dst8){\n\nsnow_inner_add_yblock_sse2_header\n\nsnow_inner_add_yblock_sse2_start_16(\"xmm1\", \"xmm5\", \"3\", \"0\")\n\nsnow_inner_add_yblock_sse2_accum_16(\"2\", \"16\")\n\nsnow_inner_add_yblock_sse2_accum_16(\"1\", \"512\")\n\nsnow_inner_add_yblock_sse2_accum_16(\"0\", \"528\")\n\n\n\n \"mov %0, %%\"REG_d\" \\n\\t\"\n\n \"movdqa %%xmm1, %%xmm0 \\n\\t\"\n\n \"movdqa %%xmm5, %%xmm4 \\n\\t\"\n\n \"punpcklwd %%xmm7, %%xmm0 \\n\\t\"\n\n \"paddd (%%\"REG_D\"), %%xmm0 \\n\\t\"\n\n \"punpckhwd %%xmm7, %%xmm1 \\n\\t\"\n\n \"paddd 16(%%\"REG_D\"), %%xmm1 \\n\\t\"\n\n \"punpcklwd %%xmm7, %%xmm4 \\n\\t\"\n\n \"paddd 32(%%\"REG_D\"), %%xmm4 \\n\\t\"\n\n \"punpckhwd %%xmm7, %%xmm5 \\n\\t\"\n\n \"paddd 48(%%\"REG_D\"), %%xmm5 \\n\\t\"\n\n \"paddd %%xmm3, %%xmm0 \\n\\t\"\n\n \"paddd %%xmm3, %%xmm1 \\n\\t\"\n\n \"paddd %%xmm3, %%xmm4 \\n\\t\"\n\n \"paddd %%xmm3, %%xmm5 \\n\\t\"\n\n \"psrad $8, %%xmm0 \\n\\t\" /* FRAC_BITS. */\n\n \"psrad $8, %%xmm1 \\n\\t\" /* FRAC_BITS. */\n\n \"psrad $8, %%xmm4 \\n\\t\" /* FRAC_BITS. */\n\n \"psrad $8, %%xmm5 \\n\\t\" /* FRAC_BITS. */\n\n\n\n \"packssdw %%xmm1, %%xmm0 \\n\\t\"\n\n \"packssdw %%xmm5, %%xmm4 \\n\\t\"\n\n \"packuswb %%xmm4, %%xmm0 \\n\\t\"\n\n\n\n \"movdqu %%xmm0, (%%\"REG_d\") \\n\\t\"\n\n\n\nsnow_inner_add_yblock_sse2_end_16\n\n}\n", + "output": "1", + "index": 22934 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,\n\n enum AVSampleFormat sample_fmt, int size,\n\n int64_t channel_layout, int planar)\n\n{\n\n AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));\n\n AVFilterBufferRef *ref = NULL;\n\n int i, sample_size, chans_nb, bufsize, per_channel_size, step_size = 0;\n\n char *buf;\n\n\n\n if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))\n\n goto fail;\n\n\n\n ref->buf = samples;\n\n ref->format = sample_fmt;\n\n\n\n ref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps));\n\n if (!ref->audio)\n\n goto fail;\n\n\n\n ref->audio->channel_layout = channel_layout;\n\n ref->audio->size = size;\n\n ref->audio->planar = planar;\n\n\n\n /* make sure the buffer gets read permission or it's useless for output */\n\n ref->perms = perms | AV_PERM_READ;\n\n\n\n samples->refcount = 1;\n\n samples->free = ff_avfilter_default_free_buffer;\n\n\n\n sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3;\n\n chans_nb = av_get_channel_layout_nb_channels(channel_layout);\n\n\n\n per_channel_size = size/chans_nb;\n\n ref->audio->nb_samples = per_channel_size/sample_size;\n\n\n\n /* Set the number of bytes to traverse to reach next sample of a particular channel:\n\n * For planar, this is simply the sample size.\n\n * For packed, this is the number of samples * sample_size.\n\n */\n\n for (i = 0; i < chans_nb; i++)\n\n samples->linesize[i] = planar > 0 ? per_channel_size : sample_size;\n\n memset(&samples->linesize[chans_nb], 0, (8-chans_nb) * sizeof(samples->linesize[0]));\n\n\n\n /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */\n\n bufsize = (size + 15)&~15;\n\n buf = av_malloc(bufsize);\n\n if (!buf)\n\n goto fail;\n\n\n\n /* For planar, set the start point of each channel's data within the buffer\n\n * For packed, set the start point of the entire buffer only\n\n */\n\n samples->data[0] = buf;\n\n if (buf && planar) {\n\n for (i = 1; i < chans_nb; i++) {\n\n step_size += per_channel_size;\n\n samples->data[i] = buf + step_size;\n\n }\n\n } else {\n\n for (i = 1; i < chans_nb; i++)\n\n samples->data[i] = buf;\n\n }\n\n\n\n memset(&samples->data[chans_nb], 0, (8-chans_nb) * sizeof(samples->data[0]));\n\n\n\n memcpy(ref->data, samples->data, sizeof(ref->data));\n\n memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize));\n\n\n\n return ref;\n\n\n\nfail:\n\n av_free(buf);\n\n if (ref && ref->audio)\n\n av_free(ref->audio);\n\n av_free(ref);\n\n av_free(samples);\n\n return NULL;\n\n}\n", + "output": "1", + "index": 2705 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,\n\n int len, int is_write)\n\n{\n\n int l, io_index;\n\n uint8_t *ptr;\n\n uint32_t val;\n\n target_phys_addr_t page;\n\n unsigned long pd;\n\n PhysPageDesc *p;\n\n\n\n while (len > 0) {\n\n page = addr & TARGET_PAGE_MASK;\n\n l = (page + TARGET_PAGE_SIZE) - addr;\n\n if (l > len)\n\n l = len;\n\n p = phys_page_find(page >> TARGET_PAGE_BITS);\n\n if (!p) {\n\n pd = IO_MEM_UNASSIGNED;\n\n } else {\n\n pd = p->phys_offset;\n\n }\n\n\n\n if (is_write) {\n\n if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM) {\n\n io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);\n\n if (p)\n\n addr = (addr & ~TARGET_PAGE_MASK) + p->region_offset;\n\n /* XXX: could force cpu_single_env to NULL to avoid\n\n potential bugs */\n\n if (l >= 4 && ((addr & 3) == 0)) {\n\n /* 32 bit write access */\n\n val = ldl_p(buf);\n\n io_mem_write[io_index][2](io_mem_opaque[io_index], addr, val);\n\n l = 4;\n\n } else if (l >= 2 && ((addr & 1) == 0)) {\n\n /* 16 bit write access */\n\n val = lduw_p(buf);\n\n io_mem_write[io_index][1](io_mem_opaque[io_index], addr, val);\n\n l = 2;\n\n } else {\n\n /* 8 bit write access */\n\n val = ldub_p(buf);\n\n io_mem_write[io_index][0](io_mem_opaque[io_index], addr, val);\n\n l = 1;\n\n }\n\n } else {\n\n unsigned long addr1;\n\n addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);\n\n /* RAM case */\n\n ptr = phys_ram_base + addr1;\n\n memcpy(ptr, buf, l);\n\n if (!cpu_physical_memory_is_dirty(addr1)) {\n\n /* invalidate code */\n\n tb_invalidate_phys_page_range(addr1, addr1 + l, 0);\n\n /* set dirty bit */\n\n phys_ram_dirty[addr1 >> TARGET_PAGE_BITS] |=\n\n (0xff & ~CODE_DIRTY_FLAG);\n\n }\n\n }\n\n } else {\n\n if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&\n\n !(pd & IO_MEM_ROMD)) {\n\n /* I/O case */\n\n io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);\n\n if (p)\n\n addr = (addr & ~TARGET_PAGE_MASK) + p->region_offset;\n\n if (l >= 4 && ((addr & 3) == 0)) {\n\n /* 32 bit read access */\n\n val = io_mem_read[io_index][2](io_mem_opaque[io_index], addr);\n\n stl_p(buf, val);\n\n l = 4;\n\n } else if (l >= 2 && ((addr & 1) == 0)) {\n\n /* 16 bit read access */\n\n val = io_mem_read[io_index][1](io_mem_opaque[io_index], addr);\n\n stw_p(buf, val);\n\n l = 2;\n\n } else {\n\n /* 8 bit read access */\n\n val = io_mem_read[io_index][0](io_mem_opaque[io_index], addr);\n\n stb_p(buf, val);\n\n l = 1;\n\n }\n\n } else {\n\n /* RAM case */\n\n ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +\n\n (addr & ~TARGET_PAGE_MASK);\n\n memcpy(buf, ptr, l);\n\n }\n\n }\n\n len -= l;\n\n buf += l;\n\n addr += l;\n\n }\n\n}\n", + "output": "1", + "index": 4640 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block)\n\n{\n\n int last_index = get_bits_size(gb);\n\n const uint8_t *scan_table = mb->scan_table;\n\n const uint8_t *shift_table = mb->shift_table;\n\n int pos = mb->pos;\n\n int partial_bit_count = mb->partial_bit_count;\n\n int level, pos1, run, vlc_len, index;\n\n \n\n OPEN_READER(re, gb);\n\n UPDATE_CACHE(re, gb);\n\n \n\n /* if we must parse a partial vlc, we do it here */\n\n if (partial_bit_count > 0) {\n\n re_cache = ((unsigned)re_cache >> partial_bit_count) |\n\n\t (mb->partial_bit_buffer << (sizeof(re_cache)*8 - partial_bit_count));\n\n\tre_index -= partial_bit_count;\n\n\tmb->partial_bit_count = 0;\n\n }\n\n\n\n /* get the AC coefficients until last_index is reached */\n\n for(;;) {\n\n#ifdef VLC_DEBUG\n\n printf(\"%2d: bits=%04x index=%d\\n\", pos, SHOW_UBITS(re, gb, 16), re_index);\n\n#endif\n\n /* our own optimized GET_RL_VLC */\n\n index = NEG_USR32(re_cache, TEX_VLC_BITS);\n\n\tvlc_len = dv_rl_vlc[index].len;\n\n if (vlc_len < 0) {\n\n index = NEG_USR32((unsigned)re_cache << TEX_VLC_BITS, -vlc_len) + dv_rl_vlc[index].level;\n\n vlc_len = TEX_VLC_BITS - vlc_len;\n\n }\n\n level = dv_rl_vlc[index].level;\n\n\trun = dv_rl_vlc[index].run;\n\n\t\n\n\t/* gotta check if we're still within gb boundaries */\n\n\tif (re_index + vlc_len > last_index) {\n\n\t /* should be < 16 bits otherwise a codeword could have been parsed */\n\n\t mb->partial_bit_count = last_index - re_index;\n\n\t mb->partial_bit_buffer = NEG_USR32(re_cache, mb->partial_bit_count);\n\n\t re_index = last_index;\n\n\t break;\n\n\t}\n\n\tre_index += vlc_len;\n\n\n\n#ifdef VLC_DEBUG\n\n\tprintf(\"run=%d level=%d\\n\", run, level);\n\n#endif\n\n\tpos += run; \t\n\n\tif (pos >= 64)\n\n\t break;\n\n \n\n\tif (level) {\n\n pos1 = scan_table[pos];\n\n block[pos1] = level << shift_table[pos1];\n\n } \n\n\n\n UPDATE_CACHE(re, gb);\n\n }\n\n CLOSE_READER(re, gb);\n\n mb->pos = pos;\n\n}\n", + "output": "0", + "index": 1656 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold int encode_init(AVCodecContext *avctx)\n\n{\n\n NellyMoserEncodeContext *s = avctx->priv_data;\n\n int i, ret;\n\n\n\n if (avctx->channels != 1) {\n\n av_log(avctx, AV_LOG_ERROR, \"Nellymoser supports only 1 channel\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n if (avctx->sample_rate != 8000 && avctx->sample_rate != 16000 &&\n\n avctx->sample_rate != 11025 &&\n\n avctx->sample_rate != 22050 && avctx->sample_rate != 44100 &&\n\n avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) {\n\n av_log(avctx, AV_LOG_ERROR, \"Nellymoser works only with 8000, 16000, 11025, 22050 and 44100 sample rate\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n avctx->frame_size = NELLY_SAMPLES;\n\n avctx->delay = NELLY_BUF_LEN;\n\n ff_af_queue_init(avctx, &s->afq);\n\n s->avctx = avctx;\n\n if ((ret = ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0)) < 0)\n\n goto error;\n\n ff_dsputil_init(&s->dsp, avctx);\n\n\n\n /* Generate overlap window */\n\n ff_sine_window_init(ff_sine_128, 128);\n\n for (i = 0; i < POW_TABLE_SIZE; i++)\n\n pow_table[i] = -pow(2, -i / 2048.0 - 3.0 + POW_TABLE_OFFSET);\n\n\n\n if (s->avctx->trellis) {\n\n s->opt = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(float ));\n\n s->path = av_malloc(NELLY_BANDS * OPT_SIZE * sizeof(uint8_t));\n\n if (!s->opt || !s->path) {\n\n ret = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n }\n\n\n\n#if FF_API_OLD_ENCODE_AUDIO\n\n avctx->coded_frame = avcodec_alloc_frame();\n\n if (!avctx->coded_frame) {\n\n ret = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n#endif\n\n\n\n return 0;\n\nerror:\n\n encode_end(avctx);\n\n return ret;\n\n}\n", + "output": "1", + "index": 14753 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void quorum_vote(QuorumAIOCB *acb)\n\n{\n\n bool quorum = true;\n\n int i, j, ret;\n\n QuorumVoteValue hash;\n\n BDRVQuorumState *s = acb->common.bs->opaque;\n\n QuorumVoteVersion *winner;\n\n\n\n if (quorum_has_too_much_io_failed(acb)) {\n\n return;\n\n }\n\n\n\n /* get the index of the first successful read */\n\n for (i = 0; i < s->num_children; i++) {\n\n if (!acb->qcrs[i].ret) {\n\n break;\n\n }\n\n }\n\n\n\n assert(i < s->num_children);\n\n\n\n /* compare this read with all other successful reads stopping at quorum\n\n * failure\n\n */\n\n for (j = i + 1; j < s->num_children; j++) {\n\n if (acb->qcrs[j].ret) {\n\n continue;\n\n }\n\n quorum = quorum_compare(acb, &acb->qcrs[i].qiov, &acb->qcrs[j].qiov);\n\n if (!quorum) {\n\n break;\n\n }\n\n }\n\n\n\n /* Every successful read agrees */\n\n if (quorum) {\n\n quorum_copy_qiov(acb->qiov, &acb->qcrs[i].qiov);\n\n return;\n\n }\n\n\n\n /* compute hashes for each successful read, also store indexes */\n\n for (i = 0; i < s->num_children; i++) {\n\n if (acb->qcrs[i].ret) {\n\n continue;\n\n }\n\n ret = quorum_compute_hash(acb, i, &hash);\n\n /* if ever the hash computation failed */\n\n if (ret < 0) {\n\n acb->vote_ret = ret;\n\n goto free_exit;\n\n }\n\n quorum_count_vote(&acb->votes, &hash, i);\n\n }\n\n\n\n /* vote to select the most represented version */\n\n winner = quorum_get_vote_winner(&acb->votes);\n\n\n\n /* if the winner count is smaller than threshold the read fails */\n\n if (winner->vote_count < s->threshold) {\n\n quorum_report_failure(acb);\n\n acb->vote_ret = -EIO;\n\n goto free_exit;\n\n }\n\n\n\n /* we have a winner: copy it */\n\n quorum_copy_qiov(acb->qiov, &acb->qcrs[winner->index].qiov);\n\n\n\n /* some versions are bad print them */\n\n quorum_report_bad_versions(s, acb, &winner->value);\n\n\n\nfree_exit:\n\n /* free lists */\n\n quorum_free_vote_list(&acb->votes);\n\n}\n", + "output": "1", + "index": 2328 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding)\n\n{\n\n int a, b, c, wrap, pred, scale, ret;\n\n int16_t *dc_val;\n\n\n\n /* find prediction */\n\n if (n < 4) {\n\n scale = s->y_dc_scale;\n\n } else {\n\n scale = s->c_dc_scale;\n\n }\n\n if(IS_3IV1)\n\n scale= 8;\n\n\n\n wrap= s->block_wrap[n];\n\n dc_val = s->dc_val[0] + s->block_index[n];\n\n\n\n /* B C\n\n * A X\n\n */\n\n a = dc_val[ - 1];\n\n b = dc_val[ - 1 - wrap];\n\n c = dc_val[ - wrap];\n\n\n\n /* outside slice handling (we can't do that by memset as we need the dc for error resilience) */\n\n if(s->first_slice_line && n!=3){\n\n if(n!=2) b=c= 1024;\n\n if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024;\n\n }\n\n if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){\n\n if(n==0 || n==4 || n==5)\n\n b=1024;\n\n }\n\n\n\n if (abs(a - b) < abs(b - c)) {\n\n pred = c;\n\n *dir_ptr = 1; /* top */\n\n } else {\n\n pred = a;\n\n *dir_ptr = 0; /* left */\n\n }\n\n /* we assume pred is positive */\n\n pred = FASTDIV((pred + (scale >> 1)), scale);\n\n\n\n if(encoding){\n\n ret = level - pred;\n\n }else{\n\n level += pred;\n\n ret= level;\n\n if(s->error_recognition>=3){\n\n if(level<0){\n\n av_log(s->avctx, AV_LOG_ERROR, \"dc<0 at %dx%d\\n\", s->mb_x, s->mb_y);\n\n return -1;\n\n }\n\n if(level*scale > 2048 + scale){\n\n av_log(s->avctx, AV_LOG_ERROR, \"dc overflow at %dx%d\\n\", s->mb_x, s->mb_y);\n\n return -1;\n\n }\n\n }\n\n }\n\n level *=scale;\n\n if(level&(~2047)){\n\n if(level<0)\n\n level=0;\n\n else if(!(s->workaround_bugs&FF_BUG_DC_CLIP))\n\n level=2047;\n\n }\n\n dc_val[0]= level;\n\n\n\n return ret;\n\n}\n", + "output": "0", + "index": 20124 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void mcf_fec_write(void *opaque, hwaddr addr,\n\n uint64_t value, unsigned size)\n\n{\n\n mcf_fec_state *s = (mcf_fec_state *)opaque;\n\n switch (addr & 0x3ff) {\n\n case 0x004:\n\n s->eir &= ~value;\n\n break;\n\n case 0x008:\n\n s->eimr = value;\n\n break;\n\n case 0x010: /* RDAR */\n\n if ((s->ecr & FEC_EN) && !s->rx_enabled) {\n\n DPRINTF(\"RX enable\\n\");\n\n mcf_fec_enable_rx(s);\n\n }\n\n break;\n\n case 0x014: /* TDAR */\n\n if (s->ecr & FEC_EN) {\n\n mcf_fec_do_tx(s);\n\n }\n\n break;\n\n case 0x024:\n\n s->ecr = value;\n\n if (value & FEC_RESET) {\n\n DPRINTF(\"Reset\\n\");\n\n mcf_fec_reset(s);\n\n }\n\n if ((s->ecr & FEC_EN) == 0) {\n\n s->rx_enabled = 0;\n\n }\n\n break;\n\n case 0x040:\n\n s->mmfr = value;\n\n s->eir |= FEC_INT_MII;\n\n break;\n\n case 0x044:\n\n s->mscr = value & 0xfe;\n\n break;\n\n case 0x064:\n\n /* TODO: Implement MIB. */\n\n break;\n\n case 0x084:\n\n s->rcr = value & 0x07ff003f;\n\n /* TODO: Implement LOOP mode. */\n\n break;\n\n case 0x0c4: /* TCR */\n\n /* We transmit immediately, so raise GRA immediately. */\n\n s->tcr = value;\n\n if (value & 1)\n\n s->eir |= FEC_INT_GRA;\n\n break;\n\n case 0x0e4: /* PALR */\n\n s->conf.macaddr.a[0] = value >> 24;\n\n s->conf.macaddr.a[1] = value >> 16;\n\n s->conf.macaddr.a[2] = value >> 8;\n\n s->conf.macaddr.a[3] = value;\n\n break;\n\n case 0x0e8: /* PAUR */\n\n s->conf.macaddr.a[4] = value >> 24;\n\n s->conf.macaddr.a[5] = value >> 16;\n\n break;\n\n case 0x0ec:\n\n /* OPD */\n\n break;\n\n case 0x118:\n\n case 0x11c:\n\n case 0x120:\n\n case 0x124:\n\n /* TODO: implement MAC hash filtering. */\n\n break;\n\n case 0x144:\n\n s->tfwr = value & 3;\n\n break;\n\n case 0x14c:\n\n /* FRBR writes ignored. */\n\n break;\n\n case 0x150:\n\n s->rfsr = (value & 0x3fc) | 0x400;\n\n break;\n\n case 0x180:\n\n s->erdsr = value & ~3;\n\n s->rx_descriptor = s->erdsr;\n\n break;\n\n case 0x184:\n\n s->etdsr = value & ~3;\n\n s->tx_descriptor = s->etdsr;\n\n break;\n\n case 0x188:\n\n s->emrbr = value & 0x7f0;\n\n break;\n\n default:\n\n hw_error(\"mcf_fec_write Bad address 0x%x\\n\", (int)addr);\n\n }\n\n mcf_fec_update(s);\n\n}\n", + "output": "0", + "index": 14955 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void decode_interframe_v4(AVCodecContext *avctx, uint8_t *src, uint32_t size)\n\n{\n\n Hnm4VideoContext *hnm = avctx->priv_data;\n\n GetByteContext gb;\n\n uint32_t writeoffset = 0, count, left, offset;\n\n uint8_t tag, previous, backline, backward, swap;\n\n\n\n bytestream2_init(&gb, src, size);\n\n\n\n while (bytestream2_tell(&gb) < size) {\n\n count = bytestream2_peek_byte(&gb) & 0x1F;\n\n if (count == 0) {\n\n tag = bytestream2_get_byte(&gb) & 0xE0;\n\n tag = tag >> 5;\n\n if (tag == 0) {\n\n hnm->current[writeoffset++] = bytestream2_get_byte(&gb);\n\n hnm->current[writeoffset++] = bytestream2_get_byte(&gb);\n\n } else if (tag == 1) {\n\n writeoffset += bytestream2_get_byte(&gb) * 2;\n\n } else if (tag == 2) {\n\n count = bytestream2_get_le16(&gb);\n\n count *= 2;\n\n writeoffset += count;\n\n } else if (tag == 3) {\n\n count = bytestream2_get_byte(&gb) * 2;\n\n while (count > 0) {\n\n hnm->current[writeoffset++] = bytestream2_peek_byte(&gb);\n\n count--;\n\n }\n\n bytestream2_skip(&gb, 1);\n\n } else {\n\n break;\n\n }\n\n } else {\n\n previous = bytestream2_peek_byte(&gb) & 0x20;\n\n backline = bytestream2_peek_byte(&gb) & 0x40;\n\n backward = bytestream2_peek_byte(&gb) & 0x80;\n\n bytestream2_skip(&gb, 1);\n\n swap = bytestream2_peek_byte(&gb) & 0x01;\n\n offset = bytestream2_get_le16(&gb);\n\n offset = (offset >> 1) & 0x7FFF;\n\n offset = writeoffset + (offset * 2) - 0x8000;\n\n\n\n left = count;\n\n\n\n if (!backward && offset + count >= hnm->width * hnm->height) {\n\n av_log(avctx, AV_LOG_ERROR, \"Attempting to read out of bounds\");\n\n break;\n\n } else if (backward && offset >= hnm->width * hnm->height) {\n\n av_log(avctx, AV_LOG_ERROR, \"Attempting to read out of bounds\");\n\n break;\n\n } else if (writeoffset + count >= hnm->width * hnm->height) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Attempting to write out of bounds\");\n\n break;\n\n }\n\n\n\n if (previous) {\n\n while (left > 0) {\n\n if (backline) {\n\n hnm->current[writeoffset++] = hnm->previous[offset - (2 * hnm->width) + 1];\n\n hnm->current[writeoffset++] = hnm->previous[offset++];\n\n offset++;\n\n } else {\n\n hnm->current[writeoffset++] = hnm->previous[offset++];\n\n hnm->current[writeoffset++] = hnm->previous[offset++];\n\n }\n\n if (backward)\n\n offset -= 4;\n\n left--;\n\n }\n\n } else {\n\n while (left > 0) {\n\n if (backline) {\n\n hnm->current[writeoffset++] = hnm->current[offset - (2 * hnm->width) + 1];\n\n hnm->current[writeoffset++] = hnm->current[offset++];\n\n offset++;\n\n } else {\n\n hnm->current[writeoffset++] = hnm->current[offset++];\n\n hnm->current[writeoffset++] = hnm->current[offset++];\n\n }\n\n if (backward)\n\n offset -= 4;\n\n left--;\n\n }\n\n }\n\n\n\n if (swap) {\n\n left = count;\n\n writeoffset -= count * 2;\n\n while (left > 0) {\n\n swap = hnm->current[writeoffset];\n\n hnm->current[writeoffset] = hnm->current[writeoffset + 1];\n\n hnm->current[writeoffset + 1] = swap;\n\n left--;\n\n writeoffset += 2;\n\n }\n\n }\n\n }\n\n }\n\n}\n", + "output": "0", + "index": 24677 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_cabac_mb_type( H264Context *h ) {\n\n MpegEncContext * const s = &h->s;\n\n\n\n if( h->slice_type == I_TYPE ) {\n\n return decode_cabac_intra_mb_type(h, 3, 1);\n\n } else if( h->slice_type == P_TYPE ) {\n\n if( get_cabac( &h->cabac, &h->cabac_state[14] ) == 0 ) {\n\n /* P-type */\n\n if( get_cabac( &h->cabac, &h->cabac_state[15] ) == 0 ) {\n\n /* P_L0_D16x16, P_8x8 */\n\n return 3 * get_cabac( &h->cabac, &h->cabac_state[16] );\n\n } else {\n\n /* P_L0_D8x16, P_L0_D16x8 */\n\n return 2 - get_cabac( &h->cabac, &h->cabac_state[17] );\n\n }\n\n } else {\n\n return decode_cabac_intra_mb_type(h, 17, 0) + 5;\n\n }\n\n } else if( h->slice_type == B_TYPE ) {\n\n const int mba_xy = h->left_mb_xy[0];\n\n const int mbb_xy = h->top_mb_xy;\n\n int ctx = 0;\n\n int bits;\n\n\n\n if( h->slice_table[mba_xy] == h->slice_num && !IS_DIRECT( s->current_picture.mb_type[mba_xy] ) )\n\n ctx++;\n\n if( h->slice_table[mbb_xy] == h->slice_num && !IS_DIRECT( s->current_picture.mb_type[mbb_xy] ) )\n\n ctx++;\n\n\n\n if( !get_cabac( &h->cabac, &h->cabac_state[27+ctx] ) )\n\n return 0; /* B_Direct_16x16 */\n\n\n\n if( !get_cabac( &h->cabac, &h->cabac_state[27+3] ) ) {\n\n return 1 + get_cabac( &h->cabac, &h->cabac_state[27+5] ); /* B_L[01]_16x16 */\n\n }\n\n\n\n bits = get_cabac( &h->cabac, &h->cabac_state[27+4] ) << 3;\n\n bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ) << 2;\n\n bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] ) << 1;\n\n bits|= get_cabac( &h->cabac, &h->cabac_state[27+5] );\n\n if( bits < 8 )\n\n return bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */\n\n else if( bits == 13 ) {\n\n return decode_cabac_intra_mb_type(h, 32, 0) + 23;\n\n } else if( bits == 14 )\n\n return 11; /* B_L1_L0_8x16 */\n\n else if( bits == 15 )\n\n return 22; /* B_8x8 */\n\n\n\n bits= ( bits<<1 ) | get_cabac( &h->cabac, &h->cabac_state[27+5] );\n\n return bits - 4; /* B_L0_Bi_* through B_Bi_Bi_* */\n\n } else {\n\n /* TODO SI/SP frames? */\n\n return -1;\n\n }\n\n}\n", + "output": "0", + "index": 15464 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_always_inline int dnxhd_decode_dct_block(const DNXHDContext *ctx,\n\n RowContext *row,\n\n int n,\n\n int index_bits,\n\n int level_bias,\n\n int level_shift,\n\n int dc_shift)\n\n{\n\n int i, j, index1, index2, len, flags;\n\n int level, component, sign;\n\n const int *scale;\n\n const uint8_t *weight_matrix;\n\n const uint8_t *ac_info = ctx->cid_table->ac_info;\n\n int16_t *block = row->blocks[n];\n\n const int eob_index = ctx->cid_table->eob_index;\n\n int ret = 0;\n\n OPEN_READER(bs, &row->gb);\n\n\n\n ctx->bdsp.clear_block(block);\n\n\n\n if (!ctx->is_444) {\n\n if (n & 2) {\n\n component = 1 + (n & 1);\n\n scale = row->chroma_scale;\n\n weight_matrix = ctx->cid_table->chroma_weight;\n\n } else {\n\n component = 0;\n\n scale = row->luma_scale;\n\n weight_matrix = ctx->cid_table->luma_weight;\n\n }\n\n } else {\n\n component = (n >> 1) % 3;\n\n if (component) {\n\n scale = row->chroma_scale;\n\n weight_matrix = ctx->cid_table->chroma_weight;\n\n } else {\n\n scale = row->luma_scale;\n\n weight_matrix = ctx->cid_table->luma_weight;\n\n }\n\n }\n\n\n\n UPDATE_CACHE(bs, &row->gb);\n\n GET_VLC(len, bs, &row->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1);\n\n if (len) {\n\n level = GET_CACHE(bs, &row->gb);\n\n LAST_SKIP_BITS(bs, &row->gb, len);\n\n sign = ~level >> 31;\n\n level = (NEG_USR32(sign ^ level, len) ^ sign) - sign;\n\n row->last_dc[component] += level << dc_shift;\n\n }\n\n block[0] = row->last_dc[component];\n\n\n\n i = 0;\n\n\n\n UPDATE_CACHE(bs, &row->gb);\n\n GET_VLC(index1, bs, &row->gb, ctx->ac_vlc.table,\n\n DNXHD_VLC_BITS, 2);\n\n\n\n while (index1 != eob_index) {\n\n level = ac_info[2*index1+0];\n\n flags = ac_info[2*index1+1];\n\n\n\n sign = SHOW_SBITS(bs, &row->gb, 1);\n\n SKIP_BITS(bs, &row->gb, 1);\n\n\n\n if (flags & 1) {\n\n level += SHOW_UBITS(bs, &row->gb, index_bits) << 7;\n\n SKIP_BITS(bs, &row->gb, index_bits);\n\n }\n\n\n\n if (flags & 2) {\n\n UPDATE_CACHE(bs, &row->gb);\n\n GET_VLC(index2, bs, &row->gb, ctx->run_vlc.table,\n\n DNXHD_VLC_BITS, 2);\n\n i += ctx->cid_table->run[index2];\n\n }\n\n\n\n if (++i > 63) {\n\n av_log(ctx->avctx, AV_LOG_ERROR, \"ac tex damaged %d, %d\\n\", n, i);\n\n ret = -1;\n\n break;\n\n }\n\n\n\n j = ctx->scantable.permutated[i];\n\n level *= scale[i];\n\n level += scale[i] >> 1;\n\n if (level_bias < 32 || weight_matrix[i] != level_bias)\n\n level += level_bias; // 1<<(level_shift-1)\n\n level >>= level_shift;\n\n\n\n block[j] = (level ^ sign) - sign;\n\n\n\n UPDATE_CACHE(bs, &row->gb);\n\n GET_VLC(index1, bs, &row->gb, ctx->ac_vlc.table,\n\n DNXHD_VLC_BITS, 2);\n\n }\n\n\n\n CLOSE_READER(bs, &row->gb);\n\n return ret;\n\n}\n", + "output": "0", + "index": 15794 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void test_opts_parse_number(void)\n\n{\n\n Error *err = NULL;\n\n QemuOpts *opts;\n\n\n\n /* Lower limit zero */\n\n opts = qemu_opts_parse(&opts_list_01, \"number1=0\", false, &error_abort);\n\n g_assert_cmpuint(opts_count(opts), ==, 1);\n\n g_assert_cmpuint(qemu_opt_get_number(opts, \"number1\", 1), ==, 0);\n\n\n\n /* Upper limit 2^64-1 */\n\n opts = qemu_opts_parse(&opts_list_01,\n\n \"number1=18446744073709551615,number2=-1\",\n\n false, &error_abort);\n\n g_assert_cmpuint(opts_count(opts), ==, 2);\n\n g_assert_cmphex(qemu_opt_get_number(opts, \"number1\", 1), ==, UINT64_MAX);\n\n g_assert_cmphex(qemu_opt_get_number(opts, \"number2\", 0), ==, UINT64_MAX);\n\n\n\n /* Above upper limit */\n\n opts = qemu_opts_parse(&opts_list_01, \"number1=18446744073709551616\",\n\n false, &error_abort);\n\n /* BUG: should reject */\n\n g_assert_cmpuint(opts_count(opts), ==, 1);\n\n g_assert_cmpuint(qemu_opt_get_number(opts, \"number1\", 1), ==, UINT64_MAX);\n\n\n\n /* Below lower limit */\n\n opts = qemu_opts_parse(&opts_list_01, \"number1=-18446744073709551616\",\n\n false, &error_abort);\n\n /* BUG: should reject */\n\n g_assert_cmpuint(opts_count(opts), ==, 1);\n\n g_assert_cmpuint(qemu_opt_get_number(opts, \"number1\", 1), ==, UINT64_MAX);\n\n\n\n /* Hex and octal */\n\n opts = qemu_opts_parse(&opts_list_01, \"number1=0x2a,number2=052\",\n\n false, &error_abort);\n\n g_assert_cmpuint(opts_count(opts), ==, 2);\n\n g_assert_cmpuint(qemu_opt_get_number(opts, \"number1\", 1), ==, 42);\n\n g_assert_cmpuint(qemu_opt_get_number(opts, \"number2\", 0), ==, 42);\n\n\n\n /* Invalid */\n\n opts = qemu_opts_parse(&opts_list_01, \"number1=\", false, &err);\n\n /* BUG: should reject */\n\n g_assert_cmpuint(opts_count(opts), ==, 1);\n\n g_assert_cmpuint(qemu_opt_get_number(opts, \"number1\", 1), ==, 0);\n\n opts = qemu_opts_parse(&opts_list_01, \"number1=eins\", false, &err);\n\n error_free_or_abort(&err);\n\n g_assert(!opts);\n\n\n\n /* Leading whitespace */\n\n opts = qemu_opts_parse(&opts_list_01, \"number1= \\t42\",\n\n false, &error_abort);\n\n g_assert_cmpuint(opts_count(opts), ==, 1);\n\n g_assert_cmpuint(qemu_opt_get_number(opts, \"number1\", 1), ==, 42);\n\n\n\n /* Trailing crap */\n\n opts = qemu_opts_parse(&opts_list_01, \"number1=3.14\", false, &err);\n\n error_free_or_abort(&err);\n\n g_assert(!opts);\n\n opts = qemu_opts_parse(&opts_list_01, \"number1=08\", false, &err);\n\n error_free_or_abort(&err);\n\n g_assert(!opts);\n\n opts = qemu_opts_parse(&opts_list_01, \"number1=0 \", false, &err);\n\n error_free_or_abort(&err);\n\n g_assert(!opts);\n\n\n\n qemu_opts_reset(&opts_list_01);\n\n}\n", + "output": "1", + "index": 23192 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void pxa2xx_i2s_write(void *opaque, hwaddr addr,\n\n uint64_t value, unsigned size)\n\n{\n\n PXA2xxI2SState *s = (PXA2xxI2SState *) opaque;\n\n uint32_t *sample;\n\n\n\n switch (addr) {\n\n case SACR0:\n\n if (value & (1 << 3))\t\t\t\t/* RST */\n\n pxa2xx_i2s_reset(s);\n\n s->control[0] = value & 0xff3d;\n\n if (!s->enable && (value & 1) && s->tx_len) {\t/* ENB */\n\n for (sample = s->fifo; s->fifo_len > 0; s->fifo_len --, sample ++)\n\n s->codec_out(s->opaque, *sample);\n\n s->status &= ~(1 << 7);\t\t\t/* I2SOFF */\n\n }\n\n if (value & (1 << 4))\t\t\t\t/* EFWR */\n\n printf(\"%s: Attempt to use special function\\n\", __FUNCTION__);\n\n s->enable = (value & 9) == 1;\t\t\t/* ENB && !RST*/\n\n pxa2xx_i2s_update(s);\n\n break;\n\n case SACR1:\n\n s->control[1] = value & 0x0039;\n\n if (value & (1 << 5))\t\t\t\t/* ENLBF */\n\n printf(\"%s: Attempt to use loopback function\\n\", __FUNCTION__);\n\n if (value & (1 << 4))\t\t\t\t/* DPRL */\n\n s->fifo_len = 0;\n\n pxa2xx_i2s_update(s);\n\n break;\n\n case SAIMR:\n\n s->mask = value & 0x0078;\n\n pxa2xx_i2s_update(s);\n\n break;\n\n case SAICR:\n\n s->status &= ~(value & (3 << 5));\n\n pxa2xx_i2s_update(s);\n\n break;\n\n case SADIV:\n\n s->clk = value & 0x007f;\n\n break;\n\n case SADR:\n\n if (s->tx_len && s->enable) {\n\n s->tx_len --;\n\n pxa2xx_i2s_update(s);\n\n s->codec_out(s->opaque, value);\n\n } else if (s->fifo_len < 16) {\n\n s->fifo[s->fifo_len ++] = value;\n\n pxa2xx_i2s_update(s);\n\n }\n\n break;\n\n default:\n\n printf(\"%s: Bad register \" REG_FMT \"\\n\", __FUNCTION__, addr);\n\n }\n\n}\n", + "output": "0", + "index": 15836 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int siff_read_packet(AVFormatContext *s, AVPacket *pkt)\n\n{\n\n SIFFContext *c = s->priv_data;\n\n int size;\n\n\n\n if (c->has_video){\n\n if (c->cur_frame >= c->frames)\n\n return AVERROR_EOF;\n\n if (c->curstrm == -1){\n\n c->pktsize = avio_rl32(s->pb) - 4;\n\n c->flags = avio_rl16(s->pb);\n\n c->gmcsize = (c->flags & VB_HAS_GMC) ? 4 : 0;\n\n if (c->gmcsize)\n\n avio_read(s->pb, c->gmc, c->gmcsize);\n\n c->sndsize = (c->flags & VB_HAS_AUDIO) ? avio_rl32(s->pb): 0;\n\n c->curstrm = !!(c->flags & VB_HAS_AUDIO);\n\n }\n\n\n\n if (!c->curstrm){\n\n size = c->pktsize - c->sndsize - c->gmcsize - 2;\n\n size = ffio_limit(s->pb, size);\n\n if(size < 0 || c->pktsize < c->sndsize)\n\n return AVERROR_INVALIDDATA;\n\n if (av_new_packet(pkt, size + c->gmcsize + 2) < 0)\n\n return AVERROR(ENOMEM);\n\n AV_WL16(pkt->data, c->flags);\n\n if (c->gmcsize)\n\n memcpy(pkt->data + 2, c->gmc, c->gmcsize);\n\n avio_read(s->pb, pkt->data + 2 + c->gmcsize, size);\n\n pkt->stream_index = 0;\n\n c->curstrm = -1;\n\n }else{\n\n if ((size = av_get_packet(s->pb, pkt, c->sndsize - 4)) < 0)\n\n return AVERROR(EIO);\n\n pkt->stream_index = 1;\n\n pkt->duration = size;\n\n c->curstrm = 0;\n\n }\n\n if(!c->cur_frame || c->curstrm)\n\n pkt->flags |= AV_PKT_FLAG_KEY;\n\n if (c->curstrm == -1)\n\n c->cur_frame++;\n\n }else{\n\n size = av_get_packet(s->pb, pkt, c->block_align);\n\n if(!size)\n\n return AVERROR_EOF;\n\n if(size < 0)\n\n return AVERROR(EIO);\n\n pkt->duration = size;\n\n }\n\n return pkt->size;\n\n}\n", + "output": "1", + "index": 12068 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int vnc_display_open(DisplayState *ds, const char *arg)\n\n{\n\n struct sockaddr *addr;\n\n struct sockaddr_in iaddr;\n\n#ifndef _WIN32\n\n struct sockaddr_un uaddr;\n\n#endif\n\n int reuse_addr, ret;\n\n socklen_t addrlen;\n\n const char *p;\n\n VncState *vs = ds ? (VncState *)ds->opaque : vnc_state;\n\n\n\n vnc_display_close(ds);\n\n if (strcmp(arg, \"none\") == 0)\n\n\treturn 0;\n\n\n\n if (!(vs->display = strdup(arg)))\n\n\treturn -1;\n\n#ifndef _WIN32\n\n if (strstart(arg, \"unix:\", &p)) {\n\n\taddr = (struct sockaddr *)&uaddr;\n\n\taddrlen = sizeof(uaddr);\n\n\n\n\tvs->lsock = socket(PF_UNIX, SOCK_STREAM, 0);\n\n\tif (vs->lsock == -1) {\n\n\t fprintf(stderr, \"Could not create socket\\n\");\n\n\t free(vs->display);\n\n\t vs->display = NULL;\n\n\t return -1;\n\n\t}\n\n\n\n\tuaddr.sun_family = AF_UNIX;\n\n\tmemset(uaddr.sun_path, 0, 108);\n\n\tsnprintf(uaddr.sun_path, 108, \"%s\", p);\n\n\n\n\tunlink(uaddr.sun_path);\n\n } else\n\n#endif\n\n {\n\n\taddr = (struct sockaddr *)&iaddr;\n\n\taddrlen = sizeof(iaddr);\n\n\n\n\tif (parse_host_port(&iaddr, arg) < 0) {\n\n\t fprintf(stderr, \"Could not parse VNC address\\n\");\n\n\t free(vs->display);\n\n\t vs->display = NULL;\n\n\t return -1;\n\n\t}\n\n\n\n\tiaddr.sin_port = htons(ntohs(iaddr.sin_port) + 5900);\n\n\n\n\tvs->lsock = socket(PF_INET, SOCK_STREAM, 0);\n\n\tif (vs->lsock == -1) {\n\n\t fprintf(stderr, \"Could not create socket\\n\");\n\n\t free(vs->display);\n\n\t vs->display = NULL;\n\n\t return -1;\n\n\t}\n\n\n\n\treuse_addr = 1;\n\n\tret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR,\n\n\t\t\t (const char *)&reuse_addr, sizeof(reuse_addr));\n\n\tif (ret == -1) {\n\n\t fprintf(stderr, \"setsockopt() failed\\n\");\n\n\t close(vs->lsock);\n\n\t vs->lsock = -1;\n\n\t free(vs->display);\n\n\t vs->display = NULL;\n\n\t return -1;\n\n\t}\n\n }\n\n\n\n if (bind(vs->lsock, addr, addrlen) == -1) {\n\n\tfprintf(stderr, \"bind() failed\\n\");\n\n\tclose(vs->lsock);\n\n\tvs->lsock = -1;\n\n\tfree(vs->display);\n\n\tvs->display = NULL;\n\n\treturn -1;\n\n }\n\n\n\n if (listen(vs->lsock, 1) == -1) {\n\n\tfprintf(stderr, \"listen() failed\\n\");\n\n\tclose(vs->lsock);\n\n\tvs->lsock = -1;\n\n\tfree(vs->display);\n\n\tvs->display = NULL;\n\n\treturn -1;\n\n }\n\n\n\n return qemu_set_fd_handler2(vs->lsock, vnc_listen_poll, vnc_listen_read, NULL, vs);\n\n}\n", + "output": "0", + "index": 19565 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_always_inline void blend_image_packed_rgb(AVFilterContext *ctx,\n\n AVFrame *dst, const AVFrame *src,\n\n int main_has_alpha, int x, int y,\n\n int is_straight)\n\n{\n\n OverlayContext *s = ctx->priv;\n\n int i, imax, j, jmax;\n\n const int src_w = src->width;\n\n const int src_h = src->height;\n\n const int dst_w = dst->width;\n\n const int dst_h = dst->height;\n\n uint8_t alpha; ///< the amount of overlay to blend on to main\n\n const int dr = s->main_rgba_map[R];\n\n const int dg = s->main_rgba_map[G];\n\n const int db = s->main_rgba_map[B];\n\n const int da = s->main_rgba_map[A];\n\n const int dstep = s->main_pix_step[0];\n\n const int sr = s->overlay_rgba_map[R];\n\n const int sg = s->overlay_rgba_map[G];\n\n const int sb = s->overlay_rgba_map[B];\n\n const int sa = s->overlay_rgba_map[A];\n\n const int sstep = s->overlay_pix_step[0];\n\n uint8_t *S, *sp, *d, *dp;\n\n\n\n i = FFMAX(-y, 0);\n\n sp = src->data[0] + i * src->linesize[0];\n\n dp = dst->data[0] + (y+i) * dst->linesize[0];\n\n\n\n for (imax = FFMIN(-y + dst_h, src_h); i < imax; i++) {\n\n j = FFMAX(-x, 0);\n\n S = sp + j * sstep;\n\n d = dp + (x+j) * dstep;\n\n\n\n for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) {\n\n alpha = S[sa];\n\n\n\n // if the main channel has an alpha channel, alpha has to be calculated\n\n // to create an un-premultiplied (straight) alpha value\n\n if (main_has_alpha && alpha != 0 && alpha != 255) {\n\n uint8_t alpha_d = d[da];\n\n alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);\n\n }\n\n\n\n switch (alpha) {\n\n case 0:\n\n break;\n\n case 255:\n\n d[dr] = S[sr];\n\n d[dg] = S[sg];\n\n d[db] = S[sb];\n\n break;\n\n default:\n\n // main_value = main_value * (1 - alpha) + overlay_value * alpha\n\n // since alpha is in the range 0-255, the result must divided by 255\n\n d[dr] = is_straight ? FAST_DIV255(d[dr] * (255 - alpha) + S[sr] * alpha) : FAST_DIV255(d[dr] * (255 - alpha) + S[sr]);\n\n d[dg] = is_straight ? FAST_DIV255(d[dg] * (255 - alpha) + S[sg] * alpha) : FAST_DIV255(d[dr] * (255 - alpha) + S[sr]);\n\n d[db] = is_straight ? FAST_DIV255(d[db] * (255 - alpha) + S[sb] * alpha) : FAST_DIV255(d[dr] * (255 - alpha) + S[sr]);\n\n }\n\n if (main_has_alpha) {\n\n switch (alpha) {\n\n case 0:\n\n break;\n\n case 255:\n\n d[da] = S[sa];\n\n break;\n\n default:\n\n // apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha\n\n d[da] += FAST_DIV255((255 - d[da]) * S[sa]);\n\n }\n\n }\n\n d += dstep;\n\n S += sstep;\n\n }\n\n dp += dst->linesize[0];\n\n sp += src->linesize[0];\n\n }\n\n}\n", + "output": "0", + "index": 23385 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)\n\n{\n\n TM2Huff huff;\n\n int res = 0;\n\n\n\n huff.val_bits = get_bits(&ctx->gb, 5);\n\n huff.max_bits = get_bits(&ctx->gb, 5);\n\n huff.min_bits = get_bits(&ctx->gb, 5);\n\n huff.nodes = get_bits_long(&ctx->gb, 17);\n\n huff.num = 0;\n\n\n\n /* check for correct codes parameters */\n\n if((huff.val_bits < 1) || (huff.val_bits > 32) ||\n\n (huff.max_bits < 0) || (huff.max_bits > 32)) {\n\n av_log(ctx->avctx, AV_LOG_ERROR, \"Incorrect tree parameters - literal length: %i, max code length: %i\\n\",\n\n huff.val_bits, huff.max_bits);\n\n return -1;\n\n }\n\n if((huff.nodes <= 0) || (huff.nodes > 0x10000)) {\n\n av_log(ctx->avctx, AV_LOG_ERROR, \"Incorrect number of Huffman tree nodes: %i\\n\", huff.nodes);\n\n return -1;\n\n }\n\n /* one-node tree */\n\n if(huff.max_bits == 0)\n\n huff.max_bits = 1;\n\n\n\n /* allocate space for codes - it is exactly ceil(nodes / 2) entries */\n\n huff.max_num = (huff.nodes + 1) >> 1;\n\n huff.nums = av_mallocz(huff.max_num * sizeof(int));\n\n huff.bits = av_mallocz(huff.max_num * sizeof(uint32_t));\n\n huff.lens = av_mallocz(huff.max_num * sizeof(int));\n\n\n\n if(tm2_read_tree(ctx, 0, 0, &huff) == -1)\n\n res = -1;\n\n\n\n if(huff.num != huff.max_num) {\n\n av_log(ctx->avctx, AV_LOG_ERROR, \"Got less codes than expected: %i of %i\\n\",\n\n huff.num, huff.max_num);\n\n res = -1;\n\n }\n\n\n\n /* convert codes to vlc_table */\n\n if(res != -1) {\n\n int i;\n\n\n\n res = init_vlc(&code->vlc, huff.max_bits, huff.max_num,\n\n huff.lens, sizeof(int), sizeof(int),\n\n huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);\n\n if(res < 0) {\n\n av_log(ctx->avctx, AV_LOG_ERROR, \"Cannot build VLC table\\n\");\n\n res = -1;\n\n } else\n\n res = 0;\n\n if(res != -1) {\n\n code->bits = huff.max_bits;\n\n code->length = huff.max_num;\n\n code->recode = av_malloc(code->length * sizeof(int));\n\n for(i = 0; i < code->length; i++)\n\n code->recode[i] = huff.nums[i];\n\n }\n\n }\n\n /* free allocated memory */\n\n av_free(huff.nums);\n\n av_free(huff.bits);\n\n av_free(huff.lens);\n\n\n\n return res;\n\n}\n", + "output": "1", + "index": 25824 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void blur(uint8_t *dst, const int dst_linesize,\n\n const uint8_t *src, const int src_linesize,\n\n const int w, const int h, FilterParam *fp)\n\n{\n\n int x, y;\n\n FilterParam f = *fp;\n\n const int radius = f.dist_width/2;\n\n\n\n const uint8_t * const src2[NB_PLANES] = { src };\n\n int src2_linesize[NB_PLANES] = { src_linesize };\n\n uint8_t *dst2[NB_PLANES] = { f.pre_filter_buf };\n\n int dst2_linesize[NB_PLANES] = { f.pre_filter_linesize };\n\n\n\n sws_scale(f.pre_filter_context, src2, src2_linesize, 0, h, dst2, dst2_linesize);\n\n\n\n#define UPDATE_FACTOR do { \\\n\n int factor; \\\n\n factor = f.color_diff_coeff[COLOR_DIFF_COEFF_SIZE/2 + pre_val - \\\n\n f.pre_filter_buf[ix + iy*f.pre_filter_linesize]] * f.dist_coeff[dx + dy*f.dist_linesize]; \\\n\n sum += src[ix + iy*src_linesize] * factor; \\\n\n div += factor; \\\n\n } while (0)\n\n\n\n for (y = 0; y < h; y++) {\n\n for (x = 0; x < w; x++) {\n\n int sum = 0;\n\n int div = 0;\n\n int dy;\n\n const int pre_val = f.pre_filter_buf[x + y*f.pre_filter_linesize];\n\n if (x >= radius && x < w - radius) {\n\n for (dy = 0; dy < radius*2 + 1; dy++) {\n\n int dx;\n\n int iy = y+dy - radius;\n\n if (iy < 0) iy = -iy;\n\n else if (iy >= h) iy = h+h-iy-1;\n\n\n\n for (dx = 0; dx < radius*2 + 1; dx++) {\n\n const int ix = x+dx - radius;\n\n UPDATE_FACTOR;\n\n }\n\n }\n\n } else {\n\n for (dy = 0; dy < radius*2+1; dy++) {\n\n int dx;\n\n int iy = y+dy - radius;\n\n if (iy < 0) iy = -iy;\n\n else if (iy >= h) iy = h+h-iy-1;\n\n\n\n for (dx = 0; dx < radius*2 + 1; dx++) {\n\n int ix = x+dx - radius;\n\n if (ix < 0) ix = -ix;\n\n else if (ix >= w) ix = w+w-ix-1;\n\n UPDATE_FACTOR;\n\n }\n\n }\n\n }\n\n dst[x + y*dst_linesize] = (sum + div/2) / div;\n\n }\n\n }\n\n}\n", + "output": "0", + "index": 26614 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "qemu_irq *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus,\n\n qemu_irq **irqs, qemu_irq irq_out)\n\n{\n\n openpic_t *opp;\n\n uint8_t *pci_conf;\n\n int i, m;\n\n\n\n /* XXX: for now, only one CPU is supported */\n\n if (nb_cpus != 1)\n\n return NULL;\n\n if (bus) {\n\n opp = (openpic_t *)pci_register_device(bus, \"OpenPIC\", sizeof(openpic_t),\n\n -1, NULL, NULL);\n\n if (opp == NULL)\n\n return NULL;\n\n pci_conf = opp->pci_dev.config;\n\n pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_IBM);\n\n pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_IBM_OPENPIC2);\n\n pci_config_set_class(pci_conf, PCI_CLASS_SYSTEM_OTHER); // FIXME?\n\n pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type\n\n pci_conf[0x3d] = 0x00; // no interrupt pin\n\n\n\n /* Register I/O spaces */\n\n pci_register_bar((PCIDevice *)opp, 0, 0x40000,\n\n PCI_BASE_ADDRESS_SPACE_MEMORY, &openpic_map);\n\n } else {\n\n opp = qemu_mallocz(sizeof(openpic_t));\n\n }\n\n opp->mem_index = cpu_register_io_memory(openpic_read,\n\n openpic_write, opp);\n\n\n\n // isu_base &= 0xFFFC0000;\n\n opp->nb_cpus = nb_cpus;\n\n opp->max_irq = OPENPIC_MAX_IRQ;\n\n opp->irq_ipi0 = OPENPIC_IRQ_IPI0;\n\n opp->irq_tim0 = OPENPIC_IRQ_TIM0;\n\n /* Set IRQ types */\n\n for (i = 0; i < OPENPIC_EXT_IRQ; i++) {\n\n opp->src[i].type = IRQ_EXTERNAL;\n\n }\n\n for (; i < OPENPIC_IRQ_TIM0; i++) {\n\n opp->src[i].type = IRQ_SPECIAL;\n\n }\n\n#if MAX_IPI > 0\n\n m = OPENPIC_IRQ_IPI0;\n\n#else\n\n m = OPENPIC_IRQ_DBL0;\n\n#endif\n\n for (; i < m; i++) {\n\n opp->src[i].type = IRQ_TIMER;\n\n }\n\n for (; i < OPENPIC_MAX_IRQ; i++) {\n\n opp->src[i].type = IRQ_INTERNAL;\n\n }\n\n for (i = 0; i < nb_cpus; i++)\n\n opp->dst[i].irqs = irqs[i];\n\n opp->irq_out = irq_out;\n\n opp->need_swap = 1;\n\n\n\n register_savevm(\"openpic\", 0, 2, openpic_save, openpic_load, opp);\n\n qemu_register_reset(openpic_reset, opp);\n\n\n\n opp->irq_raise = openpic_irq_raise;\n\n opp->reset = openpic_reset;\n\n\n\n if (pmem_index)\n\n *pmem_index = opp->mem_index;\n\n\n\n return qemu_allocate_irqs(openpic_set_irq, opp, opp->max_irq);\n\n}\n", + "output": "1", + "index": 935 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,\n\n const void *bits, int bits_wrap, int bits_size,\n\n const void *codes, int codes_wrap, int codes_size,\n\n const void *symbols, int symbols_wrap, int symbols_size,\n\n int flags)\n\n{\n\n VLCcode *buf;\n\n int i, j, ret;\n\n\n\n vlc->bits = nb_bits;\n\n if (flags & INIT_VLC_USE_NEW_STATIC) {\n\n VLC dyn_vlc = *vlc;\n\n\n\n if (vlc->table_size)\n\n return 0;\n\n\n\n ret = ff_init_vlc_sparse(&dyn_vlc, nb_bits, nb_codes,\n\n bits, bits_wrap, bits_size,\n\n codes, codes_wrap, codes_size,\n\n symbols, symbols_wrap, symbols_size,\n\n flags & ~INIT_VLC_USE_NEW_STATIC);\n\n av_assert0(ret >= 0);\n\n av_assert0(dyn_vlc.table_size <= vlc->table_allocated);\n\n if (dyn_vlc.table_size < vlc->table_allocated)\n\n av_log(NULL, AV_LOG_ERROR, \"needed %d had %d\\n\", dyn_vlc.table_size, vlc->table_allocated);\n\n memcpy(vlc->table, dyn_vlc.table, dyn_vlc.table_size * sizeof(*vlc->table));\n\n vlc->table_size = dyn_vlc.table_size;\n\n ff_free_vlc(&dyn_vlc);\n\n return 0;\n\n } else {\n\n vlc->table = NULL;\n\n vlc->table_allocated = 0;\n\n vlc->table_size = 0;\n\n }\n\n\n\n av_dlog(NULL, \"build table nb_codes=%d\\n\", nb_codes);\n\n\n\n buf = av_malloc((nb_codes + 1) * sizeof(VLCcode));\n\n\n\n\n\n av_assert0(symbols_size <= 2 || !symbols);\n\n j = 0;\n\n#define COPY(condition)\\\n\n for (i = 0; i < nb_codes; i++) { \\\n\n GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size); \\\n\n if (!(condition)) \\\n\n continue; \\\n\n if (buf[j].bits > 3*nb_bits || buf[j].bits>32) { \\\n\n av_log(NULL, AV_LOG_ERROR, \"Too long VLC (%d) in init_vlc\\n\", buf[j].bits);\\\n\n av_free(buf); \\\n\n return -1; \\\n\n } \\\n\n GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size); \\\n\n if (buf[j].code >= (1LL< nb_bits);\n\n // qsort is the slowest part of init_vlc, and could probably be improved or avoided\n\n qsort(buf, j, sizeof(VLCcode), compare_vlcspec);\n\n COPY(buf[j].bits && buf[j].bits <= nb_bits);\n\n nb_codes = j;\n\n\n\n ret = build_table(vlc, nb_bits, nb_codes, buf, flags);\n\n\n\n av_free(buf);\n\n if (ret < 0) {\n\n av_freep(&vlc->table);\n\n return ret;\n\n }\n\n return 0;\n\n}", + "output": "1", + "index": 25673 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void set_frame_data(MIContext *mi_ctx, int alpha, AVFrame *avf_out)\n\n{\n\n int x, y, plane;\n\n\n\n for (plane = 0; plane < mi_ctx->nb_planes; plane++) {\n\n int width = avf_out->width;\n\n int height = avf_out->height;\n\n int chroma = plane == 1 || plane == 2;\n\n\n\n for (y = 0; y < height; y++)\n\n for (x = 0; x < width; x++) {\n\n int x_mv, y_mv;\n\n int weight_sum = 0;\n\n int i, val = 0;\n\n Pixel *pixel = &mi_ctx->pixels[x + y * avf_out->width];\n\n\n\n for (i = 0; i < pixel->nb; i++)\n\n weight_sum += pixel->weights[i];\n\n\n\n if (!weight_sum || !pixel->nb) {\n\n pixel->weights[0] = ALPHA_MAX - alpha;\n\n pixel->refs[0] = 1;\n\n pixel->mvs[0][0] = 0;\n\n pixel->mvs[0][1] = 0;\n\n pixel->weights[1] = alpha;\n\n pixel->refs[1] = 2;\n\n pixel->mvs[1][0] = 0;\n\n pixel->mvs[1][1] = 0;\n\n pixel->nb = 2;\n\n\n\n weight_sum = ALPHA_MAX;\n\n }\n\n\n\n for (i = 0; i < pixel->nb; i++) {\n\n Frame *frame = &mi_ctx->frames[pixel->refs[i]];\n\n if (chroma) {\n\n x_mv = (x >> mi_ctx->chroma_h_shift) + (pixel->mvs[i][0] >> mi_ctx->chroma_h_shift);\n\n y_mv = (y >> mi_ctx->chroma_v_shift) + (pixel->mvs[i][1] >> mi_ctx->chroma_v_shift);\n\n } else {\n\n x_mv = x + pixel->mvs[i][0];\n\n y_mv = y + pixel->mvs[i][1];\n\n }\n\n\n\n val += pixel->weights[i] * frame->avf->data[plane][x_mv + y_mv * frame->avf->linesize[plane]];\n\n }\n\n\n\n val = ROUNDED_DIV(val, weight_sum);\n\n\n\n if (chroma)\n\n avf_out->data[plane][(x >> mi_ctx->chroma_h_shift) + (y >> mi_ctx->chroma_v_shift) * avf_out->linesize[plane]] = val;\n\n else\n\n avf_out->data[plane][x + y * avf_out->linesize[plane]] = val;\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 15116 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static const char *keyval_parse_one(QDict *qdict, const char *params,\n\n const char *implied_key,\n\n Error **errp)\n\n{\n\n const char *key, *key_end, *s;\n\n size_t len;\n\n char key_in_cur[128];\n\n QDict *cur;\n\n int ret;\n\n QObject *next;\n\n QString *val;\n\n\n\n key = params;\n\n len = strcspn(params, \"=,\");\n\n if (implied_key && len && key[len] != '=') {\n\n /* Desugar implied key */\n\n key = implied_key;\n\n len = strlen(implied_key);\n\n }\n\n key_end = key + len;\n\n\n\n /*\n\n * Loop over key fragments: @s points to current fragment, it\n\n * applies to @cur. @key_in_cur[] holds the previous fragment.\n\n */\n\n cur = qdict;\n\n s = key;\n\n for (;;) {\n\n ret = parse_qapi_name(s, false);\n\n len = ret < 0 ? 0 : ret;\n\n assert(s + len <= key_end);\n\n if (!len || (s + len < key_end && s[len] != '.')) {\n\n assert(key != implied_key);\n\n error_setg(errp, \"Invalid parameter '%.*s'\",\n\n (int)(key_end - key), key);\n\n return NULL;\n\n }\n\n if (len >= sizeof(key_in_cur)) {\n\n assert(key != implied_key);\n\n error_setg(errp, \"Parameter%s '%.*s' is too long\",\n\n s != key || s + len != key_end ? \" fragment\" : \"\",\n\n (int)len, s);\n\n return NULL;\n\n }\n\n\n\n if (s != key) {\n\n next = keyval_parse_put(cur, key_in_cur, NULL,\n\n key, s - 1, errp);\n\n if (!next) {\n\n return NULL;\n\n }\n\n cur = qobject_to_qdict(next);\n\n assert(cur);\n\n }\n\n\n\n memcpy(key_in_cur, s, len);\n\n key_in_cur[len] = 0;\n\n s += len;\n\n\n\n if (*s != '.') {\n\n break;\n\n }\n\n s++;\n\n }\n\n\n\n if (key == implied_key) {\n\n assert(!*s);\n\n s = params;\n\n } else {\n\n if (*s != '=') {\n\n error_setg(errp, \"Expected '=' after parameter '%.*s'\",\n\n (int)(s - key), key);\n\n return NULL;\n\n }\n\n s++;\n\n }\n\n\n\n val = qstring_new();\n\n for (;;) {\n\n if (!*s) {\n\n break;\n\n } else if (*s == ',') {\n\n s++;\n\n if (*s != ',') {\n\n break;\n\n }\n\n }\n\n qstring_append_chr(val, *s++);\n\n }\n\n\n\n if (!keyval_parse_put(cur, key_in_cur, val, key, key_end, errp)) {\n\n return NULL;\n\n }\n\n return s;\n\n}\n", + "output": "1", + "index": 22815 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void adjust_frame_information(ChannelElement *cpe, int chans)\n\n{\n\n int i, w, w2, g, ch;\n\n int start, maxsfb, cmaxsfb;\n\n\n\n for (ch = 0; ch < chans; ch++) {\n\n IndividualChannelStream *ics = &cpe->ch[ch].ics;\n\n start = 0;\n\n maxsfb = 0;\n\n cpe->ch[ch].pulse.num_pulse = 0;\n\n for (w = 0; w < ics->num_windows*16; w += 16) {\n\n for (g = 0; g < ics->num_swb; g++) {\n\n //apply M/S\n\n if (cpe->common_window && !ch && cpe->ms_mask[w + g]) {\n\n for (i = 0; i < ics->swb_sizes[g]; i++) {\n\n cpe->ch[0].coeffs[start+i] = (cpe->ch[0].coeffs[start+i] + cpe->ch[1].coeffs[start+i]) / 2.0;\n\n cpe->ch[1].coeffs[start+i] = cpe->ch[0].coeffs[start+i] - cpe->ch[1].coeffs[start+i];\n\n }\n\n }\n\n start += ics->swb_sizes[g];\n\n }\n\n for (cmaxsfb = ics->num_swb; cmaxsfb > 0 && cpe->ch[ch].zeroes[w+cmaxsfb-1]; cmaxsfb--)\n\n ;\n\n maxsfb = FFMAX(maxsfb, cmaxsfb);\n\n }\n\n ics->max_sfb = maxsfb;\n\n\n\n //adjust zero bands for window groups\n\n for (w = 0; w < ics->num_windows; w += ics->group_len[w]) {\n\n for (g = 0; g < ics->max_sfb; g++) {\n\n i = 1;\n\n for (w2 = w; w2 < w + ics->group_len[w]; w2++) {\n\n if (!cpe->ch[ch].zeroes[w2*16 + g]) {\n\n i = 0;\n\n break;\n\n }\n\n }\n\n cpe->ch[ch].zeroes[w*16 + g] = i;\n\n }\n\n }\n\n }\n\n\n\n if (chans > 1 && cpe->common_window) {\n\n IndividualChannelStream *ics0 = &cpe->ch[0].ics;\n\n IndividualChannelStream *ics1 = &cpe->ch[1].ics;\n\n int msc = 0;\n\n ics0->max_sfb = FFMAX(ics0->max_sfb, ics1->max_sfb);\n\n ics1->max_sfb = ics0->max_sfb;\n\n for (w = 0; w < ics0->num_windows*16; w += 16)\n\n for (i = 0; i < ics0->max_sfb; i++)\n\n if (cpe->ms_mask[w+i])\n\n msc++;\n\n if (msc == 0 || ics0->max_sfb == 0)\n\n cpe->ms_mode = 0;\n\n else\n\n cpe->ms_mode = msc < ics0->max_sfb * ics0->num_windows ? 1 : 2;\n\n }\n\n}\n", + "output": "1", + "index": 635 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void init_qxl_rom(PCIQXLDevice *d)\n\n{\n\n QXLRom *rom = memory_region_get_ram_ptr(&d->rom_bar);\n\n QXLModes *modes = (QXLModes *)(rom + 1);\n\n uint32_t ram_header_size;\n\n uint32_t surface0_area_size;\n\n uint32_t num_pages;\n\n uint32_t fb, maxfb = 0;\n\n int i;\n\n\n\n memset(rom, 0, d->rom_size);\n\n\n\n rom->magic = cpu_to_le32(QXL_ROM_MAGIC);\n\n rom->id = cpu_to_le32(d->id);\n\n rom->log_level = cpu_to_le32(d->guestdebug);\n\n rom->modes_offset = cpu_to_le32(sizeof(QXLRom));\n\n\n\n rom->slot_gen_bits = MEMSLOT_GENERATION_BITS;\n\n rom->slot_id_bits = MEMSLOT_SLOT_BITS;\n\n rom->slots_start = 1;\n\n rom->slots_end = NUM_MEMSLOTS - 1;\n\n rom->n_surfaces = cpu_to_le32(NUM_SURFACES);\n\n\n\n modes->n_modes = cpu_to_le32(ARRAY_SIZE(qxl_modes));\n\n for (i = 0; i < modes->n_modes; i++) {\n\n fb = qxl_modes[i].y_res * qxl_modes[i].stride;\n\n if (maxfb < fb) {\n\n maxfb = fb;\n\n }\n\n modes->modes[i].id = cpu_to_le32(i);\n\n modes->modes[i].x_res = cpu_to_le32(qxl_modes[i].x_res);\n\n modes->modes[i].y_res = cpu_to_le32(qxl_modes[i].y_res);\n\n modes->modes[i].bits = cpu_to_le32(qxl_modes[i].bits);\n\n modes->modes[i].stride = cpu_to_le32(qxl_modes[i].stride);\n\n modes->modes[i].x_mili = cpu_to_le32(qxl_modes[i].x_mili);\n\n modes->modes[i].y_mili = cpu_to_le32(qxl_modes[i].y_mili);\n\n modes->modes[i].orientation = cpu_to_le32(qxl_modes[i].orientation);\n\n }\n\n if (maxfb < VGA_RAM_SIZE && d->id == 0)\n\n maxfb = VGA_RAM_SIZE;\n\n\n\n ram_header_size = ALIGN(sizeof(QXLRam), 4096);\n\n surface0_area_size = ALIGN(maxfb, 4096);\n\n num_pages = d->vga.vram_size;\n\n num_pages -= ram_header_size;\n\n num_pages -= surface0_area_size;\n\n num_pages = num_pages / TARGET_PAGE_SIZE;\n\n\n\n rom->draw_area_offset = cpu_to_le32(0);\n\n rom->surface0_area_size = cpu_to_le32(surface0_area_size);\n\n rom->pages_offset = cpu_to_le32(surface0_area_size);\n\n rom->num_pages = cpu_to_le32(num_pages);\n\n rom->ram_header_offset = cpu_to_le32(d->vga.vram_size - ram_header_size);\n\n\n\n d->shadow_rom = *rom;\n\n d->rom = rom;\n\n d->modes = modes;\n\n}\n", + "output": "1", + "index": 17346 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int coroutine_fn iscsi_co_writev(BlockDriverState *bs,\n\n int64_t sector_num, int nb_sectors,\n\n QEMUIOVector *iov)\n\n{\n\n IscsiLun *iscsilun = bs->opaque;\n\n struct IscsiTask iTask;\n\n uint64_t lba;\n\n uint32_t num_sectors;\n\n uint8_t *data = NULL;\n\n uint8_t *buf = NULL;\n\n\n\n if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {\n\n return -EINVAL;\n\n }\n\n\n\n lba = sector_qemu2lun(sector_num, iscsilun);\n\n num_sectors = sector_qemu2lun(nb_sectors, iscsilun);\n\n#if !defined(LIBISCSI_FEATURE_IOVECTOR)\n\n /* if the iovec only contains one buffer we can pass it directly */\n\n if (iov->niov == 1) {\n\n data = iov->iov[0].iov_base;\n\n } else {\n\n size_t size = MIN(nb_sectors * BDRV_SECTOR_SIZE, iov->size);\n\n buf = g_malloc(size);\n\n qemu_iovec_to_buf(iov, 0, buf, size);\n\n data = buf;\n\n }\n\n#endif\n\n iscsi_co_init_iscsitask(iscsilun, &iTask);\n\nretry:\n\n if (iscsilun->use_16_for_rw) {\n\n iTask.task = iscsi_write16_task(iscsilun->iscsi, iscsilun->lun, lba,\n\n data, num_sectors * iscsilun->block_size,\n\n iscsilun->block_size, 0, 0, 0, 0, 0,\n\n iscsi_co_generic_cb, &iTask);\n\n } else {\n\n iTask.task = iscsi_write10_task(iscsilun->iscsi, iscsilun->lun, lba,\n\n data, num_sectors * iscsilun->block_size,\n\n iscsilun->block_size, 0, 0, 0, 0, 0,\n\n iscsi_co_generic_cb, &iTask);\n\n }\n\n if (iTask.task == NULL) {\n\n g_free(buf);\n\n return -ENOMEM;\n\n }\n\n#if defined(LIBISCSI_FEATURE_IOVECTOR)\n\n scsi_task_set_iov_out(iTask.task, (struct scsi_iovec *) iov->iov,\n\n iov->niov);\n\n#endif\n\n while (!iTask.complete) {\n\n iscsi_set_events(iscsilun);\n\n qemu_coroutine_yield();\n\n }\n\n\n\n if (iTask.task != NULL) {\n\n scsi_free_scsi_task(iTask.task);\n\n iTask.task = NULL;\n\n }\n\n\n\n if (iTask.do_retry) {\n\n iTask.complete = 0;\n\n goto retry;\n\n }\n\n\n\n g_free(buf);\n\n\n\n if (iTask.status != SCSI_STATUS_GOOD) {\n\n return -EIO;\n\n }\n\n\n\n iscsi_allocationmap_set(iscsilun, sector_num, nb_sectors);\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 21913 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void test_to_from_buf_1(void)\n\n{\n\n unsigned niov;\n\n struct iovec *iov;\n\n size_t sz;\n\n unsigned char *ibuf, *obuf;\n\n unsigned i, j, n;\n\n\n\n iov_random(&iov, &niov);\n\n\n\n sz = iov_size(iov, niov);\n\n\n\n ibuf = g_malloc(sz + 8) + 4;\n\n memcpy(ibuf-4, \"aaaa\", 4); memcpy(ibuf + sz, \"bbbb\", 4);\n\n obuf = g_malloc(sz + 8) + 4;\n\n memcpy(obuf-4, \"xxxx\", 4); memcpy(obuf + sz, \"yyyy\", 4);\n\n\n\n /* fill in ibuf with 0123456... */\n\n for (i = 0; i < sz; ++i) {\n\n ibuf[i] = i & 255;\n\n }\n\n\n\n for (i = 0; i <= sz; ++i) {\n\n\n\n /* Test from/to buf for offset(i) in [0..sz] up to the end of buffer.\n\n * For last iteration with offset == sz, the procedure should\n\n * skip whole vector and process exactly 0 bytes */\n\n\n\n /* first set bytes [i..sz) to some \"random\" value */\n\n n = iov_memset(iov, niov, 0, 0xff, -1);\n\n g_assert(n == sz);\n\n\n\n /* next copy bytes [i..sz) from ibuf to iovec */\n\n n = iov_from_buf(iov, niov, i, ibuf + i, -1);\n\n g_assert(n == sz - i);\n\n\n\n /* clear part of obuf */\n\n memset(obuf + i, 0, sz - i);\n\n /* and set this part of obuf to values from iovec */\n\n n = iov_to_buf(iov, niov, i, obuf + i, -1);\n\n g_assert(n == sz - i);\n\n\n\n /* now compare resulting buffers */\n\n g_assert(memcmp(ibuf, obuf, sz) == 0);\n\n\n\n /* test just one char */\n\n n = iov_to_buf(iov, niov, i, obuf + i, 1);\n\n g_assert(n == (i < sz));\n\n if (n) {\n\n g_assert(obuf[i] == (i & 255));\n\n }\n\n\n\n for (j = i; j <= sz; ++j) {\n\n /* now test num of bytes cap up to byte no. j,\n\n * with j in [i..sz]. */\n\n\n\n /* clear iovec */\n\n n = iov_memset(iov, niov, 0, 0xff, -1);\n\n g_assert(n == sz);\n\n\n\n /* copy bytes [i..j) from ibuf to iovec */\n\n n = iov_from_buf(iov, niov, i, ibuf + i, j - i);\n\n g_assert(n == j - i);\n\n\n\n /* clear part of obuf */\n\n memset(obuf + i, 0, j - i);\n\n\n\n /* copy bytes [i..j) from iovec to obuf */\n\n n = iov_to_buf(iov, niov, i, obuf + i, j - i);\n\n g_assert(n == j - i);\n\n\n\n /* verify result */\n\n g_assert(memcmp(ibuf, obuf, sz) == 0);\n\n\n\n /* now actually check if the iovec contains the right data */\n\n test_iov_bytes(iov, niov, i, j - i);\n\n }\n\n }\n\n g_assert(!memcmp(ibuf-4, \"aaaa\", 4) && !memcmp(ibuf+sz, \"bbbb\", 4));\n\n g_free(ibuf-4);\n\n g_assert(!memcmp(obuf-4, \"xxxx\", 4) && !memcmp(obuf+sz, \"yyyy\", 4));\n\n g_free(obuf-4);\n\n iov_free(iov, niov);\n\n}\n", + "output": "0", + "index": 24586 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int dirac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt)\n\n{\n\n DiracContext *s = avctx->priv_data;\n\n AVFrame *picture = data;\n\n uint8_t *buf = pkt->data;\n\n int buf_size = pkt->size;\n\n int i, data_unit_size, buf_idx = 0;\n\n int ret;\n\n\n\n /* release unused frames */\n\n for (i = 0; i < MAX_FRAMES; i++)\n\n if (s->all_frames[i].avframe->data[0] && !s->all_frames[i].avframe->reference) {\n\n av_frame_unref(s->all_frames[i].avframe);\n\n memset(s->all_frames[i].interpolated, 0, sizeof(s->all_frames[i].interpolated));\n\n }\n\n\n\n s->current_picture = NULL;\n\n *got_frame = 0;\n\n\n\n /* end of stream, so flush delayed pics */\n\n if (buf_size == 0)\n\n return get_delayed_pic(s, (AVFrame *)data, got_frame);\n\n\n\n for (;;) {\n\n /*[DIRAC_STD] Here starts the code from parse_info() defined in 9.6\n\n [DIRAC_STD] PARSE_INFO_PREFIX = \"BBCD\" as defined in ISO/IEC 646\n\n BBCD start code search */\n\n for (; buf_idx + DATA_UNIT_HEADER_SIZE < buf_size; buf_idx++) {\n\n if (buf[buf_idx ] == 'B' && buf[buf_idx+1] == 'B' &&\n\n buf[buf_idx+2] == 'C' && buf[buf_idx+3] == 'D')\n\n break;\n\n }\n\n /* BBCD found or end of data */\n\n if (buf_idx + DATA_UNIT_HEADER_SIZE >= buf_size)\n\n break;\n\n\n\n data_unit_size = AV_RB32(buf+buf_idx+5);\n\n if (data_unit_size > buf_size - buf_idx || !data_unit_size) {\n\n if(data_unit_size > buf_size - buf_idx)\n\n av_log(s->avctx, AV_LOG_ERROR,\n\n \"Data unit with size %d is larger than input buffer, discarding\\n\",\n\n data_unit_size);\n\n buf_idx += 4;\n\n continue;\n\n }\n\n /* [DIRAC_STD] dirac_decode_data_unit makes reference to the while defined in 9.3 inside the function parse_sequence() */\n\n ret = dirac_decode_data_unit(avctx, buf+buf_idx, data_unit_size);\n\n if (ret < 0)\n\n {\n\n av_log(s->avctx, AV_LOG_ERROR,\"Error in dirac_decode_data_unit\\n\");\n\n return ret;\n\n }\n\n buf_idx += data_unit_size;\n\n }\n\n\n\n if (!s->current_picture)\n\n return buf_size;\n\n\n\n if (s->current_picture->avframe->display_picture_number > s->frame_number) {\n\n DiracFrame *delayed_frame = remove_frame(s->delay_frames, s->frame_number);\n\n\n\n s->current_picture->avframe->reference |= DELAYED_PIC_REF;\n\n\n\n if (add_frame(s->delay_frames, MAX_DELAY, s->current_picture)) {\n\n int min_num = s->delay_frames[0]->avframe->display_picture_number;\n\n /* Too many delayed frames, so we display the frame with the lowest pts */\n\n av_log(avctx, AV_LOG_ERROR, \"Delay frame overflow\\n\");\n\n\n\n for (i = 1; s->delay_frames[i]; i++)\n\n if (s->delay_frames[i]->avframe->display_picture_number < min_num)\n\n min_num = s->delay_frames[i]->avframe->display_picture_number;\n\n\n\n delayed_frame = remove_frame(s->delay_frames, min_num);\n\n add_frame(s->delay_frames, MAX_DELAY, s->current_picture);\n\n }\n\n\n\n if (delayed_frame) {\n\n delayed_frame->avframe->reference ^= DELAYED_PIC_REF;\n\n if((ret=av_frame_ref(data, delayed_frame->avframe)) < 0)\n\n return ret;\n\n *got_frame = 1;\n\n }\n\n } else if (s->current_picture->avframe->display_picture_number == s->frame_number) {\n\n /* The right frame at the right time :-) */\n\n if((ret=av_frame_ref(data, s->current_picture->avframe)) < 0)\n\n return ret;\n\n *got_frame = 1;\n\n }\n\n\n\n if (*got_frame)\n\n s->frame_number = picture->display_picture_number + 1;\n\n\n\n return buf_idx;\n\n}\n", + "output": "0", + "index": 10667 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, int mb_type,\n\n int is_h264, int simple,\n\n int transform_bypass,\n\n int pixel_shift,\n\n int *block_offset,\n\n int linesize,\n\n uint8_t *dest_y, int p)\n\n{\n\n void (*idct_add)(uint8_t *dst, int16_t *block, int stride);\n\n int i;\n\n block_offset += 16 * p;\n\n if (!IS_INTRA4x4(mb_type)) {\n\n if (is_h264) {\n\n if (IS_INTRA16x16(mb_type)) {\n\n if (transform_bypass) {\n\n if (h->sps.profile_idc == 244 &&\n\n (h->intra16x16_pred_mode == VERT_PRED8x8 ||\n\n h->intra16x16_pred_mode == HOR_PRED8x8)) {\n\n h->hpc.pred16x16_add[h->intra16x16_pred_mode](dest_y, block_offset,\n\n h->mb + (p * 256 << pixel_shift),\n\n linesize);\n\n } else {\n\n for (i = 0; i < 16; i++)\n\n if (h->non_zero_count_cache[scan8[i + p * 16]] ||\n\n dctcoef_get(h->mb, pixel_shift, i * 16 + p * 256))\n\n h->h264dsp.h264_add_pixels4(dest_y + block_offset[i],\n\n h->mb + (i * 16 + p * 256 << pixel_shift),\n\n linesize);\n\n }\n\n } else {\n\n h->h264dsp.h264_idct_add16intra(dest_y, block_offset,\n\n h->mb + (p * 256 << pixel_shift),\n\n linesize,\n\n h->non_zero_count_cache + p * 5 * 8);\n\n }\n\n } else if (h->cbp & 15) {\n\n if (transform_bypass) {\n\n const int di = IS_8x8DCT(mb_type) ? 4 : 1;\n\n idct_add = IS_8x8DCT(mb_type) ? h->h264dsp.h264_add_pixels8\n\n : h->h264dsp.h264_add_pixels4;\n\n for (i = 0; i < 16; i += di)\n\n if (h->non_zero_count_cache[scan8[i + p * 16]])\n\n idct_add(dest_y + block_offset[i],\n\n h->mb + (i * 16 + p * 256 << pixel_shift),\n\n linesize);\n\n } else {\n\n if (IS_8x8DCT(mb_type))\n\n h->h264dsp.h264_idct8_add4(dest_y, block_offset,\n\n h->mb + (p * 256 << pixel_shift),\n\n linesize,\n\n h->non_zero_count_cache + p * 5 * 8);\n\n else\n\n h->h264dsp.h264_idct_add16(dest_y, block_offset,\n\n h->mb + (p * 256 << pixel_shift),\n\n linesize,\n\n h->non_zero_count_cache + p * 5 * 8);\n\n }\n\n }\n\n } else if (CONFIG_SVQ3_DECODER) {\n\n for (i = 0; i < 16; i++)\n\n if (h->non_zero_count_cache[scan8[i + p * 16]] || h->mb[i * 16 + p * 256]) {\n\n // FIXME benchmark weird rule, & below\n\n uint8_t *const ptr = dest_y + block_offset[i];\n\n ff_svq3_add_idct_c(ptr, h->mb + i * 16 + p * 256, linesize,\n\n h->qscale, IS_INTRA(mb_type) ? 1 : 0);\n\n }\n\n }\n\n }\n\n}\n", + "output": "0", + "index": 10939 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void flush_encoders(void)\n\n{\n\n int i, ret;\n\n\n\n for (i = 0; i < nb_output_streams; i++) {\n\n OutputStream *ost = output_streams[i];\n\n AVCodecContext *enc = ost->enc_ctx;\n\n OutputFile *of = output_files[ost->file_index];\n\n\n\n if (!ost->encoding_needed)\n\n continue;\n\n\n\n // Try to enable encoding with no input frames.\n\n // Maybe we should just let encoding fail instead.\n\n if (!ost->initialized) {\n\n FilterGraph *fg = ost->filter->graph;\n\n char error[1024];\n\n\n\n av_log(NULL, AV_LOG_WARNING,\n\n \"Finishing stream %d:%d without any data written to it.\\n\",\n\n ost->file_index, ost->st->index);\n\n\n\n if (ost->filter && !fg->graph) {\n\n int x;\n\n for (x = 0; x < fg->nb_inputs; x++) {\n\n InputFilter *ifilter = fg->inputs[x];\n\n if (ifilter->format < 0) {\n\n AVCodecParameters *par = ifilter->ist->st->codecpar;\n\n // We never got any input. Set a fake format, which will\n\n // come from libavformat.\n\n ifilter->format = par->format;\n\n ifilter->sample_rate = par->sample_rate;\n\n ifilter->channels = par->channels;\n\n ifilter->channel_layout = par->channel_layout;\n\n ifilter->width = par->width;\n\n ifilter->height = par->height;\n\n ifilter->sample_aspect_ratio = par->sample_aspect_ratio;\n\n }\n\n }\n\n\n\n if (!ifilter_has_all_input_formats(fg))\n\n continue;\n\n\n\n ret = configure_filtergraph(fg);\n\n if (ret < 0) {\n\n av_log(NULL, AV_LOG_ERROR, \"Error configuring filter graph\\n\");\n\n exit_program(1);\n\n }\n\n\n\n finish_output_stream(ost);\n\n }\n\n\n\n ret = init_output_stream(ost, error, sizeof(error));\n\n if (ret < 0) {\n\n av_log(NULL, AV_LOG_ERROR, \"Error initializing output stream %d:%d -- %s\\n\",\n\n ost->file_index, ost->index, error);\n\n exit_program(1);\n\n }\n\n }\n\n\n\n if (enc->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <= 1)\n\n continue;\n\n#if FF_API_LAVF_FMT_RAWPICTURE\n\n if (enc->codec_type == AVMEDIA_TYPE_VIDEO && (of->ctx->oformat->flags & AVFMT_RAWPICTURE) && enc->codec->id == AV_CODEC_ID_RAWVIDEO)\n\n continue;\n\n#endif\n\n\n\n if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO)\n\n continue;\n\n\n\n avcodec_send_frame(enc, NULL);\n\n\n\n for (;;) {\n\n const char *desc = NULL;\n\n AVPacket pkt;\n\n int pkt_size;\n\n\n\n switch (enc->codec_type) {\n\n case AVMEDIA_TYPE_AUDIO:\n\n desc = \"audio\";\n\n break;\n\n case AVMEDIA_TYPE_VIDEO:\n\n desc = \"video\";\n\n break;\n\n default:\n\n av_assert0(0);\n\n }\n\n\n\n av_init_packet(&pkt);\n\n pkt.data = NULL;\n\n pkt.size = 0;\n\n\n\n update_benchmark(NULL);\n\n ret = avcodec_receive_packet(enc, &pkt);\n\n update_benchmark(\"flush_%s %d.%d\", desc, ost->file_index, ost->index);\n\n if (ret < 0 && ret != AVERROR_EOF) {\n\n av_log(NULL, AV_LOG_FATAL, \"%s encoding failed: %s\\n\",\n\n desc,\n\n av_err2str(ret));\n\n exit_program(1);\n\n }\n\n if (ost->logfile && enc->stats_out) {\n\n fprintf(ost->logfile, \"%s\", enc->stats_out);\n\n }\n\n if (ret == AVERROR_EOF) {\n\n break;\n\n }\n\n if (ost->finished & MUXER_FINISHED) {\n\n av_packet_unref(&pkt);\n\n continue;\n\n }\n\n av_packet_rescale_ts(&pkt, enc->time_base, ost->mux_timebase);\n\n pkt_size = pkt.size;\n\n output_packet(of, &pkt, ost);\n\n if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) {\n\n do_video_stats(ost, pkt_size);\n\n }\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 17942 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void ff_h264_pred_init_x86(H264PredContext *h, int codec_id)\n\n{\n\n mm_flags = mm_support();\n\n\n\n#if HAVE_YASM\n\n if (mm_flags & FF_MM_MMX) {\n\n h->pred16x16[VERT_PRED8x8] = ff_pred16x16_vertical_mmx;\n\n h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_mmx;\n\n h->pred8x8 [VERT_PRED8x8] = ff_pred8x8_vertical_mmx;\n\n h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmx;\n\n if (codec_id == CODEC_ID_VP8) {\n\n h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_tm_vp8_mmx;\n\n h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_tm_vp8_mmx;\n\n h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_mmx;\n\n }\n\n }\n\n\n\n if (mm_flags & FF_MM_MMX2) {\n\n h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_mmxext;\n\n h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_mmxext;\n\n h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmxext;\n\n h->pred4x4 [DC_PRED ] = ff_pred4x4_dc_mmxext;\n\n if (codec_id == CODEC_ID_VP8) {\n\n h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_tm_vp8_mmxext;\n\n h->pred8x8 [DC_PRED8x8 ] = ff_pred8x8_dc_rv40_mmxext;\n\n h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_tm_vp8_mmxext;\n\n h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_mmxext;\n\n h->pred4x4 [VERT_PRED ] = ff_pred4x4_vertical_vp8_mmxext;\n\n }\n\n }\n\n\n\n if (mm_flags & FF_MM_SSE) {\n\n h->pred16x16[VERT_PRED8x8] = ff_pred16x16_vertical_sse;\n\n h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_sse;\n\n }\n\n\n\n if (mm_flags & FF_MM_SSE2) {\n\n h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_sse2;\n\n if (codec_id == CODEC_ID_VP8) {\n\n h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_tm_vp8_sse2;\n\n h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_tm_vp8_sse2;\n\n }\n\n }\n\n\n\n if (mm_flags & FF_MM_SSSE3) {\n\n h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_ssse3;\n\n h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_ssse3;\n\n h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_ssse3;\n\n if (codec_id == CODEC_ID_VP8) {\n\n h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_tm_vp8_ssse3;\n\n h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_ssse3;\n\n }\n\n }\n\n#endif\n\n}\n", + "output": "0", + "index": 15679 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,\n\n AVPacket *avpkt) {\n\n const uint8_t *buf = avpkt->data;\n\n int buf_size = avpkt->size;\n\n AVSContext *h = avctx->priv_data;\n\n MpegEncContext *s = &h->s;\n\n int input_size;\n\n const uint8_t *buf_end;\n\n const uint8_t *buf_ptr;\n\n AVFrame *picture = data;\n\n uint32_t stc = -1;\n\n\n\n s->avctx = avctx;\n\n\n\n if (buf_size == 0) {\n\n if (!s->low_delay && h->DPB[0].f.data[0]) {\n\n *data_size = sizeof(AVPicture);\n\n *picture = *(AVFrame *) &h->DPB[0];\n\n }\n\n return 0;\n\n }\n\n\n\n buf_ptr = buf;\n\n buf_end = buf + buf_size;\n\n for(;;) {\n\n buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc);\n\n if(stc & 0xFFFFFE00)\n\n return FFMAX(0, buf_ptr - buf - s->parse_context.last_index);\n\n input_size = (buf_end - buf_ptr)*8;\n\n switch(stc) {\n\n case CAVS_START_CODE:\n\n init_get_bits(&s->gb, buf_ptr, input_size);\n\n decode_seq_header(h);\n\n break;\n\n case PIC_I_START_CODE:\n\n if(!h->got_keyframe) {\n\n if(h->DPB[0].f.data[0])\n\n avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]);\n\n if(h->DPB[1].f.data[0])\n\n avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]);\n\n h->got_keyframe = 1;\n\n }\n\n case PIC_PB_START_CODE:\n\n *data_size = 0;\n\n if(!h->got_keyframe)\n\n break;\n\n init_get_bits(&s->gb, buf_ptr, input_size);\n\n h->stc = stc;\n\n if(decode_pic(h))\n\n break;\n\n *data_size = sizeof(AVPicture);\n\n if(h->pic_type != AV_PICTURE_TYPE_B) {\n\n if(h->DPB[1].f.data[0]) {\n\n *picture = *(AVFrame *) &h->DPB[1];\n\n } else {\n\n *data_size = 0;\n\n }\n\n } else\n\n *picture = *(AVFrame *) &h->picture;\n\n break;\n\n case EXT_START_CODE:\n\n //mpeg_decode_extension(avctx,buf_ptr, input_size);\n\n break;\n\n case USER_START_CODE:\n\n //mpeg_decode_user_data(avctx,buf_ptr, input_size);\n\n break;\n\n default:\n\n if (stc <= SLICE_MAX_START_CODE) {\n\n init_get_bits(&s->gb, buf_ptr, input_size);\n\n decode_slice_header(h, &s->gb);\n\n }\n\n break;\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 10617 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void avc_luma_mid_8w_msa(const uint8_t *src, int32_t src_stride,\n\n uint8_t *dst, int32_t dst_stride,\n\n int32_t height)\n\n{\n\n uint32_t loop_cnt;\n\n v16i8 src0, src1, src2, src3, src4;\n\n v16i8 mask0, mask1, mask2;\n\n v8i16 hz_out0, hz_out1, hz_out2, hz_out3;\n\n v8i16 hz_out4, hz_out5, hz_out6, hz_out7, hz_out8;\n\n v8i16 dst0, dst1, dst2, dst3;\n\n v16u8 out0, out1;\n\n\n\n LD_SB3(&luma_mask_arr[0], 16, mask0, mask1, mask2);\n\n\n\n LD_SB5(src, src_stride, src0, src1, src2, src3, src4);\n\n XORI_B5_128_SB(src0, src1, src2, src3, src4);\n\n src += (5 * src_stride);\n\n\n\n hz_out0 = AVC_HORZ_FILTER_SH(src0, src0, mask0, mask1, mask2);\n\n hz_out1 = AVC_HORZ_FILTER_SH(src1, src1, mask0, mask1, mask2);\n\n hz_out2 = AVC_HORZ_FILTER_SH(src2, src2, mask0, mask1, mask2);\n\n hz_out3 = AVC_HORZ_FILTER_SH(src3, src3, mask0, mask1, mask2);\n\n hz_out4 = AVC_HORZ_FILTER_SH(src4, src4, mask0, mask1, mask2);\n\n\n\n for (loop_cnt = (height >> 2); loop_cnt--;) {\n\n LD_SB4(src, src_stride, src0, src1, src2, src3);\n\n XORI_B4_128_SB(src0, src1, src2, src3);\n\n src += (4 * src_stride);\n\n\n\n hz_out5 = AVC_HORZ_FILTER_SH(src0, src0, mask0, mask1, mask2);\n\n hz_out6 = AVC_HORZ_FILTER_SH(src1, src1, mask0, mask1, mask2);\n\n hz_out7 = AVC_HORZ_FILTER_SH(src2, src2, mask0, mask1, mask2);\n\n hz_out8 = AVC_HORZ_FILTER_SH(src3, src3, mask0, mask1, mask2);\n\n dst0 = AVC_CALC_DPADD_H_6PIX_2COEFF_SH(hz_out0, hz_out1, hz_out2,\n\n hz_out3, hz_out4, hz_out5);\n\n dst1 = AVC_CALC_DPADD_H_6PIX_2COEFF_SH(hz_out1, hz_out2, hz_out3,\n\n hz_out4, hz_out5, hz_out6);\n\n dst2 = AVC_CALC_DPADD_H_6PIX_2COEFF_SH(hz_out2, hz_out3, hz_out4,\n\n hz_out5, hz_out6, hz_out7);\n\n dst3 = AVC_CALC_DPADD_H_6PIX_2COEFF_SH(hz_out3, hz_out4, hz_out5,\n\n hz_out6, hz_out7, hz_out8);\n\n out0 = PCKEV_XORI128_UB(dst0, dst1);\n\n out1 = PCKEV_XORI128_UB(dst2, dst3);\n\n ST8x4_UB(out0, out1, dst, dst_stride);\n\n\n\n dst += (4 * dst_stride);\n\n hz_out3 = hz_out7;\n\n hz_out1 = hz_out5;\n\n hz_out5 = hz_out4;\n\n hz_out4 = hz_out8;\n\n hz_out2 = hz_out6;\n\n hz_out0 = hz_out5;\n\n }\n\n}\n", + "output": "0", + "index": 24368 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void vnc_connect(VncDisplay *vd, int csock,\n\n bool skipauth, bool websocket)\n\n{\n\n VncState *vs = g_malloc0(sizeof(VncState));\n\n int i;\n\n\n\n vs->csock = csock;\n\n vs->vd = vd;\n\n\n\n if (skipauth) {\n\n\tvs->auth = VNC_AUTH_NONE;\n\n\tvs->subauth = VNC_AUTH_INVALID;\n\n } else {\n\n if (websocket) {\n\n vs->auth = vd->ws_auth;\n\n vs->subauth = VNC_AUTH_INVALID;\n\n } else {\n\n vs->auth = vd->auth;\n\n vs->subauth = vd->subauth;\n\n }\n\n }\n\n VNC_DEBUG(\"Client sock=%d ws=%d auth=%d subauth=%d\\n\",\n\n csock, websocket, vs->auth, vs->subauth);\n\n\n\n vs->lossy_rect = g_malloc0(VNC_STAT_ROWS * sizeof (*vs->lossy_rect));\n\n for (i = 0; i < VNC_STAT_ROWS; ++i) {\n\n vs->lossy_rect[i] = g_malloc0(VNC_STAT_COLS * sizeof (uint8_t));\n\n }\n\n\n\n VNC_DEBUG(\"New client on socket %d\\n\", csock);\n\n update_displaychangelistener(&vd->dcl, VNC_REFRESH_INTERVAL_BASE);\n\n qemu_set_nonblock(vs->csock);\n\n#ifdef CONFIG_VNC_WS\n\n if (websocket) {\n\n vs->websocket = 1;\n\n#ifdef CONFIG_VNC_TLS\n\n if (vd->ws_tls) {\n\n qemu_set_fd_handler(vs->csock, vncws_tls_handshake_io, NULL, vs);\n\n } else\n\n#endif /* CONFIG_VNC_TLS */\n\n {\n\n qemu_set_fd_handler(vs->csock, vncws_handshake_read, NULL, vs);\n\n }\n\n } else\n\n#endif /* CONFIG_VNC_WS */\n\n {\n\n qemu_set_fd_handler(vs->csock, vnc_client_read, NULL, vs);\n\n }\n\n\n\n vnc_client_cache_addr(vs);\n\n vnc_qmp_event(vs, QAPI_EVENT_VNC_CONNECTED);\n\n vnc_set_share_mode(vs, VNC_SHARE_MODE_CONNECTING);\n\n\n\n#ifdef CONFIG_VNC_WS\n\n if (!vs->websocket)\n\n#endif\n\n {\n\n vnc_init_state(vs);\n\n }\n\n\n\n if (vd->num_connecting > vd->connections_limit) {\n\n QTAILQ_FOREACH(vs, &vd->clients, next) {\n\n if (vs->share_mode == VNC_SHARE_MODE_CONNECTING) {\n\n vnc_disconnect_start(vs);\n\n return;\n\n }\n\n }\n\n }\n\n}\n", + "output": "0", + "index": 9948 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "AVAES *av_aes_init(uint8_t *key, int key_bits, int decrypt) {\n\n AVAES *a;\n\n int i, j, t, rconpointer = 0;\n\n uint8_t tk[8][4];\n\n int KC= key_bits>>5;\n\n int rounds= KC + 6;\n\n uint8_t log8[256];\n\n uint8_t alog8[512];\n\n\n\n if(!sbox[255]){\n\n j=1;\n\n for(i=0; i<255; i++){\n\n alog8[i]=\n\n alog8[i+255]= j;\n\n log8[j]= i;\n\n j^= j+j;\n\n if(j>255) j^= 0x11B;\n\n }\n\n for(i=0; i<256; i++){\n\n j= i ? alog8[255-log8[i]] : 0;\n\n j ^= (j<<1) ^ (j<<2) ^ (j<<3) ^ (j<<4);\n\n j = (j ^ (j>>8) ^ 99) & 255;\n\n inv_sbox[j]= i;\n\n sbox [i]= j;\n\n }\n\n init_multbl2(dec_multbl[0], (int[4]){0xe, 0x9, 0xd, 0xb}, log8, alog8, inv_sbox);\n\n init_multbl2(enc_multbl[0], (int[4]){0x2, 0x1, 0x1, 0x3}, log8, alog8, sbox);\n\n }\n\n\n\n if(key_bits!=128 && key_bits!=192 && key_bits!=256)\n\n return NULL;\n\n\n\n a= av_malloc(sizeof(AVAES));\n\n a->rounds= rounds;\n\n\n\n memcpy(tk, key, KC*4);\n\n\n\n for(t= 0; t < (rounds+1)*4;) {\n\n memcpy(a->round_key[0][t], tk, KC*4);\n\n t+= KC;\n\n\n\n for(i = 0; i < 4; i++)\n\n tk[0][i] ^= sbox[tk[KC-1][(i+1)&3]];\n\n tk[0][0] ^= rcon[rconpointer++];\n\n\n\n for(j = 1; j < KC; j++){\n\n if(KC != 8 || j != KC>>1)\n\n for(i = 0; i < 4; i++) tk[j][i] ^= tk[j-1][i];\n\n else\n\n for(i = 0; i < 4; i++) tk[j][i] ^= sbox[tk[j-1][i]];\n\n }\n\n }\n\n\n\n if(decrypt){\n\n for(i=1; iround_key[i][0][j]= sbox[a->round_key[i][0][j]];\n\n mix(a->round_key[i], dec_multbl);\n\n }\n\n }else{\n\n for(i=0; i<(rounds+1)>>1; i++){\n\n for(j=0; j<16; j++)\n\n FFSWAP(int, a->round_key[i][0][j], a->round_key[rounds-i][0][j]);\n\n }\n\n }\n\n\n\n return a;\n\n}\n", + "output": "0", + "index": 21753 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int advanced_decode_picture_header(VC9Context *v)\n\n{\n\n static const int type_table[4] = { P_TYPE, B_TYPE, I_TYPE, BI_TYPE };\n\n int type, i, ret;\n\n\n\n if (v->interlace)\n\n {\n\n v->fcm = get_bits(&v->gb, 1);\n\n if (v->fcm) v->fcm = 2+get_bits(&v->gb, 1);\n\n }\n\n\n\n type = get_prefix(&v->gb, 0, 4);\n\n if (type > 4 || type < 0) return FRAME_SKIPED;\n\n v->pict_type = type_table[type];\n\n av_log(v->avctx, AV_LOG_INFO, \"AP Frame Type: %i\\n\", v->pict_type);\n\n\n\n if (v->tfcntrflag) v->tfcntr = get_bits(&v->gb, 8);\n\n if (v->broadcast)\n\n {\n\n if (!v->interlace) v->rptfrm = get_bits(&v->gb, 2);\n\n else\n\n {\n\n v->tff = get_bits(&v->gb, 1);\n\n v->rff = get_bits(&v->gb, 1);\n\n }\n\n }\n\n\n\n if (v->panscanflag)\n\n {\n\n#if 0\n\n for (i=0; inumpanscanwin; i++)\n\n {\n\n v->topleftx[i] = get_bits(&v->gb, 16);\n\n v->toplefty[i] = get_bits(&v->gb, 16);\n\n v->bottomrightx[i] = get_bits(&v->gb, 16);\n\n v->bottomrighty[i] = get_bits(&v->gb, 16);\n\n }\n\n#else\n\n skip_bits(&v->gb, 16*4*v->numpanscanwin);\n\n#endif\n\n }\n\n v->rndctrl = get_bits(&v->gb, 1);\n\n v->uvsamp = get_bits(&v->gb, 1);\n\n if (v->finterpflag == 1) v->interpfrm = get_bits(&v->gb, 1);\n\n\n\n switch(v->pict_type)\n\n {\n\n case I_TYPE: if (decode_i_picture_header(v) < 0) return -1;\n\n case P_TYPE: if (decode_p_picture_header(v) < 0) return -1;\n\n case BI_TYPE:\n\n case B_TYPE: if (decode_b_picture_header(v) < 0) return FRAME_SKIPED;\n\n default: break;\n\n }\n\n\n\n /* AC/DC Syntax */\n\n v->transacfrm = get_bits(&v->gb, 1);\n\n if (v->transacfrm) v->transacfrm += get_bits(&v->gb, 1);\n\n if (v->pict_type == I_TYPE || v->pict_type == BI_TYPE)\n\n {\n\n v->transacfrm2 = get_bits(&v->gb, 1);\n\n if (v->transacfrm2) v->transacfrm2 += get_bits(&v->gb, 1);\n\n }\n\n v->transacdctab = get_bits(&v->gb, 1);\n\n if (v->pict_type == I_TYPE) vop_dquant_decoding(v);\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 4410 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int coroutine_fn iscsi_co_writev(BlockDriverState *bs,\n\n int64_t sector_num, int nb_sectors,\n\n QEMUIOVector *iov)\n\n{\n\n IscsiLun *iscsilun = bs->opaque;\n\n struct IscsiTask iTask;\n\n uint64_t lba;\n\n uint32_t num_sectors;\n\n int fua;\n\n\n\n if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {\n\n return -EINVAL;\n\n }\n\n\n\n if (bs->bl.max_transfer_length && nb_sectors > bs->bl.max_transfer_length) {\n\n error_report(\"iSCSI Error: Write of %d sectors exceeds max_xfer_len \"\n\n \"of %d sectors\", nb_sectors, bs->bl.max_transfer_length);\n\n return -EINVAL;\n\n }\n\n\n\n lba = sector_qemu2lun(sector_num, iscsilun);\n\n num_sectors = sector_qemu2lun(nb_sectors, iscsilun);\n\n iscsi_co_init_iscsitask(iscsilun, &iTask);\n\nretry:\n\n fua = iscsilun->dpofua && !bdrv_enable_write_cache(bs);\n\n iTask.force_next_flush = !fua;\n\n if (iscsilun->use_16_for_rw) {\n\n iTask.task = iscsi_write16_task(iscsilun->iscsi, iscsilun->lun, lba,\n\n NULL, num_sectors * iscsilun->block_size,\n\n iscsilun->block_size, 0, 0, fua, 0, 0,\n\n iscsi_co_generic_cb, &iTask);\n\n } else {\n\n iTask.task = iscsi_write10_task(iscsilun->iscsi, iscsilun->lun, lba,\n\n NULL, num_sectors * iscsilun->block_size,\n\n iscsilun->block_size, 0, 0, fua, 0, 0,\n\n iscsi_co_generic_cb, &iTask);\n\n }\n\n if (iTask.task == NULL) {\n\n return -ENOMEM;\n\n }\n\n scsi_task_set_iov_out(iTask.task, (struct scsi_iovec *) iov->iov,\n\n iov->niov);\n\n while (!iTask.complete) {\n\n iscsi_set_events(iscsilun);\n\n qemu_coroutine_yield();\n\n }\n\n\n\n if (iTask.task != NULL) {\n\n scsi_free_scsi_task(iTask.task);\n\n iTask.task = NULL;\n\n }\n\n\n\n if (iTask.do_retry) {\n\n iTask.complete = 0;\n\n goto retry;\n\n }\n\n\n\n if (iTask.status != SCSI_STATUS_GOOD) {\n\n return iTask.err_code;\n\n }\n\n\n\n iscsi_allocationmap_set(iscsilun, sector_num, nb_sectors);\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 15889 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,\n\n const int32_t *ubuf[2], const int32_t *vbuf[2],\n\n const int32_t *abuf0, uint16_t *dest, int dstW,\n\n int uvalpha, int y, enum AVPixelFormat target, int hasAlpha, int eightbytes)\n\n{\n\n const int32_t *ubuf0 = ubuf[0], *vbuf0 = vbuf[0];\n\n int i;\n\n int A = 0xffff<<14;\n\n\n\n if (uvalpha < 2048) {\n\n for (i = 0; i < dstW; i++) {\n\n int Y = (buf0[i]) >> 2;\n\n int U = (ubuf0[i] + (-128 << 11)) >> 2;\n\n int V = (vbuf0[i] + (-128 << 11)) >> 2;\n\n int R, G, B;\n\n\n\n Y -= c->yuv2rgb_y_offset;\n\n Y *= c->yuv2rgb_y_coeff;\n\n Y += 1 << 13;\n\n\n\n if (hasAlpha) {\n\n A = abuf0[i] << 11;\n\n\n\n A += 1 << 13;\n\n }\n\n\n\n R = V * c->yuv2rgb_v2r_coeff;\n\n G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;\n\n B = U * c->yuv2rgb_u2b_coeff;\n\n\n\n output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);\n\n output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);\n\n output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);\n\n if (eightbytes) {\n\n output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);\n\n dest += 4;\n\n } else {\n\n dest += 3;\n\n }\n\n }\n\n } else {\n\n const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];\n\n int A = 0xffff<<14;\n\n for (i = 0; i < dstW; i++) {\n\n int Y = (buf0[i] ) >> 2;\n\n int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;\n\n int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3;\n\n int R, G, B;\n\n\n\n Y -= c->yuv2rgb_y_offset;\n\n Y *= c->yuv2rgb_y_coeff;\n\n Y += 1 << 13;\n\n\n\n if (hasAlpha) {\n\n A = abuf0[i] << 11;\n\n\n\n A += 1 << 13;\n\n }\n\n\n\n R = V * c->yuv2rgb_v2r_coeff;\n\n G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;\n\n B = U * c->yuv2rgb_u2b_coeff;\n\n\n\n output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);\n\n output_pixel(&dest[1], av_clip_uintp2( G + Y, 30) >> 14);\n\n output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);\n\n if (eightbytes) {\n\n output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);\n\n dest += 4;\n\n } else {\n\n dest += 3;\n\n }\n\n }\n\n }\n\n}\n", + "output": "0", + "index": 16727 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int dca_subframe_footer(DCAContext *s, int base_channel)\n\n{\n\n int in, out, aux_data_count, aux_data_end, reserved;\n\n uint32_t nsyncaux;\n\n\n\n /*\n\n * Unpack optional information\n\n */\n\n\n\n /* presumably optional information only appears in the core? */\n\n if (!base_channel) {\n\n if (s->timestamp)\n\n skip_bits_long(&s->gb, 32);\n\n\n\n if (s->aux_data) {\n\n aux_data_count = get_bits(&s->gb, 6);\n\n\n\n // align (32-bit)\n\n skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);\n\n\n\n aux_data_end = 8 * aux_data_count + get_bits_count(&s->gb);\n\n\n\n if ((nsyncaux = get_bits_long(&s->gb, 32)) != DCA_NSYNCAUX) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"nSYNCAUX mismatch %#\"PRIx32\"\\n\",\n\n nsyncaux);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n if (get_bits1(&s->gb)) { // bAUXTimeStampFlag\n\n avpriv_request_sample(s->avctx,\n\n \"Auxiliary Decode Time Stamp Flag\");\n\n // align (4-bit)\n\n skip_bits(&s->gb, (-get_bits_count(&s->gb)) & 4);\n\n // 44 bits: nMSByte (8), nMarker (4), nLSByte (28), nMarker (4)\n\n skip_bits_long(&s->gb, 44);\n\n }\n\n\n\n if ((s->core_downmix = get_bits1(&s->gb))) {\n\n int am = get_bits(&s->gb, 3);\n\n switch (am) {\n\n case 0:\n\n s->core_downmix_amode = DCA_MONO;\n\n break;\n\n case 1:\n\n s->core_downmix_amode = DCA_STEREO;\n\n break;\n\n case 2:\n\n s->core_downmix_amode = DCA_STEREO_TOTAL;\n\n break;\n\n case 3:\n\n s->core_downmix_amode = DCA_3F;\n\n break;\n\n case 4:\n\n s->core_downmix_amode = DCA_2F1R;\n\n break;\n\n case 5:\n\n s->core_downmix_amode = DCA_2F2R;\n\n break;\n\n case 6:\n\n s->core_downmix_amode = DCA_3F1R;\n\n break;\n\n default:\n\n av_log(s->avctx, AV_LOG_ERROR,\n\n \"Invalid mode %d for embedded downmix coefficients\\n\",\n\n am);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n for (out = 0; out < ff_dca_channels[s->core_downmix_amode]; out++) {\n\n for (in = 0; in < s->audio_header.prim_channels + !!s->lfe; in++) {\n\n uint16_t tmp = get_bits(&s->gb, 9);\n\n if ((tmp & 0xFF) > 241) {\n\n av_log(s->avctx, AV_LOG_ERROR,\n\n \"Invalid downmix coefficient code %\"PRIu16\"\\n\",\n\n tmp);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n s->core_downmix_codes[in][out] = tmp;\n\n }\n\n }\n\n }\n\n\n\n align_get_bits(&s->gb); // byte align\n\n skip_bits(&s->gb, 16); // nAUXCRC16\n\n\n\n // additional data (reserved, cf. ETSI TS 102 114 V1.4.1)\n\n if ((reserved = (aux_data_end - get_bits_count(&s->gb))) < 0) {\n\n av_log(s->avctx, AV_LOG_ERROR,\n\n \"Overread auxiliary data by %d bits\\n\", -reserved);\n\n return AVERROR_INVALIDDATA;\n\n } else if (reserved) {\n\n avpriv_request_sample(s->avctx,\n\n \"Core auxiliary data reserved content\");\n\n skip_bits_long(&s->gb, reserved);\n\n }\n\n }\n\n\n\n if (s->crc_present && s->dynrange)\n\n get_bits(&s->gb, 16);\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 13104 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int submit_packet(PerThreadContext *p, AVPacket *avpkt)\n\n{\n\n FrameThreadContext *fctx = p->parent;\n\n PerThreadContext *prev_thread = fctx->prev_thread;\n\n const AVCodec *codec = p->avctx->codec;\n\n\n\n if (!avpkt->size && !(codec->capabilities & AV_CODEC_CAP_DELAY))\n\n return 0;\n\n\n\n pthread_mutex_lock(&p->mutex);\n\n\n\n release_delayed_buffers(p);\n\n\n\n if (prev_thread) {\n\n int err;\n\n if (prev_thread->state == STATE_SETTING_UP) {\n\n pthread_mutex_lock(&prev_thread->progress_mutex);\n\n while (prev_thread->state == STATE_SETTING_UP)\n\n pthread_cond_wait(&prev_thread->progress_cond, &prev_thread->progress_mutex);\n\n pthread_mutex_unlock(&prev_thread->progress_mutex);\n\n }\n\n\n\n err = update_context_from_thread(p->avctx, prev_thread->avctx, 0);\n\n if (err) {\n\n pthread_mutex_unlock(&p->mutex);\n\n return err;\n\n }\n\n }\n\n\n\n av_packet_unref(&p->avpkt);\n\n av_packet_ref(&p->avpkt, avpkt);\n\n\n\n p->state = STATE_SETTING_UP;\n\n pthread_cond_signal(&p->input_cond);\n\n pthread_mutex_unlock(&p->mutex);\n\n\n\n /*\n\n * If the client doesn't have a thread-safe get_buffer(),\n\n * then decoding threads call back to the main thread,\n\n * and it calls back to the client here.\n\n */\n\n\n\n if (!p->avctx->thread_safe_callbacks && (\n\n p->avctx->get_format != avcodec_default_get_format ||\n\n p->avctx->get_buffer2 != avcodec_default_get_buffer2)) {\n\n while (p->state != STATE_SETUP_FINISHED && p->state != STATE_INPUT_READY) {\n\n int call_done = 1;\n\n pthread_mutex_lock(&p->progress_mutex);\n\n while (p->state == STATE_SETTING_UP)\n\n pthread_cond_wait(&p->progress_cond, &p->progress_mutex);\n\n\n\n switch (p->state) {\n\n case STATE_GET_BUFFER:\n\n p->result = ff_get_buffer(p->avctx, p->requested_frame, p->requested_flags);\n\n break;\n\n case STATE_GET_FORMAT:\n\n p->result_format = ff_get_format(p->avctx, p->available_formats);\n\n break;\n\n default:\n\n call_done = 0;\n\n break;\n\n }\n\n if (call_done) {\n\n p->state = STATE_SETTING_UP;\n\n pthread_cond_signal(&p->progress_cond);\n\n }\n\n pthread_mutex_unlock(&p->progress_mutex);\n\n }\n\n }\n\n\n\n fctx->prev_thread = p;\n\n fctx->next_decoding++;\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 12183 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "CpuInfoList *qmp_query_cpus(Error **errp)\n\n{\n\n MachineState *ms = MACHINE(qdev_get_machine());\n\n MachineClass *mc = MACHINE_GET_CLASS(ms);\n\n CpuInfoList *head = NULL, *cur_item = NULL;\n\n CPUState *cpu;\n\n\n\n CPU_FOREACH(cpu) {\n\n CpuInfoList *info;\n\n#if defined(TARGET_I386)\n\n X86CPU *x86_cpu = X86_CPU(cpu);\n\n CPUX86State *env = &x86_cpu->env;\n\n#elif defined(TARGET_PPC)\n\n PowerPCCPU *ppc_cpu = POWERPC_CPU(cpu);\n\n CPUPPCState *env = &ppc_cpu->env;\n\n#elif defined(TARGET_SPARC)\n\n SPARCCPU *sparc_cpu = SPARC_CPU(cpu);\n\n CPUSPARCState *env = &sparc_cpu->env;\n\n#elif defined(TARGET_MIPS)\n\n MIPSCPU *mips_cpu = MIPS_CPU(cpu);\n\n CPUMIPSState *env = &mips_cpu->env;\n\n#elif defined(TARGET_TRICORE)\n\n TriCoreCPU *tricore_cpu = TRICORE_CPU(cpu);\n\n CPUTriCoreState *env = &tricore_cpu->env;\n\n#endif\n\n\n\n cpu_synchronize_state(cpu);\n\n\n\n info = g_malloc0(sizeof(*info));\n\n info->value = g_malloc0(sizeof(*info->value));\n\n info->value->CPU = cpu->cpu_index;\n\n info->value->current = (cpu == first_cpu);\n\n info->value->halted = cpu->halted;\n\n info->value->qom_path = object_get_canonical_path(OBJECT(cpu));\n\n info->value->thread_id = cpu->thread_id;\n\n#if defined(TARGET_I386)\n\n info->value->arch = CPU_INFO_ARCH_X86;\n\n info->value->u.x86.pc = env->eip + env->segs[R_CS].base;\n\n#elif defined(TARGET_PPC)\n\n info->value->arch = CPU_INFO_ARCH_PPC;\n\n info->value->u.ppc.nip = env->nip;\n\n#elif defined(TARGET_SPARC)\n\n info->value->arch = CPU_INFO_ARCH_SPARC;\n\n info->value->u.q_sparc.pc = env->pc;\n\n info->value->u.q_sparc.npc = env->npc;\n\n#elif defined(TARGET_MIPS)\n\n info->value->arch = CPU_INFO_ARCH_MIPS;\n\n info->value->u.q_mips.PC = env->active_tc.PC;\n\n#elif defined(TARGET_TRICORE)\n\n info->value->arch = CPU_INFO_ARCH_TRICORE;\n\n info->value->u.tricore.PC = env->PC;\n\n#else\n\n info->value->arch = CPU_INFO_ARCH_OTHER;\n\n#endif\n\n\n\n\n\n\n\n\n\n\n /* XXX: waiting for the qapi to support GSList */\n\n if (!cur_item) {\n\n head = cur_item = info;\n\n } else {\n\n cur_item->next = info;\n\n cur_item = info;\n\n\n\n\n\n return head;\n", + "output": "1", + "index": 24030 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb)\n\n{\n\n ASFContext *asf = s->priv_data;\n\n uint32_t packet_length, padsize;\n\n int rsize = 8;\n\n int c, d, e, off;\n\n\n\n // if we do not know packet size, allow skipping up to 32 kB\n\n off= 32768;\n\n if (s->packet_size > 0)\n\n off= (avio_tell(pb) - s->data_offset) % s->packet_size + 3;\n\n\n\n c=d=e=-1;\n\n while(off-- > 0){\n\n c=d; d=e;\n\n e= avio_r8(pb);\n\n if(c == 0x82 && !d && !e)\n\n break;\n\n\n\n\n if (c != 0x82) {\n\n /**\n\n * This code allows handling of -EAGAIN at packet boundaries (i.e.\n\n * if the packet sync code above triggers -EAGAIN). This does not\n\n * imply complete -EAGAIN handling support at random positions in\n\n * the stream.\n\n */\n\n if (pb->error == AVERROR(EAGAIN))\n\n return AVERROR(EAGAIN);\n\n if (!pb->eof_reached)\n\n av_log(s, AV_LOG_ERROR, \"ff asf bad header %x at:%\"PRId64\"\\n\", c, avio_tell(pb));\n\n\n if ((c & 0x8f) == 0x82) {\n\n if (d || e) {\n\n if (!pb->eof_reached)\n\n av_log(s, AV_LOG_ERROR, \"ff asf bad non zero\\n\");\n\n\n\n c= avio_r8(pb);\n\n d= avio_r8(pb);\n\n rsize+=3;\n\n }else{\n\n avio_seek(pb, -1, SEEK_CUR); //FIXME\n\n\n\n\n asf->packet_flags = c;\n\n asf->packet_property = d;\n\n\n\n DO_2BITS(asf->packet_flags >> 5, packet_length, s->packet_size);\n\n DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored\n\n DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length\n\n\n\n //the following checks prevent overflows and infinite loops\n\n if(!packet_length || packet_length >= (1U<<29)){\n\n av_log(s, AV_LOG_ERROR, \"invalid packet_length %d at:%\"PRId64\"\\n\", packet_length, avio_tell(pb));\n\n\n\n if(padsize >= packet_length){\n\n av_log(s, AV_LOG_ERROR, \"invalid padsize %d at:%\"PRId64\"\\n\", padsize, avio_tell(pb));\n\n\n\n\n\n asf->packet_timestamp = avio_rl32(pb);\n\n avio_rl16(pb); /* duration */\n\n // rsize has at least 11 bytes which have to be present\n\n\n\n if (asf->packet_flags & 0x01) {\n\n asf->packet_segsizetype = avio_r8(pb); rsize++;\n\n asf->packet_segments = asf->packet_segsizetype & 0x3f;\n\n } else {\n\n asf->packet_segments = 1;\n\n asf->packet_segsizetype = 0x80;\n\n\n\n\n\n\n\n\n\n asf->packet_size_left = packet_length - padsize - rsize;\n\n if (packet_length < asf->hdr.min_pktsize)\n\n padsize += asf->hdr.min_pktsize - packet_length;\n\n asf->packet_padsize = padsize;\n\n av_dlog(s, \"packet: size=%d padsize=%d left=%d\\n\", s->packet_size, asf->packet_padsize, asf->packet_size_left);\n\n return 0;\n", + "output": "1", + "index": 19159 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold int flic_decode_init(AVCodecContext *avctx)\n\n{\n\n FlicDecodeContext *s = avctx->priv_data;\n\n unsigned char *fli_header = (unsigned char *)avctx->extradata;\n\n int depth;\n\n\n\n if (avctx->extradata_size != 0 &&\n\n avctx->extradata_size != 12 &&\n\n avctx->extradata_size != 128 &&\n\n avctx->extradata_size != 1024) {\n\n av_log(avctx, AV_LOG_ERROR, \"Expected extradata of 12, 128 or 1024 bytes\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n s->avctx = avctx;\n\n\n\n if (s->avctx->extradata_size == 12) {\n\n /* special case for magic carpet FLIs */\n\n s->fli_type = FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE;\n\n depth = 8;\n\n } else if (avctx->extradata_size == 1024) {\n\n uint8_t *ptr = avctx->extradata;\n\n int i;\n\n\n\n for (i = 0; i < 256; i++) {\n\n s->palette[i] = AV_RL32(ptr);\n\n ptr += 4;\n\n }\n\n depth = 8;\n\n } else if (avctx->extradata_size == 0) {\n\n /* FLI in MOV, see e.g. FFmpeg trac issue #626 */\n\n s->fli_type = FLI_TYPE_CODE;\n\n depth = 8;\n\n } else {\n\n s->fli_type = AV_RL16(&fli_header[4]);\n\n depth = AV_RL16(&fli_header[12]);\n\n }\n\n\n\n if (depth == 0) {\n\n depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */\n\n }\n\n\n\n if ((s->fli_type == FLC_FLX_TYPE_CODE) && (depth == 16)) {\n\n depth = 15; /* Original Autodesk FLX's say the depth is 16Bpp when it is really 15Bpp */\n\n }\n\n\n\n switch (depth) {\n\n case 8 : avctx->pix_fmt = PIX_FMT_PAL8; break;\n\n case 15 : avctx->pix_fmt = PIX_FMT_RGB555; break;\n\n case 16 : avctx->pix_fmt = PIX_FMT_RGB565; break;\n\n case 24 : avctx->pix_fmt = PIX_FMT_BGR24; /* Supposedly BGR, but havent any files to test with */\n\n av_log(avctx, AV_LOG_ERROR, \"24Bpp FLC/FLX is unsupported due to no test files.\\n\");\n\n return -1;\n\n default :\n\n av_log(avctx, AV_LOG_ERROR, \"Unknown FLC/FLX depth of %d Bpp is unsupported.\\n\",depth);\n\n return -1;\n\n }\n\n\n\n avcodec_get_frame_defaults(&s->frame);\n\n s->frame.data[0] = NULL;\n\n s->new_palette = 0;\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 19695 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void RENAME(yuv2rgb555_1)(SwsContext *c, const uint16_t *buf0,\n\n const uint16_t *ubuf0, const uint16_t *ubuf1,\n\n const uint16_t *vbuf0, const uint16_t *vbuf1,\n\n const uint16_t *abuf0, uint8_t *dest,\n\n int dstW, int uvalpha, enum PixelFormat dstFormat,\n\n int flags, int y)\n\n{\n\n x86_reg uv_off = c->uv_off << 1;\n\n const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1\n\n\n\n if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster\n\n __asm__ volatile(\n\n \"mov %%\"REG_b\", \"ESP_OFFSET\"(%5) \\n\\t\"\n\n \"mov %4, %%\"REG_b\" \\n\\t\"\n\n \"push %%\"REG_BP\" \\n\\t\"\n\n YSCALEYUV2RGB1(%%REGBP, %5, %6)\n\n \"pxor %%mm7, %%mm7 \\n\\t\"\n\n /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\n\n#ifdef DITHER1XBPP\n\n \"paddusb \"BLUE_DITHER\"(%5), %%mm2 \\n\\t\"\n\n \"paddusb \"GREEN_DITHER\"(%5), %%mm4 \\n\\t\"\n\n \"paddusb \"RED_DITHER\"(%5), %%mm5 \\n\\t\"\n\n#endif\n\n WRITERGB15(%%REGb, 8280(%5), %%REGBP)\n\n \"pop %%\"REG_BP\" \\n\\t\"\n\n \"mov \"ESP_OFFSET\"(%5), %%\"REG_b\" \\n\\t\"\n\n :: \"c\" (buf0), \"d\" (buf1), \"S\" (ubuf0), \"D\" (ubuf1), \"m\" (dest),\n\n \"a\" (&c->redDither), \"m\"(uv_off)\n\n );\n\n } else {\n\n __asm__ volatile(\n\n \"mov %%\"REG_b\", \"ESP_OFFSET\"(%5) \\n\\t\"\n\n \"mov %4, %%\"REG_b\" \\n\\t\"\n\n \"push %%\"REG_BP\" \\n\\t\"\n\n YSCALEYUV2RGB1b(%%REGBP, %5, %6)\n\n \"pxor %%mm7, %%mm7 \\n\\t\"\n\n /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\n\n#ifdef DITHER1XBPP\n\n \"paddusb \"BLUE_DITHER\"(%5), %%mm2 \\n\\t\"\n\n \"paddusb \"GREEN_DITHER\"(%5), %%mm4 \\n\\t\"\n\n \"paddusb \"RED_DITHER\"(%5), %%mm5 \\n\\t\"\n\n#endif\n\n WRITERGB15(%%REGb, 8280(%5), %%REGBP)\n\n \"pop %%\"REG_BP\" \\n\\t\"\n\n \"mov \"ESP_OFFSET\"(%5), %%\"REG_b\" \\n\\t\"\n\n :: \"c\" (buf0), \"d\" (buf1), \"S\" (ubuf0), \"D\" (ubuf1), \"m\" (dest),\n\n \"a\" (&c->redDither), \"m\"(uv_off)\n\n );\n\n }\n\n}\n", + "output": "1", + "index": 18954 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3)\n\n{\n\n uint64_t addr = env->regs[r1];\n\n uint64_t subcode = env->regs[r3];\n\n IplParameterBlock *iplb;\n\n\n\n if (env->psw.mask & PSW_MASK_PSTATE) {\n\n program_interrupt(env, PGM_PRIVILEGED, ILEN_LATER_INC);\n\n return;\n\n }\n\n\n\n if ((subcode & ~0x0ffffULL) || (subcode > 6)) {\n\n program_interrupt(env, PGM_SPECIFICATION, ILEN_LATER_INC);\n\n return;\n\n }\n\n\n\n switch (subcode) {\n\n case 0:\n\n modified_clear_reset(s390_env_get_cpu(env));\n\n if (tcg_enabled()) {\n\n cpu_loop_exit(CPU(s390_env_get_cpu(env)));\n\n }\n\n break;\n\n case 1:\n\n load_normal_reset(s390_env_get_cpu(env));\n\n if (tcg_enabled()) {\n\n cpu_loop_exit(CPU(s390_env_get_cpu(env)));\n\n }\n\n break;\n\n case 3:\n\n s390_reipl_request();\n\n if (tcg_enabled()) {\n\n cpu_loop_exit(CPU(s390_env_get_cpu(env)));\n\n }\n\n break;\n\n case 5:\n\n if ((r1 & 1) || (addr & 0x0fffULL)) {\n\n program_interrupt(env, PGM_SPECIFICATION, ILEN_LATER_INC);\n\n return;\n\n }\n\n if (!address_space_access_valid(&address_space_memory, addr,\n\n sizeof(IplParameterBlock), false)) {\n\n program_interrupt(env, PGM_ADDRESSING, ILEN_LATER_INC);\n\n return;\n\n }\n\n iplb = g_malloc0(sizeof(IplParameterBlock));\n\n cpu_physical_memory_read(addr, iplb, sizeof(iplb->len));\n\n if (!iplb_valid_len(iplb)) {\n\n env->regs[r1 + 1] = DIAG_308_RC_INVALID;\n\n goto out;\n\n }\n\n\n\n cpu_physical_memory_read(addr, iplb, be32_to_cpu(iplb->len));\n\n\n\n if (!iplb_valid_ccw(iplb) && !iplb_valid_fcp(iplb)) {\n\n env->regs[r1 + 1] = DIAG_308_RC_INVALID;\n\n goto out;\n\n }\n\n\n\n s390_ipl_update_diag308(iplb);\n\n env->regs[r1 + 1] = DIAG_308_RC_OK;\n\nout:\n\n g_free(iplb);\n\n return;\n\n case 6:\n\n if ((r1 & 1) || (addr & 0x0fffULL)) {\n\n program_interrupt(env, PGM_SPECIFICATION, ILEN_LATER_INC);\n\n return;\n\n }\n\n if (!address_space_access_valid(&address_space_memory, addr,\n\n sizeof(IplParameterBlock), true)) {\n\n program_interrupt(env, PGM_ADDRESSING, ILEN_LATER_INC);\n\n return;\n\n }\n\n iplb = s390_ipl_get_iplb();\n\n if (iplb) {\n\n cpu_physical_memory_write(addr, iplb, be32_to_cpu(iplb->len));\n\n env->regs[r1 + 1] = DIAG_308_RC_OK;\n\n } else {\n\n env->regs[r1 + 1] = DIAG_308_RC_NO_CONF;\n\n }\n\n return;\n\n default:\n\n hw_error(\"Unhandled diag308 subcode %\" PRIx64, subcode);\n\n break;\n\n }\n\n}\n", + "output": "0", + "index": 19194 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,\n\n int size, int type,\n\n uint32_t **lace_buf, int *laces)\n\n{\n\n int res = 0, n;\n\n uint8_t *data = *buf;\n\n uint32_t *lace_size;\n\n\n\n if (!type) {\n\n *laces = 1;\n\n *lace_buf = av_mallocz(sizeof(int));\n\n if (!*lace_buf)\n\n return AVERROR(ENOMEM);\n\n\n\n *lace_buf[0] = size;\n\n return 0;\n\n }\n\n\n\n assert(size > 0);\n\n *laces = *data + 1;\n\n data += 1;\n\n size -= 1;\n\n lace_size = av_mallocz(*laces * sizeof(int));\n\n if (!lace_size)\n\n return AVERROR(ENOMEM);\n\n\n\n switch (type) {\n\n case 0x1: /* Xiph lacing */ {\n\n uint8_t temp;\n\n uint32_t total = 0;\n\n for (n = 0; res == 0 && n < *laces - 1; n++) {\n\n while (1) {\n\n if (size == 0) {\n\n res = AVERROR_EOF;\n\n break;\n\n }\n\n temp = *data;\n\n lace_size[n] += temp;\n\n data += 1;\n\n size -= 1;\n\n if (temp != 0xff)\n\n break;\n\n }\n\n total += lace_size[n];\n\n }\n\n if (size <= total) {\n\n res = AVERROR_INVALIDDATA;\n\n break;\n\n }\n\n\n\n lace_size[n] = size - total;\n\n break;\n\n }\n\n\n\n case 0x2: /* fixed-size lacing */\n\n if (size != (size / *laces) * size) {\n\n res = AVERROR_INVALIDDATA;\n\n break;\n\n }\n\n for (n = 0; n < *laces; n++)\n\n lace_size[n] = size / *laces;\n\n break;\n\n\n\n case 0x3: /* EBML lacing */ {\n\n uint64_t num;\n\n uint32_t total;\n\n n = matroska_ebmlnum_uint(matroska, data, size, &num);\n\n if (n < 0) {\n\n av_log(matroska->ctx, AV_LOG_INFO,\n\n \"EBML block data error\\n\");\n\n res = n;\n\n break;\n\n }\n\n data += n;\n\n size -= n;\n\n total = lace_size[0] = num;\n\n for (n = 1; res == 0 && n < *laces - 1; n++) {\n\n int64_t snum;\n\n int r;\n\n r = matroska_ebmlnum_sint(matroska, data, size, &snum);\n\n if (r < 0) {\n\n av_log(matroska->ctx, AV_LOG_INFO,\n\n \"EBML block data error\\n\");\n\n res = r;\n\n break;\n\n }\n\n data += r;\n\n size -= r;\n\n lace_size[n] = lace_size[n - 1] + snum;\n\n total += lace_size[n];\n\n }\n\n if (size <= total) {\n\n res = AVERROR_INVALIDDATA;\n\n break;\n\n }\n\n lace_size[*laces - 1] = size - total;\n\n break;\n\n }\n\n }\n\n\n\n *buf = data;\n\n *lace_buf = lace_size;\n\n\n\n return res;\n\n}\n", + "output": "1", + "index": 39 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_slice(AVCodecContext *c, void *arg)\n\n{\n\n FFV1Context *fs = *(void **)arg;\n\n FFV1Context *f = fs->avctx->priv_data;\n\n int width, height, x, y, ret;\n\n const int ps = (av_pix_fmt_desc_get(c->pix_fmt)->flags & AV_PIX_FMT_FLAG_PLANAR)\n\n ? (c->bits_per_raw_sample > 8) + 1\n\n : 4;\n\n AVFrame *const p = f->cur;\n\n\n\n if (f->version > 2) {\n\n if (decode_slice_header(f, fs) < 0) {\n\n fs->slice_damaged = 1;\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n if ((ret = ffv1_init_slice_state(f, fs)) < 0)\n\n return ret;\n\n if (f->cur->key_frame)\n\n ffv1_clear_slice_state(f, fs);\n\n width = fs->slice_width;\n\n height = fs->slice_height;\n\n x = fs->slice_x;\n\n y = fs->slice_y;\n\n\n\n if (!fs->ac) {\n\n if (f->version == 3 && f->minor_version > 1 || f->version > 3)\n\n get_rac(&fs->c, (uint8_t[]) { 129 });\n\n fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0;\n\n init_get_bits(&fs->gb, fs->c.bytestream_start + fs->ac_byte_count,\n\n (fs->c.bytestream_end - fs->c.bytestream_start -\n\n fs->ac_byte_count) * 8);\n\n }\n\n\n\n av_assert1(width && height);\n\n if (f->colorspace == 0) {\n\n const int chroma_width = -((-width) >> f->chroma_h_shift);\n\n const int chroma_height = -((-height) >> f->chroma_v_shift);\n\n const int cx = x >> f->chroma_h_shift;\n\n const int cy = y >> f->chroma_v_shift;\n\n decode_plane(fs, p->data[0] + ps * x + y * p->linesize[0], width,\n\n height, p->linesize[0],\n\n 0);\n\n\n\n if (f->chroma_planes) {\n\n decode_plane(fs, p->data[1] + ps * cx + cy * p->linesize[1],\n\n chroma_width, chroma_height, p->linesize[1],\n\n 1);\n\n decode_plane(fs, p->data[2] + ps * cx + cy * p->linesize[2],\n\n chroma_width, chroma_height, p->linesize[2],\n\n 1);\n\n }\n\n if (fs->transparency)\n\n decode_plane(fs, p->data[3] + ps * x + y * p->linesize[3], width,\n\n height, p->linesize[3],\n\n 2);\n\n } else {\n\n uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0],\n\n p->data[1] + ps * x + y * p->linesize[1],\n\n p->data[2] + ps * x + y * p->linesize[2] };\n\n decode_rgb_frame(fs, planes, width, height, p->linesize);\n\n }\n\n if (fs->ac && f->version > 2) {\n\n int v;\n\n get_rac(&fs->c, (uint8_t[]) { 129 });\n\n v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5 * f->ec;\n\n if (v) {\n\n av_log(f->avctx, AV_LOG_ERROR, \"bytestream end mismatching by %d\\n\",\n\n v);\n\n fs->slice_damaged = 1;\n\n }\n\n }\n\n\n\n emms_c();\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 4056 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int buffer_needs_copy(PadContext *s, AVFrame *frame, AVBufferRef *buf)\n\n{\n\n int planes[4] = { -1, -1, -1, -1}, *p = planes;\n\n int i, j;\n\n\n\n /* get all planes in this buffer */\n\n for (i = 0; i < FF_ARRAY_ELEMS(planes) && frame->data[i]; i++) {\n\n if (av_frame_get_plane_buffer(frame, i) == buf)\n\n *p++ = i;\n\n }\n\n\n\n /* for each plane in this buffer, check that it can be padded without\n\n * going over buffer bounds or other planes */\n\n for (i = 0; i < FF_ARRAY_ELEMS(planes) && planes[i] >= 0; i++) {\n\n int hsub = (planes[i] == 1 || planes[i] == 2) ? s->hsub : 0;\n\n int vsub = (planes[i] == 1 || planes[i] == 2) ? s->vsub : 0;\n\n\n\n uint8_t *start = frame->data[planes[i]];\n\n uint8_t *end = start + (frame->height >> hsub) *\n\n frame->linesize[planes[i]];\n\n\n\n /* amount of free space needed before the start and after the end\n\n * of the plane */\n\n ptrdiff_t req_start = (s->x >> hsub) * s->line_step[planes[i]] +\n\n (s->y >> vsub) * frame->linesize[planes[i]];\n\n ptrdiff_t req_end = ((s->w - s->x - frame->width) >> hsub) *\n\n s->line_step[planes[i]] +\n\n (s->y >> vsub) * frame->linesize[planes[i]];\n\n\n\n if (frame->linesize[planes[i]] < (s->w >> hsub) * s->line_step[planes[i]])\n\n return 1;\n\n if (start - buf->data < req_start ||\n\n (buf->data + buf->size) - end < req_end)\n\n return 1;\n\n\n\n#define SIGN(x) ((x) > 0 ? 1 : -1)\n\n for (j = 0; j < FF_ARRAY_ELEMS(planes) & planes[j] >= 0; j++) {\n\n int hsub1 = (planes[j] == 1 || planes[j] == 2) ? s->hsub : 0;\n\n uint8_t *start1 = frame->data[planes[j]];\n\n uint8_t *end1 = start1 + (frame->height >> hsub1) *\n\n frame->linesize[planes[j]];\n\n if (i == j)\n\n continue;\n\n\n\n if (SIGN(start - end1) != SIGN(start - end1 - req_start) ||\n\n SIGN(end - start1) != SIGN(end - start1 + req_end))\n\n return 1;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 9836 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,\n\n ram_addr_t size, void *host)\n\n{\n\n RAMBlock *new_block, *block;\n\n\n\n size = TARGET_PAGE_ALIGN(size);\n\n new_block = qemu_mallocz(sizeof(*new_block));\n\n\n\n if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) {\n\n char *id = dev->parent_bus->info->get_dev_path(dev);\n\n if (id) {\n\n snprintf(new_block->idstr, sizeof(new_block->idstr), \"%s/\", id);\n\n qemu_free(id);\n\n\n\n pstrcat(new_block->idstr, sizeof(new_block->idstr), name);\n\n\n\n QLIST_FOREACH(block, &ram_list.blocks, next) {\n\n if (!strcmp(block->idstr, new_block->idstr)) {\n\n fprintf(stderr, \"RAMBlock \\\"%s\\\" already registered, abort!\\n\",\n\n new_block->idstr);\n\n\n\n\n\n\n new_block->offset = find_ram_offset(size);\n\n if (host) {\n\n new_block->host = host;\n\n new_block->flags |= RAM_PREALLOC_MASK;\n\n } else {\n\n if (mem_path) {\n\n#if defined (__linux__) && !defined(TARGET_S390X)\n\n new_block->host = file_ram_alloc(new_block, size, mem_path);\n\n if (!new_block->host) {\n\n new_block->host = qemu_vmalloc(size);\n\n qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE);\n\n\n#else\n\n fprintf(stderr, \"-mem-path option unsupported\\n\");\n\n exit(1);\n\n#endif\n\n } else {\n\n#if defined(TARGET_S390X) && defined(CONFIG_KVM)\n\n /* S390 KVM requires the topmost vma of the RAM to be smaller than\n\n an system defined value, which is at least 256GB. Larger systems\n\n have larger values. We put the guest between the end of data\n\n segment (system break) and this value. We use 32GB as a base to\n\n have enough room for the system break to grow. */\n\n new_block->host = mmap((void*)0x800000000, size,\n\n PROT_EXEC|PROT_READ|PROT_WRITE,\n\n MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0);\n\n\n\n\n\n#else\n\n if (xen_mapcache_enabled()) {\n\n xen_ram_alloc(new_block->offset, size);\n\n } else {\n\n new_block->host = qemu_vmalloc(size);\n\n\n#endif\n\n qemu_madvise(new_block->host, size, QEMU_MADV_MERGEABLE);\n\n\n\n new_block->length = size;\n\n\n\n QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);\n\n\n\n ram_list.phys_dirty = qemu_realloc(ram_list.phys_dirty,\n\n last_ram_offset() >> TARGET_PAGE_BITS);\n\n memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),\n\n 0xff, size >> TARGET_PAGE_BITS);\n\n\n\n if (kvm_enabled())\n\n kvm_setup_guest_memory(new_block->host, size);\n\n\n\n return new_block->offset;\n", + "output": "1", + "index": 23807 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int coroutine_fn backup_do_cow(BlockDriverState *bs,\n\n int64_t sector_num, int nb_sectors,\n\n bool *error_is_read,\n\n bool is_write_notifier)\n\n{\n\n BackupBlockJob *job = (BackupBlockJob *)bs->job;\n\n CowRequest cow_request;\n\n struct iovec iov;\n\n QEMUIOVector bounce_qiov;\n\n void *bounce_buffer = NULL;\n\n int ret = 0;\n\n int64_t sectors_per_cluster = cluster_size_sectors(job);\n\n int64_t start, end;\n\n int n;\n\n\n\n qemu_co_rwlock_rdlock(&job->flush_rwlock);\n\n\n\n start = sector_num / sectors_per_cluster;\n\n end = DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster);\n\n\n\n trace_backup_do_cow_enter(job, start, sector_num, nb_sectors);\n\n\n\n wait_for_overlapping_requests(job, start, end);\n\n cow_request_begin(&cow_request, job, start, end);\n\n\n\n for (; start < end; start++) {\n\n if (hbitmap_get(job->bitmap, start)) {\n\n trace_backup_do_cow_skip(job, start);\n\n continue; /* already copied */\n\n }\n\n\n\n trace_backup_do_cow_process(job, start);\n\n\n\n n = MIN(sectors_per_cluster,\n\n job->common.len / BDRV_SECTOR_SIZE -\n\n start * sectors_per_cluster);\n\n\n\n if (!bounce_buffer) {\n\n bounce_buffer = qemu_blockalign(bs, job->cluster_size);\n\n }\n\n iov.iov_base = bounce_buffer;\n\n iov.iov_len = n * BDRV_SECTOR_SIZE;\n\n qemu_iovec_init_external(&bounce_qiov, &iov, 1);\n\n\n\n if (is_write_notifier) {\n\n ret = bdrv_co_readv_no_serialising(bs,\n\n start * sectors_per_cluster,\n\n n, &bounce_qiov);\n\n } else {\n\n ret = bdrv_co_readv(bs, start * sectors_per_cluster, n,\n\n &bounce_qiov);\n\n }\n\n if (ret < 0) {\n\n trace_backup_do_cow_read_fail(job, start, ret);\n\n if (error_is_read) {\n\n *error_is_read = true;\n\n }\n\n goto out;\n\n }\n\n\n\n if (buffer_is_zero(iov.iov_base, iov.iov_len)) {\n\n ret = bdrv_co_write_zeroes(job->target,\n\n start * sectors_per_cluster,\n\n n, BDRV_REQ_MAY_UNMAP);\n\n } else {\n\n ret = bdrv_co_writev(job->target,\n\n start * sectors_per_cluster, n,\n\n &bounce_qiov);\n\n }\n\n if (ret < 0) {\n\n trace_backup_do_cow_write_fail(job, start, ret);\n\n if (error_is_read) {\n\n *error_is_read = false;\n\n }\n\n goto out;\n\n }\n\n\n\n hbitmap_set(job->bitmap, start, 1);\n\n\n\n /* Publish progress, guest I/O counts as progress too. Note that the\n\n * offset field is an opaque progress value, it is not a disk offset.\n\n */\n\n job->sectors_read += n;\n\n job->common.offset += n * BDRV_SECTOR_SIZE;\n\n }\n\n\n\nout:\n\n if (bounce_buffer) {\n\n qemu_vfree(bounce_buffer);\n\n }\n\n\n\n cow_request_end(&cow_request);\n\n\n\n trace_backup_do_cow_return(job, sector_num, nb_sectors, ret);\n\n\n\n qemu_co_rwlock_unlock(&job->flush_rwlock);\n\n\n\n return ret;\n\n}\n", + "output": "0", + "index": 14088 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int qemu_chr_open_win_stdio(QemuOpts *opts, CharDriverState **_chr)\n\n{\n\n CharDriverState *chr;\n\n WinStdioCharState *stdio;\n\n DWORD dwMode;\n\n int is_console = 0;\n\n\n\n if (stdio_nb_clients >= STDIO_MAX_CLIENTS\n\n || ((display_type != DT_NOGRAPHIC) && (stdio_nb_clients != 0))) {\n\n return -EIO;\n\n }\n\n\n\n chr = g_malloc0(sizeof(CharDriverState));\n\n stdio = g_malloc0(sizeof(WinStdioCharState));\n\n\n\n stdio->hStdIn = GetStdHandle(STD_INPUT_HANDLE);\n\n if (stdio->hStdIn == INVALID_HANDLE_VALUE) {\n\n fprintf(stderr, \"cannot open stdio: invalid handle\\n\");\n\n exit(1);\n\n }\n\n\n\n is_console = GetConsoleMode(stdio->hStdIn, &dwMode) != 0;\n\n\n\n chr->opaque = stdio;\n\n chr->chr_write = win_stdio_write;\n\n chr->chr_close = win_stdio_close;\n\n\n\n if (stdio_nb_clients == 0) {\n\n if (is_console) {\n\n if (qemu_add_wait_object(stdio->hStdIn,\n\n win_stdio_wait_func, chr)) {\n\n fprintf(stderr, \"qemu_add_wait_object: failed\\n\");\n\n }\n\n } else {\n\n DWORD dwId;\n\n\n\n stdio->hInputReadyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);\n\n stdio->hInputDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL);\n\n stdio->hInputThread = CreateThread(NULL, 0, win_stdio_thread,\n\n chr, 0, &dwId);\n\n\n\n if (stdio->hInputThread == INVALID_HANDLE_VALUE\n\n || stdio->hInputReadyEvent == INVALID_HANDLE_VALUE\n\n || stdio->hInputDoneEvent == INVALID_HANDLE_VALUE) {\n\n fprintf(stderr, \"cannot create stdio thread or event\\n\");\n\n exit(1);\n\n }\n\n if (qemu_add_wait_object(stdio->hInputReadyEvent,\n\n win_stdio_thread_wait_func, chr)) {\n\n fprintf(stderr, \"qemu_add_wait_object: failed\\n\");\n\n }\n\n }\n\n }\n\n\n\n dwMode |= ENABLE_LINE_INPUT;\n\n\n\n stdio_clients[stdio_nb_clients++] = chr;\n\n if (stdio_nb_clients == 1 && is_console) {\n\n /* set the terminal in raw mode */\n\n /* ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS */\n\n dwMode |= ENABLE_PROCESSED_INPUT;\n\n }\n\n\n\n SetConsoleMode(stdio->hStdIn, dwMode);\n\n\n\n chr->chr_set_echo = qemu_chr_set_echo_win_stdio;\n\n qemu_chr_fe_set_echo(chr, false);\n\n\n\n *_chr = chr;\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 9428 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,\n\n int64_t size)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n int chk = s->overlap_check & ~ign;\n\n int i, j;\n\n\n\n if (!size) {\n\n return 0;\n\n }\n\n\n\n if (chk & QCOW2_OL_MAIN_HEADER) {\n\n if (offset < s->cluster_size) {\n\n return QCOW2_OL_MAIN_HEADER;\n\n }\n\n }\n\n\n\n /* align range to test to cluster boundaries */\n\n size = align_offset(offset_into_cluster(s, offset) + size, s->cluster_size);\n\n offset = start_of_cluster(s, offset);\n\n\n\n if ((chk & QCOW2_OL_ACTIVE_L1) && s->l1_size) {\n\n if (overlaps_with(s->l1_table_offset, s->l1_size * sizeof(uint64_t))) {\n\n return QCOW2_OL_ACTIVE_L1;\n\n }\n\n }\n\n\n\n if ((chk & QCOW2_OL_REFCOUNT_TABLE) && s->refcount_table_size) {\n\n if (overlaps_with(s->refcount_table_offset,\n\n s->refcount_table_size * sizeof(uint64_t))) {\n\n return QCOW2_OL_REFCOUNT_TABLE;\n\n }\n\n }\n\n\n\n if ((chk & QCOW2_OL_SNAPSHOT_TABLE) && s->snapshots_size) {\n\n if (overlaps_with(s->snapshots_offset, s->snapshots_size)) {\n\n return QCOW2_OL_SNAPSHOT_TABLE;\n\n }\n\n }\n\n\n\n if ((chk & QCOW2_OL_INACTIVE_L1) && s->snapshots) {\n\n for (i = 0; i < s->nb_snapshots; i++) {\n\n if (s->snapshots[i].l1_size &&\n\n overlaps_with(s->snapshots[i].l1_table_offset,\n\n s->snapshots[i].l1_size * sizeof(uint64_t))) {\n\n return QCOW2_OL_INACTIVE_L1;\n\n }\n\n }\n\n }\n\n\n\n if ((chk & QCOW2_OL_ACTIVE_L2) && s->l1_table) {\n\n for (i = 0; i < s->l1_size; i++) {\n\n if ((s->l1_table[i] & L1E_OFFSET_MASK) &&\n\n overlaps_with(s->l1_table[i] & L1E_OFFSET_MASK,\n\n s->cluster_size)) {\n\n return QCOW2_OL_ACTIVE_L2;\n\n }\n\n }\n\n }\n\n\n\n if ((chk & QCOW2_OL_REFCOUNT_BLOCK) && s->refcount_table) {\n\n for (i = 0; i < s->refcount_table_size; i++) {\n\n if ((s->refcount_table[i] & REFT_OFFSET_MASK) &&\n\n overlaps_with(s->refcount_table[i] & REFT_OFFSET_MASK,\n\n s->cluster_size)) {\n\n return QCOW2_OL_REFCOUNT_BLOCK;\n\n }\n\n }\n\n }\n\n\n\n if ((chk & QCOW2_OL_INACTIVE_L2) && s->snapshots) {\n\n for (i = 0; i < s->nb_snapshots; i++) {\n\n uint64_t l1_ofs = s->snapshots[i].l1_table_offset;\n\n uint32_t l1_sz = s->snapshots[i].l1_size;\n\n uint64_t l1_sz2 = l1_sz * sizeof(uint64_t);\n\n uint64_t *l1 = g_malloc(l1_sz2);\n\n int ret;\n\n\n\n ret = bdrv_pread(bs->file, l1_ofs, l1, l1_sz2);\n\n if (ret < 0) {\n\n g_free(l1);\n\n return ret;\n\n }\n\n\n\n for (j = 0; j < l1_sz; j++) {\n\n uint64_t l2_ofs = be64_to_cpu(l1[j]) & L1E_OFFSET_MASK;\n\n if (l2_ofs && overlaps_with(l2_ofs, s->cluster_size)) {\n\n g_free(l1);\n\n return QCOW2_OL_INACTIVE_L2;\n\n }\n\n }\n\n\n\n g_free(l1);\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 1339 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int rv20_decode_picture_header(MpegEncContext *s)\n\n{\n\n int seq, mb_pos, i;\n\n\n\n i= get_bits(&s->gb, 2);\n\n switch(i){\n\n case 0: s->pict_type= I_TYPE; break;\n\n case 1: s->pict_type= I_TYPE; break; //hmm ...\n\n case 2: s->pict_type= P_TYPE; break;\n\n case 3: s->pict_type= B_TYPE; break;\n\n default: \n\n av_log(s->avctx, AV_LOG_ERROR, \"unknown frame type\\n\");\n\n return -1;\n\n }\n\n \n\n if (get_bits(&s->gb, 1)){\n\n av_log(s->avctx, AV_LOG_ERROR, \"unknown bit set\\n\");\n\n return -1;\n\n }\n\n\n\n s->qscale = get_bits(&s->gb, 5);\n\n if(s->qscale==0){\n\n av_log(s->avctx, AV_LOG_ERROR, \"error, qscale:0\\n\");\n\n return -1;\n\n }\n\n\n\n if(s->avctx->sub_id == 0x20200002)\n\n seq= get_bits(&s->gb, 16);\n\n else\n\n seq= get_bits(&s->gb, 8);\n\n\n\n for(i=0; i<6; i++){\n\n if(s->mb_width*s->mb_height < ff_mba_max[i]) break;\n\n }\n\n mb_pos= get_bits(&s->gb, ff_mba_length[i]);\n\n s->mb_x= mb_pos % s->mb_width;\n\n s->mb_y= mb_pos / s->mb_width;\n\n s->no_rounding= get_bits1(&s->gb);\n\n \n\n s->f_code = 1;\n\n s->unrestricted_mv = 1;\n\n s->h263_aic= s->pict_type == I_TYPE;\n\n// s->alt_inter_vlc=1;\n\n// s->obmc=1;\n\n// s->umvplus=1;\n\n// s->modified_quant=1;\n\n \n\n if(s->avctx->debug & FF_DEBUG_PICT_INFO){\n\n av_log(s->avctx, AV_LOG_INFO, \"num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\\n\", \n\n seq, s->mb_x, s->mb_y, s->pict_type, s->qscale, s->no_rounding);\n\n }\n\n\n\n if (s->pict_type == B_TYPE){\n\n av_log(s->avctx, AV_LOG_ERROR, \"b frame not supported\\n\");\n\n return -1;\n\n }\n\n\n\n return s->mb_width*s->mb_height - mb_pos;\n\n}\n", + "output": "0", + "index": 20443 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_jni_init_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx)\n{\n int i, ret = 0;\n jclass last_clazz = NULL;\n for (i = 0; jfields_mapping[i].name; i++) {\n int mandatory = jfields_mapping[i].mandatory;\n enum FFJniFieldType type = jfields_mapping[i].type;\n if (type == FF_JNI_CLASS) {\n jclass clazz;\n last_clazz = NULL;\n clazz = (*env)->FindClass(env, jfields_mapping[i].name);\n if ((ret = ff_jni_exception_check(env, mandatory, log_ctx)) < 0 && mandatory) {\n goto done;\n last_clazz = *(jclass*)((uint8_t*)jfields + jfields_mapping[i].offset) =\n global ? (*env)->NewGlobalRef(env, clazz) : clazz;\n } else {\n if (!last_clazz) {\n ret = AVERROR_EXTERNAL;\n break;\n switch(type) {\n case FF_JNI_FIELD: {\n jfieldID field_id = (*env)->GetFieldID(env, last_clazz, jfields_mapping[i].method, jfields_mapping[i].signature);\n if ((ret = ff_jni_exception_check(env, mandatory, log_ctx)) < 0 && mandatory) {\n goto done;\n *(jfieldID*)((uint8_t*)jfields + jfields_mapping[i].offset) = field_id;\n break;\n case FF_JNI_STATIC_FIELD: {\n jfieldID field_id = (*env)->GetStaticFieldID(env, last_clazz, jfields_mapping[i].method, jfields_mapping[i].signature);\n if ((ret = ff_jni_exception_check(env, mandatory, log_ctx)) < 0 && mandatory) {\n goto done;\n *(jfieldID*)((uint8_t*)jfields + jfields_mapping[i].offset) = field_id;\n break;\n case FF_JNI_METHOD: {\n jmethodID method_id = (*env)->GetMethodID(env, last_clazz, jfields_mapping[i].method, jfields_mapping[i].signature);\n if ((ret = ff_jni_exception_check(env, mandatory, log_ctx)) < 0 && mandatory) {\n goto done;\n *(jmethodID*)((uint8_t*)jfields + jfields_mapping[i].offset) = method_id;\n break;\n case FF_JNI_STATIC_METHOD: {\n jmethodID method_id = (*env)->GetStaticMethodID(env, last_clazz, jfields_mapping[i].method, jfields_mapping[i].signature);\n if ((ret = ff_jni_exception_check(env, mandatory, log_ctx)) < 0 && mandatory) {\n goto done;\n *(jmethodID*)((uint8_t*)jfields + jfields_mapping[i].offset) = method_id;\n break;\n default:\n av_log(log_ctx, AV_LOG_ERROR, \"Unknown JNI field type\\n\");\n ret = AVERROR(EINVAL);\n goto done;\n ret = 0;\ndone:\n if (ret < 0) {\n /* reset jfields in case of failure so it does not leak references */\n ff_jni_reset_jfields(env, jfields, jfields_mapping, global, log_ctx);\n return ret;", + "output": "1", + "index": 11358 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int get_sot(Jpeg2000DecoderContext *s, int n)\n\n{\n\n Jpeg2000TilePart *tp;\n\n uint16_t Isot;\n\n uint32_t Psot;\n\n uint8_t TPsot;\n\n\n\n if (bytestream2_get_bytes_left(&s->g) < 8)\n\n return AVERROR_INVALIDDATA;\n\n\n\n s->curtileno = 0;\n\n Isot = bytestream2_get_be16u(&s->g); // Isot\n\n if (Isot >= s->numXtiles * s->numYtiles)\n\n return AVERROR_INVALIDDATA;\n\n\n\n s->curtileno = Isot;\n\n Psot = bytestream2_get_be32u(&s->g); // Psot\n\n TPsot = bytestream2_get_byteu(&s->g); // TPsot\n\n\n\n /* Read TNSot but not used */\n\n bytestream2_get_byteu(&s->g); // TNsot\n\n\n\n if (!Psot)\n\n Psot = bytestream2_get_bytes_left(&s->g) + n + 2;\n\n\n\n if (Psot > bytestream2_get_bytes_left(&s->g) + n + 2) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"Psot %\"PRIu32\" too big\\n\", Psot);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n if (TPsot >= FF_ARRAY_ELEMS(s->tile[Isot].tile_part)) {\n\n avpriv_request_sample(s->avctx, \"Support for %\"PRIu8\" components\", TPsot);\n\n return AVERROR_PATCHWELCOME;\n\n }\n\n\n\n s->tile[Isot].tp_idx = TPsot;\n\n tp = s->tile[Isot].tile_part + TPsot;\n\n tp->tile_index = Isot;\n\n tp->tp_end = s->g.buffer + Psot - n - 2;\n\n\n\n if (!TPsot) {\n\n Jpeg2000Tile *tile = s->tile + s->curtileno;\n\n\n\n /* copy defaults */\n\n memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(Jpeg2000CodingStyle));\n\n memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(Jpeg2000QuantStyle));\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 8975 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n QCowSnapshot *new_snapshot_list = NULL;\n\n QCowSnapshot *old_snapshot_list = NULL;\n\n QCowSnapshot sn1, *sn = &sn1;\n\n int i, ret;\n\n uint64_t *l1_table = NULL;\n\n int64_t l1_table_offset;\n\n\n\n memset(sn, 0, sizeof(*sn));\n\n\n\n /* Generate an ID if it wasn't passed */\n\n if (sn_info->id_str[0] == '\\0') {\n\n find_new_snapshot_id(bs, sn_info->id_str, sizeof(sn_info->id_str));\n\n }\n\n\n\n /* Check that the ID is unique */\n\n if (find_snapshot_by_id_and_name(bs, sn_info->id_str, NULL) >= 0) {\n\n return -EEXIST;\n\n }\n\n\n\n /* Populate sn with passed data */\n\n sn->id_str = g_strdup(sn_info->id_str);\n\n sn->name = g_strdup(sn_info->name);\n\n\n\n sn->disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;\n\n sn->vm_state_size = sn_info->vm_state_size;\n\n sn->date_sec = sn_info->date_sec;\n\n sn->date_nsec = sn_info->date_nsec;\n\n sn->vm_clock_nsec = sn_info->vm_clock_nsec;\n\n\n\n /* Allocate the L1 table of the snapshot and copy the current one there. */\n\n l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t));\n\n if (l1_table_offset < 0) {\n\n ret = l1_table_offset;\n\n goto fail;\n\n }\n\n\n\n sn->l1_table_offset = l1_table_offset;\n\n sn->l1_size = s->l1_size;\n\n\n\n l1_table = g_malloc(s->l1_size * sizeof(uint64_t));\n\n for(i = 0; i < s->l1_size; i++) {\n\n l1_table[i] = cpu_to_be64(s->l1_table[i]);\n\n }\n\n\n\n ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,\n\n sn->l1_table_offset, s->l1_size * sizeof(uint64_t));\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table,\n\n s->l1_size * sizeof(uint64_t));\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n g_free(l1_table);\n\n l1_table = NULL;\n\n\n\n /*\n\n * Increase the refcounts of all clusters and make sure everything is\n\n * stable on disk before updating the snapshot table to contain a pointer\n\n * to the new L1 table.\n\n */\n\n ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n /* Append the new snapshot to the snapshot list */\n\n new_snapshot_list = g_malloc((s->nb_snapshots + 1) * sizeof(QCowSnapshot));\n\n if (s->snapshots) {\n\n memcpy(new_snapshot_list, s->snapshots,\n\n s->nb_snapshots * sizeof(QCowSnapshot));\n\n old_snapshot_list = s->snapshots;\n\n }\n\n s->snapshots = new_snapshot_list;\n\n s->snapshots[s->nb_snapshots++] = *sn;\n\n\n\n ret = qcow2_write_snapshots(bs);\n\n if (ret < 0) {\n\n g_free(s->snapshots);\n\n s->snapshots = old_snapshot_list;\n\n s->nb_snapshots--;\n\n goto fail;\n\n }\n\n\n\n g_free(old_snapshot_list);\n\n\n\n /* The VM state isn't needed any more in the active L1 table; in fact, it\n\n * hurts by causing expensive COW for the next snapshot. */\n\n qcow2_discard_clusters(bs, qcow2_vm_state_offset(s),\n\n align_offset(sn->vm_state_size, s->cluster_size)\n\n >> BDRV_SECTOR_BITS,\n\n QCOW2_DISCARD_NEVER);\n\n\n\n#ifdef DEBUG_ALLOC\n\n {\n\n BdrvCheckResult result = {0};\n\n qcow2_check_refcounts(bs, &result, 0);\n\n }\n\n#endif\n\n return 0;\n\n\n\nfail:\n\n g_free(sn->id_str);\n\n g_free(sn->name);\n\n g_free(l1_table);\n\n\n\n return ret;\n\n}\n", + "output": "1", + "index": 12091 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int hls_decode_entry(AVCodecContext *avctxt, void *isFilterThread)\n\n{\n\n HEVCContext *s = avctxt->priv_data;\n\n int ctb_size = 1 << s->ps.sps->log2_ctb_size;\n\n int more_data = 1;\n\n int x_ctb = 0;\n\n int y_ctb = 0;\n\n int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];\n\n\n\n if (!ctb_addr_ts && s->sh.dependent_slice_segment_flag) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"Impossible initial tile.\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n if (s->sh.dependent_slice_segment_flag) {\n\n int prev_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];\n\n if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"Previous slice segment missing\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n\n\n while (more_data && ctb_addr_ts < s->ps.sps->ctb_size) {\n\n int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];\n\n\n\n x_ctb = (ctb_addr_rs % ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;\n\n y_ctb = (ctb_addr_rs / ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;\n\n hls_decode_neighbour(s, x_ctb, y_ctb, ctb_addr_ts);\n\n\n\n ff_hevc_cabac_init(s, ctb_addr_ts);\n\n\n\n hls_sao_param(s, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size);\n\n\n\n s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;\n\n s->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;\n\n s->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;\n\n\n\n more_data = hls_coding_quadtree(s, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0);\n\n if (more_data < 0) {\n\n s->tab_slice_address[ctb_addr_rs] = -1;\n\n return more_data;\n\n }\n\n\n\n\n\n ctb_addr_ts++;\n\n ff_hevc_save_states(s, ctb_addr_ts);\n\n ff_hevc_hls_filters(s, x_ctb, y_ctb, ctb_size);\n\n }\n\n\n\n if (x_ctb + ctb_size >= s->ps.sps->width &&\n\n y_ctb + ctb_size >= s->ps.sps->height)\n\n ff_hevc_hls_filter(s, x_ctb, y_ctb, ctb_size);\n\n\n\n return ctb_addr_ts;\n\n}\n", + "output": "1", + "index": 11450 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int poll_filters(void)\n\n{\n\n AVFilterBufferRef *picref;\n\n AVFrame *filtered_frame = NULL;\n\n int i, frame_size;\n\n\n\n for (i = 0; i < nb_output_streams; i++) {\n\n OutputStream *ost = output_streams[i];\n\n OutputFile *of = output_files[ost->file_index];\n\n int ret = 0;\n\n\n\n if (!ost->filter)\n\n continue;\n\n\n\n if (!ost->filtered_frame && !(ost->filtered_frame = avcodec_alloc_frame())) {\n\n return AVERROR(ENOMEM);\n\n } else\n\n avcodec_get_frame_defaults(ost->filtered_frame);\n\n filtered_frame = ost->filtered_frame;\n\n\n\n while (ret >= 0 && !ost->is_past_recording_time) {\n\n if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&\n\n !(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))\n\n ret = av_buffersink_read_samples(ost->filter->filter, &picref,\n\n ost->st->codec->frame_size);\n\n else\n\n ret = av_buffersink_read(ost->filter->filter, &picref);\n\n\n\n if (ret < 0)\n\n break;\n\n\n\n avfilter_copy_buf_props(filtered_frame, picref);\n\n if (picref->pts != AV_NOPTS_VALUE)\n\n filtered_frame->pts = av_rescale_q(picref->pts,\n\n ost->filter->filter->inputs[0]->time_base,\n\n ost->st->codec->time_base) -\n\n av_rescale_q(of->start_time,\n\n AV_TIME_BASE_Q,\n\n ost->st->codec->time_base);\n\n\n\n if (of->start_time && filtered_frame->pts < of->start_time) {\n\n avfilter_unref_buffer(picref);\n\n continue;\n\n }\n\n\n\n switch (ost->filter->filter->inputs[0]->type) {\n\n case AVMEDIA_TYPE_VIDEO:\n\n if (!ost->frame_aspect_ratio)\n\n ost->st->codec->sample_aspect_ratio = picref->video->pixel_aspect;\n\n\n\n do_video_out(of->ctx, ost, filtered_frame, &frame_size,\n\n same_quant ? ost->last_quality :\n\n ost->st->codec->global_quality);\n\n if (vstats_filename && frame_size)\n\n do_video_stats(of->ctx, ost, frame_size);\n\n break;\n\n case AVMEDIA_TYPE_AUDIO:\n\n do_audio_out(of->ctx, ost, filtered_frame);\n\n break;\n\n default:\n\n // TODO support subtitle filters\n\n av_assert0(0);\n\n }\n\n\n\n avfilter_unref_buffer(picref);\n\n }\n\n }\n\n return 0;\n\n}\n", + "output": "0", + "index": 1969 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)\n{\n int i, csize = 1;\n int32_t *src[3], i0, i1, i2;\n float *srcf[3], i0f, i1f, i2f;\n for (i = 0; i < 3; i++)\n if (tile->codsty[0].transform == FF_DWT97)\n srcf[i] = tile->comp[i].f_data;\n else\n src [i] = tile->comp[i].i_data;\n for (i = 0; i < 2; i++)\n csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];\n switch (tile->codsty[0].transform) {\n case FF_DWT97:\n for (i = 0; i < csize; i++) {\n i0f = *srcf[0] + (f_ict_params[0] * *srcf[2]);\n i1f = *srcf[0] - (f_ict_params[1] * *srcf[1])\n - (f_ict_params[2] * *srcf[2]);\n i2f = *srcf[0] + (f_ict_params[3] * *srcf[1]);\n *srcf[0]++ = i0f;\n *srcf[1]++ = i1f;\n *srcf[2]++ = i2f;\n break;\n case FF_DWT97_INT:\n for (i = 0; i < csize; i++) {\n i0 = *src[0] + (((i_ict_params[0] * *src[2]) + (1 << 15)) >> 16);\n i1 = *src[0] - (((i_ict_params[1] * *src[1]) + (1 << 15)) >> 16)\n - (((i_ict_params[2] * *src[2]) + (1 << 15)) >> 16);\n i2 = *src[0] + (((i_ict_params[3] * *src[1]) + (1 << 15)) >> 16);\n *src[0]++ = i0;\n *src[1]++ = i1;\n *src[2]++ = i2;\n break;\n case FF_DWT53:\n for (i = 0; i < csize; i++) {\n i1 = *src[0] - (*src[2] + *src[1] >> 2);\n i0 = i1 + *src[2];\n i2 = i1 + *src[1];\n *src[0]++ = i0;\n *src[1]++ = i1;\n *src[2]++ = i2;\n break;", + "output": "1", + "index": 5909 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void decode_opc_special3(CPUMIPSState *env, DisasContext *ctx)\n{\n int rs, rt, rd, sa;\n uint32_t op1, op2;\n rs = (ctx->opcode >> 21) & 0x1f;\n rt = (ctx->opcode >> 16) & 0x1f;\n rd = (ctx->opcode >> 11) & 0x1f;\n sa = (ctx->opcode >> 6) & 0x1f;\n op1 = MASK_SPECIAL3(ctx->opcode);\n case OPC_EXT:\n case OPC_INS:\n check_insn(ctx, ISA_MIPS32R2);\n gen_bitops(ctx, op1, rt, rs, sa, rd);\n break;\n case OPC_BSHFL:\n op2 = MASK_BSHFL(ctx->opcode);\n switch (op2) {\n case OPC_ALIGN ... OPC_ALIGN_END:\n case OPC_BITSWAP:\n check_insn(ctx, ISA_MIPS32R6);\n decode_opc_special3_r6(env, ctx);\n break;\n default:\n check_insn(ctx, ISA_MIPS32R2);\n gen_bshfl(ctx, op2, rt, rd);\n break;\n break;\n#if defined(TARGET_MIPS64)\n case OPC_DEXTM ... OPC_DEXT:\n case OPC_DINSM ... OPC_DINS:\n check_insn(ctx, ISA_MIPS64R2);\n check_mips_64(ctx);\n gen_bitops(ctx, op1, rt, rs, sa, rd);\n break;\n case OPC_DBSHFL:\n op2 = MASK_DBSHFL(ctx->opcode);\n switch (op2) {\n case OPC_DALIGN ... OPC_DALIGN_END:\n case OPC_DBITSWAP:\n check_insn(ctx, ISA_MIPS32R6);\n decode_opc_special3_r6(env, ctx);\n break;\n default:\n check_insn(ctx, ISA_MIPS64R2);\n check_mips_64(ctx);\n op2 = MASK_DBSHFL(ctx->opcode);\n gen_bshfl(ctx, op2, rt, rd);\n break;\n break;\n#endif\n case OPC_RDHWR:\n gen_rdhwr(ctx, rt, rd, extract32(ctx->opcode, 6, 3));\n break;\n case OPC_FORK:\n check_insn(ctx, ASE_MT);\n {\n TCGv t0 = tcg_temp_new();\n TCGv t1 = tcg_temp_new();\n gen_load_gpr(t0, rt);\n gen_load_gpr(t1, rs);\n gen_helper_fork(t0, t1);\n tcg_temp_free(t0);\n tcg_temp_free(t1);\n break;\n case OPC_YIELD:\n check_insn(ctx, ASE_MT);\n {\n TCGv t0 = tcg_temp_new();\n gen_load_gpr(t0, rs);\n gen_helper_yield(t0, cpu_env, t0);\n gen_store_gpr(t0, rd);\n tcg_temp_free(t0);\n break;\n default:\n if (ctx->insn_flags & ISA_MIPS32R6) {\n decode_opc_special3_r6(env, ctx);\n } else {\n decode_opc_special3_legacy(env, ctx);", + "output": "1", + "index": 14995 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) {\n\n GetBitContext *gb=&vc->gb;\n\n uint_fast8_t i, j;\n\n\n\n vc->mapping_count=get_bits(gb, 6)+1;\n\n vc->mappings=av_mallocz(vc->mapping_count * sizeof(vorbis_mapping));\n\n\n\n AV_DEBUG(\" There are %d mappings. \\n\", vc->mapping_count);\n\n\n\n for(i=0;imapping_count;++i) {\n\n vorbis_mapping *mapping_setup=&vc->mappings[i];\n\n\n\n if (get_bits(gb, 16)) {\n\n av_log(vc->avccontext, AV_LOG_ERROR, \"Other mappings than type 0 are not compliant with the Vorbis I specification. \\n\");\n\n return 1;\n\n }\n\n if (get_bits1(gb)) {\n\n mapping_setup->submaps=get_bits(gb, 4)+1;\n\n } else {\n\n mapping_setup->submaps=1;\n\n }\n\n\n\n if (get_bits1(gb)) {\n\n mapping_setup->coupling_steps=get_bits(gb, 8)+1;\n\n mapping_setup->magnitude=av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));\n\n mapping_setup->angle =av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));\n\n for(j=0;jcoupling_steps;++j) {\n\n mapping_setup->magnitude[j]=get_bits(gb, ilog(vc->audio_channels-1));\n\n mapping_setup->angle[j]=get_bits(gb, ilog(vc->audio_channels-1));\n\n // FIXME: sanity checks\n\n }\n\n } else {\n\n mapping_setup->coupling_steps=0;\n\n }\n\n\n\n AV_DEBUG(\" %d mapping coupling steps: %d \\n\", i, mapping_setup->coupling_steps);\n\n\n\n if(get_bits(gb, 2)) {\n\n av_log(vc->avccontext, AV_LOG_ERROR, \"%d. mapping setup data invalid. \\n\", i);\n\n return 1; // following spec.\n\n }\n\n\n\n if (mapping_setup->submaps>1) {\n\n mapping_setup->mux=av_mallocz(vc->audio_channels * sizeof(uint_fast8_t));\n\n for(j=0;jaudio_channels;++j) {\n\n mapping_setup->mux[j]=get_bits(gb, 4);\n\n }\n\n }\n\n\n\n for(j=0;jsubmaps;++j) {\n\n skip_bits(gb, 8); // FIXME check?\n\n mapping_setup->submap_floor[j]=get_bits(gb, 8);\n\n mapping_setup->submap_residue[j]=get_bits(gb, 8);\n\n\n\n AV_DEBUG(\" %d mapping %d submap : floor %d, residue %d \\n\", i, j, mapping_setup->submap_floor[j], mapping_setup->submap_residue[j]);\n\n }\n\n }\n\n return 0;\n\n}\n", + "output": "1", + "index": 18074 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v)\n\n{\n\n XHCIInterrupter *intr;\n\n dma_addr_t erdp;\n\n unsigned int dp_idx;\n\n\n\n if (v >= xhci->numintrs) {\n\n DPRINTF(\"intr nr out of range (%d >= %d)\\n\", v, xhci->numintrs);\n\n return;\n\n }\n\n intr = &xhci->intr[v];\n\n\n\n if (intr->er_full) {\n\n DPRINTF(\"xhci_event(): ER full, queueing\\n\");\n\n if (((intr->ev_buffer_put+1) % EV_QUEUE) == intr->ev_buffer_get) {\n\n DPRINTF(\"xhci: event queue full, dropping event!\\n\");\n\n return;\n\n }\n\n intr->ev_buffer[intr->ev_buffer_put++] = *event;\n\n if (intr->ev_buffer_put == EV_QUEUE) {\n\n intr->ev_buffer_put = 0;\n\n }\n\n return;\n\n }\n\n\n\n erdp = xhci_addr64(intr->erdp_low, intr->erdp_high);\n\n if (erdp < intr->er_start ||\n\n erdp >= (intr->er_start + TRB_SIZE*intr->er_size)) {\n\n DPRINTF(\"xhci: ERDP out of bounds: \"DMA_ADDR_FMT\"\\n\", erdp);\n\n DPRINTF(\"xhci: ER[%d] at \"DMA_ADDR_FMT\" len %d\\n\",\n\n v, intr->er_start, intr->er_size);\n\n xhci_die(xhci);\n\n return;\n\n }\n\n\n\n dp_idx = (erdp - intr->er_start) / TRB_SIZE;\n\n assert(dp_idx < intr->er_size);\n\n\n\n if ((intr->er_ep_idx+1) % intr->er_size == dp_idx) {\n\n DPRINTF(\"xhci_event(): ER full, queueing\\n\");\n\n#ifndef ER_FULL_HACK\n\n XHCIEvent full = {ER_HOST_CONTROLLER, CC_EVENT_RING_FULL_ERROR};\n\n xhci_write_event(xhci, &full);\n\n#endif\n\n intr->er_full = 1;\n\n if (((intr->ev_buffer_put+1) % EV_QUEUE) == intr->ev_buffer_get) {\n\n DPRINTF(\"xhci: event queue full, dropping event!\\n\");\n\n return;\n\n }\n\n intr->ev_buffer[intr->ev_buffer_put++] = *event;\n\n if (intr->ev_buffer_put == EV_QUEUE) {\n\n intr->ev_buffer_put = 0;\n\n }\n\n } else {\n\n xhci_write_event(xhci, event, v);\n\n }\n\n\n\n xhci_intr_raise(xhci, v);\n\n}\n", + "output": "1", + "index": 18551 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_stream_header(NUTContext *nut){\n\n AVFormatContext *s= nut->avf;\n\n ByteIOContext *bc = &s->pb;\n\n StreamContext *stc;\n\n int class, nom, denom, stream_id;\n\n uint64_t tmp, end;\n\n AVStream *st;\n\n\n\n end= get_packetheader(nut, bc, 1);\n\n end += url_ftell(bc) - 4;\n\n\n\n GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base.num);\n\n stc= &nut->stream[stream_id];\n\n\n\n st = s->streams[stream_id];\n\n if (!st)\n\n return AVERROR_NOMEM;\n\n\n\n class = get_v(bc);\n\n tmp = get_fourcc(bc);\n\n st->codec->codec_tag= tmp;\n\n switch(class)\n\n {\n\n case 0:\n\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n\n st->codec->codec_id = codec_get_bmp_id(tmp);\n\n if (st->codec->codec_id == CODEC_ID_NONE)\n\n av_log(s, AV_LOG_ERROR, \"Unknown codec?!\\n\");\n\n break;\n\n case 1:\n\n st->codec->codec_type = CODEC_TYPE_AUDIO;\n\n st->codec->codec_id = codec_get_wav_id(tmp);\n\n if (st->codec->codec_id == CODEC_ID_NONE)\n\n av_log(s, AV_LOG_ERROR, \"Unknown codec?!\\n\");\n\n break;\n\n case 2:\n\n// st->codec->codec_type = CODEC_TYPE_TEXT;\n\n// break;\n\n case 3:\n\n st->codec->codec_type = CODEC_TYPE_DATA;\n\n break;\n\n default:\n\n av_log(s, AV_LOG_ERROR, \"Unknown stream class (%d)\\n\", class);\n\n return -1;\n\n }\n\n GET_V(stc->time_base_id , tmp < nut->time_base_count);\n\n GET_V(stc->msb_pts_shift , tmp < 16);\n\n stc->max_pts_distance= get_v(bc);\n\n GET_V(stc->decode_delay , tmp < 1000); //sanity limit, raise this if moors law is true\n\n st->codec->has_b_frames= stc->decode_delay;\n\n get_v(bc); //stream flags\n\n\n\n GET_V(st->codec->extradata_size, tmp < (1<<30));\n\n if(st->codec->extradata_size){\n\n st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);\n\n get_buffer(bc, st->codec->extradata, st->codec->extradata_size);\n\n }\n\n\n\n if (st->codec->codec_type == CODEC_TYPE_VIDEO){\n\n GET_V(st->codec->width , tmp > 0)\n\n GET_V(st->codec->height, tmp > 0)\n\n st->codec->sample_aspect_ratio.num= get_v(bc);\n\n st->codec->sample_aspect_ratio.den= get_v(bc);\n\n if((!st->codec->sample_aspect_ratio.num) != (!st->codec->sample_aspect_ratio.den)){\n\n av_log(s, AV_LOG_ERROR, \"invalid aspect ratio\\n\");\n\n return -1;\n\n }\n\n get_v(bc); /* csp type */\n\n }else if (st->codec->codec_type == CODEC_TYPE_AUDIO){\n\n GET_V(st->codec->sample_rate , tmp > 0)\n\n tmp= get_v(bc); // samplerate_den\n\n if(tmp > st->codec->sample_rate){\n\n av_log(s, AV_LOG_ERROR, \"bleh, libnut muxed this ;)\\n\");\n\n st->codec->sample_rate= tmp;\n\n }\n\n GET_V(st->codec->channels, tmp > 0)\n\n }\n\n if(skip_reserved(bc, end) || check_checksum(bc)){\n\n av_log(s, AV_LOG_ERROR, \"Stream header %d checksum mismatch\\n\", stream_id);\n\n return -1;\n\n }\n\n stc->time_base= nut->time_base[stc->time_base_id];\n\n av_set_pts_info(s->streams[stream_id], 63, stc->time_base.num, stc->time_base.den);\n\n return 0;\n\n}\n", + "output": "1", + "index": 19657 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,\n\n AVPacket *pkt, int flush)\n\n{\n\n AVPacketList *pktl;\n\n int stream_count = 0;\n\n int i;\n\n\n\n if (pkt) {\n\n ff_interleave_add_packet(s, pkt, interleave_compare_dts);\n\n }\n\n\n\n if (s->max_interleave_delta > 0 && s->packet_buffer && !flush) {\n\n AVPacket *top_pkt = &s->packet_buffer->pkt;\n\n int64_t delta_dts = INT64_MIN;\n\n int64_t top_dts = av_rescale_q(top_pkt->dts,\n\n s->streams[top_pkt->stream_index]->time_base,\n\n AV_TIME_BASE_Q);\n\n\n\n for (i = 0; i < s->nb_streams; i++) {\n\n int64_t last_dts;\n\n const AVPacketList *last = s->streams[i]->last_in_packet_buffer;\n\n\n\n if (!last)\n\n continue;\n\n\n\n last_dts = av_rescale_q(last->pkt.dts,\n\n s->streams[i]->time_base,\n\n AV_TIME_BASE_Q);\n\n delta_dts = FFMAX(delta_dts, last_dts - top_dts);\n\n stream_count++;\n\n }\n\n\n\n if (delta_dts > s->max_interleave_delta) {\n\n av_log(s, AV_LOG_DEBUG,\n\n \"Delay between the first packet and last packet in the \"\n\n \"muxing queue is %\"PRId64\" > %\"PRId64\": forcing output\\n\",\n\n delta_dts, s->max_interleave_delta);\n\n flush = 1;\n\n }\n\n } else {\n\n for (i = 0; i < s->nb_streams; i++)\n\n stream_count += !!s->streams[i]->last_in_packet_buffer;\n\n }\n\n\n\n\n\n if (stream_count && (s->internal->nb_interleaved_streams == stream_count || flush)) {\n\n pktl = s->packet_buffer;\n\n *out = pktl->pkt;\n\n\n\n s->packet_buffer = pktl->next;\n\n if (!s->packet_buffer)\n\n s->packet_buffer_end = NULL;\n\n\n\n if (s->streams[out->stream_index]->last_in_packet_buffer == pktl)\n\n s->streams[out->stream_index]->last_in_packet_buffer = NULL;\n\n av_freep(&pktl);\n\n return 1;\n\n } else {\n\n av_init_packet(out);\n\n return 0;\n\n }\n\n}\n", + "output": "0", + "index": 15694 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int __qemu_rdma_add_block(RDMAContext *rdma, void *host_addr,\n\n ram_addr_t block_offset, uint64_t length)\n\n{\n\n RDMALocalBlocks *local = &rdma->local_ram_blocks;\n\n RDMALocalBlock *block = g_hash_table_lookup(rdma->blockmap,\n\n (void *) block_offset);\n\n RDMALocalBlock *old = local->block;\n\n\n\n assert(block == NULL);\n\n\n\n local->block = g_malloc0(sizeof(RDMALocalBlock) * (local->nb_blocks + 1));\n\n\n\n if (local->nb_blocks) {\n\n int x;\n\n\n\n for (x = 0; x < local->nb_blocks; x++) {\n\n g_hash_table_remove(rdma->blockmap, (void *)old[x].offset);\n\n g_hash_table_insert(rdma->blockmap, (void *)old[x].offset,\n\n &local->block[x]);\n\n }\n\n memcpy(local->block, old, sizeof(RDMALocalBlock) * local->nb_blocks);\n\n g_free(old);\n\n }\n\n\n\n block = &local->block[local->nb_blocks];\n\n\n\n block->local_host_addr = host_addr;\n\n block->offset = block_offset;\n\n block->length = length;\n\n block->index = local->nb_blocks;\n\n block->nb_chunks = ram_chunk_index(host_addr, host_addr + length) + 1UL;\n\n block->transit_bitmap = bitmap_new(block->nb_chunks);\n\n bitmap_clear(block->transit_bitmap, 0, block->nb_chunks);\n\n block->unregister_bitmap = bitmap_new(block->nb_chunks);\n\n bitmap_clear(block->unregister_bitmap, 0, block->nb_chunks);\n\n block->remote_keys = g_malloc0(block->nb_chunks * sizeof(uint32_t));\n\n\n\n block->is_ram_block = local->init ? false : true;\n\n\n\n g_hash_table_insert(rdma->blockmap, (void *) block_offset, block);\n\n\n\n DDPRINTF(\"Added Block: %d, addr: %\" PRIu64 \", offset: %\" PRIu64\n\n \" length: %\" PRIu64 \" end: %\" PRIu64 \" bits %\" PRIu64 \" chunks %d\\n\",\n\n local->nb_blocks, (uint64_t) block->local_host_addr, block->offset,\n\n block->length, (uint64_t) (block->local_host_addr + block->length),\n\n BITS_TO_LONGS(block->nb_chunks) *\n\n sizeof(unsigned long) * 8, block->nb_chunks);\n\n\n\n local->nb_blocks++;\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 20579 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int hls_slice_data_wpp(HEVCContext *s, const HEVCNAL *nal)\n\n{\n\n const uint8_t *data = nal->data;\n\n int length = nal->size;\n\n HEVCLocalContext *lc = s->HEVClc;\n\n int *ret = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int));\n\n int *arg = av_malloc_array(s->sh.num_entry_point_offsets + 1, sizeof(int));\n\n int64_t offset;\n\n int startheader, cmpt = 0;\n\n int i, j, res = 0;\n\n\n\n if (!ret || !arg) {\n\n av_free(ret);\n\n av_free(arg);\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n\n\n if (!s->sList[1]) {\n\n ff_alloc_entries(s->avctx, s->sh.num_entry_point_offsets + 1);\n\n\n\n\n\n for (i = 1; i < s->threads_number; i++) {\n\n s->sList[i] = av_malloc(sizeof(HEVCContext));\n\n memcpy(s->sList[i], s, sizeof(HEVCContext));\n\n s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext));\n\n s->sList[i]->HEVClc = s->HEVClcList[i];\n\n }\n\n }\n\n\n\n offset = (lc->gb.index >> 3);\n\n\n\n for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {\n\n if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {\n\n startheader--;\n\n cmpt++;\n\n }\n\n }\n\n\n\n for (i = 1; i < s->sh.num_entry_point_offsets; i++) {\n\n offset += (s->sh.entry_point_offset[i - 1] - cmpt);\n\n for (j = 0, cmpt = 0, startheader = offset\n\n + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) {\n\n if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {\n\n startheader--;\n\n cmpt++;\n\n }\n\n }\n\n s->sh.size[i - 1] = s->sh.entry_point_offset[i] - cmpt;\n\n s->sh.offset[i - 1] = offset;\n\n\n\n }\n\n if (s->sh.num_entry_point_offsets != 0) {\n\n offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt;\n\n if (length < offset) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"entry_point_offset table is corrupted\\n\");\n\n res = AVERROR_INVALIDDATA;\n\n goto error;\n\n }\n\n s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset;\n\n s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset;\n\n\n\n }\n\n s->data = data;\n\n\n\n for (i = 1; i < s->threads_number; i++) {\n\n s->sList[i]->HEVClc->first_qp_group = 1;\n\n s->sList[i]->HEVClc->qp_y = s->sList[0]->HEVClc->qp_y;\n\n memcpy(s->sList[i], s, sizeof(HEVCContext));\n\n s->sList[i]->HEVClc = s->HEVClcList[i];\n\n }\n\n\n\n avpriv_atomic_int_set(&s->wpp_err, 0);\n\n ff_reset_entries(s->avctx);\n\n\n\n for (i = 0; i <= s->sh.num_entry_point_offsets; i++) {\n\n arg[i] = i;\n\n ret[i] = 0;\n\n }\n\n\n\n if (s->ps.pps->entropy_coding_sync_enabled_flag)\n\n s->avctx->execute2(s->avctx, hls_decode_entry_wpp, arg, ret, s->sh.num_entry_point_offsets + 1);\n\n\n\n for (i = 0; i <= s->sh.num_entry_point_offsets; i++)\n\n res += ret[i];\n\nerror:\n\n av_free(ret);\n\n av_free(arg);\n\n return res;\n\n}\n", + "output": "0", + "index": 7854 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void cpu_dump_state(CPUState *env, FILE *f, \n\n int (*cpu_fprintf)(FILE *f, const char *fmt, ...),\n\n int flags)\n\n{\n\n#if defined(TARGET_PPC64) || 1\n\n#define FILL \"\"\n\n#define RGPL 4\n\n#define RFPL 4\n\n#else\n\n#define FILL \" \"\n\n#define RGPL 8\n\n#define RFPL 4\n\n#endif\n\n\n\n int i;\n\n\n\n cpu_fprintf(f, \"NIP \" REGX \" LR \" REGX \" CTR \" REGX \"\\n\",\n\n env->nip, env->lr, env->ctr);\n\n cpu_fprintf(f, \"MSR \" REGX FILL \" XER %08x TB %08x %08x \"\n\n#if !defined(CONFIG_USER_ONLY)\n\n \"DECR %08x\"\n\n#endif\n\n \"\\n\",\n\n do_load_msr(env), load_xer(env), cpu_ppc_load_tbu(env),\n\n cpu_ppc_load_tbl(env)\n\n#if !defined(CONFIG_USER_ONLY)\n\n , cpu_ppc_load_decr(env)\n\n#endif\n\n );\n\n for (i = 0; i < 32; i++) {\n\n if ((i & (RGPL - 1)) == 0)\n\n cpu_fprintf(f, \"GPR%02d\", i);\n\n cpu_fprintf(f, \" \" REGX, env->gpr[i]);\n\n if ((i & (RGPL - 1)) == (RGPL - 1))\n\n cpu_fprintf(f, \"\\n\");\n\n }\n\n cpu_fprintf(f, \"CR \");\n\n for (i = 0; i < 8; i++)\n\n cpu_fprintf(f, \"%01x\", env->crf[i]);\n\n cpu_fprintf(f, \" [\");\n\n for (i = 0; i < 8; i++) {\n\n char a = '-';\n\n if (env->crf[i] & 0x08)\n\n a = 'L';\n\n else if (env->crf[i] & 0x04)\n\n a = 'G';\n\n else if (env->crf[i] & 0x02)\n\n a = 'E';\n\n cpu_fprintf(f, \" %c%c\", a, env->crf[i] & 0x01 ? 'O' : ' ');\n\n }\n\n cpu_fprintf(f, \" ] \" FILL \"RES \" REGX \"\\n\", env->reserve);\n\n for (i = 0; i < 32; i++) {\n\n if ((i & (RFPL - 1)) == 0)\n\n cpu_fprintf(f, \"FPR%02d\", i);\n\n cpu_fprintf(f, \" %016\" PRIx64, *((uint64_t *)&env->fpr[i]));\n\n if ((i & (RFPL - 1)) == (RFPL - 1))\n\n cpu_fprintf(f, \"\\n\");\n\n }\n\n cpu_fprintf(f, \"SRR0 \" REGX \" SRR1 \" REGX \" \" FILL FILL FILL\n\n \"SDR1 \" REGX \"\\n\",\n\n env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1);\n\n\n\n#undef REGX\n\n#undef RGPL\n\n#undef RFPL\n\n#undef FILL\n\n}\n", + "output": "1", + "index": 21775 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int set_sps(HEVCContext *s, const HEVCSPS *sps)\n\n{\n\n int ret;\n\n int num = 0, den = 0;\n\n\n\n pic_arrays_free(s);\n\n ret = pic_arrays_init(s, sps);\n\n if (ret < 0)\n\n goto fail;\n\n\n\n s->avctx->coded_width = sps->width;\n\n s->avctx->coded_height = sps->height;\n\n s->avctx->width = sps->output_width;\n\n s->avctx->height = sps->output_height;\n\n s->avctx->pix_fmt = sps->pix_fmt;\n\n s->avctx->sample_aspect_ratio = sps->vui.sar;\n\n s->avctx->has_b_frames = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;\n\n\n\n if (sps->vui.video_signal_type_present_flag)\n\n s->avctx->color_range = sps->vui.video_full_range_flag ? AVCOL_RANGE_JPEG\n\n : AVCOL_RANGE_MPEG;\n\n else\n\n s->avctx->color_range = AVCOL_RANGE_MPEG;\n\n\n\n if (sps->vui.colour_description_present_flag) {\n\n s->avctx->color_primaries = sps->vui.colour_primaries;\n\n s->avctx->color_trc = sps->vui.transfer_characteristic;\n\n s->avctx->colorspace = sps->vui.matrix_coeffs;\n\n } else {\n\n s->avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;\n\n s->avctx->color_trc = AVCOL_TRC_UNSPECIFIED;\n\n s->avctx->colorspace = AVCOL_SPC_UNSPECIFIED;\n\n }\n\n\n\n ff_hevc_pred_init(&s->hpc, sps->bit_depth);\n\n ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);\n\n ff_videodsp_init (&s->vdsp, sps->bit_depth);\n\n\n\n if (sps->sao_enabled) {\n\n av_frame_unref(s->tmp_frame);\n\n ret = ff_get_buffer(s->avctx, s->tmp_frame, AV_GET_BUFFER_FLAG_REF);\n\n if (ret < 0)\n\n goto fail;\n\n s->frame = s->tmp_frame;\n\n }\n\n\n\n s->sps = sps;\n\n s->vps = (HEVCVPS*) s->vps_list[s->sps->vps_id]->data;\n\n\n\n if (s->vps->vps_timing_info_present_flag) {\n\n num = s->vps->vps_num_units_in_tick;\n\n den = s->vps->vps_time_scale;\n\n } else if (sps->vui.vui_timing_info_present_flag) {\n\n num = sps->vui.vui_num_units_in_tick;\n\n den = sps->vui.vui_time_scale;\n\n }\n\n\n\n if (num != 0 && den != 0)\n\n av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,\n\n num, den, 1 << 30);\n\n\n\n return 0;\n\n\n\nfail:\n\n pic_arrays_free(s);\n\n s->sps = NULL;\n\n return ret;\n\n}\n", + "output": "0", + "index": 3417 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int dnxhd_find_frame_end(DNXHDParserContext *dctx,\n\n const uint8_t *buf, int buf_size)\n\n{\n\n ParseContext *pc = &dctx->pc;\n\n uint64_t state = pc->state64;\n\n int pic_found = pc->frame_start_found;\n\n int i = 0;\n\n\n\n if (!pic_found) {\n\n for (i = 0; i < buf_size; i++) {\n\n state = (state << 8) | buf[i];\n\n if (ff_dnxhd_check_header_prefix(state & 0xffffffffff00LL) != 0) {\n\n i++;\n\n pic_found = 1;\n\n dctx->cur_byte = 0;\n\n dctx->remaining = 0;\n\n break;\n\n }\n\n }\n\n }\n\n\n\n if (pic_found && !dctx->remaining) {\n\n if (!buf_size) /* EOF considered as end of frame */\n\n return 0;\n\n for (; i < buf_size; i++) {\n\n dctx->cur_byte++;\n\n state = (state << 8) | buf[i];\n\n\n\n if (dctx->cur_byte == 24) {\n\n dctx->h = (state >> 32) & 0xFFFF;\n\n } else if (dctx->cur_byte == 26) {\n\n dctx->w = (state >> 32) & 0xFFFF;\n\n } else if (dctx->cur_byte == 42) {\n\n int cid = (state >> 32) & 0xFFFFFFFF;\n\n\n\n if (cid <= 0)\n\n continue;\n\n\n\n dctx->remaining = avpriv_dnxhd_get_frame_size(cid);\n\n if (dctx->remaining <= 0) {\n\n dctx->remaining = ff_dnxhd_get_hr_frame_size(cid, dctx->w, dctx->h);\n\n if (dctx->remaining <= 0)\n\n return dctx->remaining;\n\n }\n\n if (buf_size - i + 47 >= dctx->remaining) {\n\n int remaining = dctx->remaining;\n\n\n\n pc->frame_start_found = 0;\n\n pc->state64 = -1;\n\n dctx->cur_byte = 0;\n\n dctx->remaining = 0;\n\n return remaining;\n\n } else {\n\n dctx->remaining -= buf_size;\n\n }\n\n }\n\n }\n\n } else if (pic_found) {\n\n if (dctx->remaining > buf_size) {\n\n dctx->remaining -= buf_size;\n\n } else {\n\n int remaining = dctx->remaining;\n\n\n\n pc->frame_start_found = 0;\n\n pc->state64 = -1;\n\n dctx->cur_byte = 0;\n\n dctx->remaining = 0;\n\n return remaining;\n\n }\n\n }\n\n pc->frame_start_found = pic_found;\n\n pc->state64 = state;\n\n return END_NOT_FOUND;\n\n}\n", + "output": "1", + "index": 19728 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void copy_picture_field(TInterlaceContext *tinterlace,\n\n uint8_t *dst[4], int dst_linesize[4],\n\n const uint8_t *src[4], int src_linesize[4],\n\n enum AVPixelFormat format, int w, int src_h,\n\n int src_field, int interleave, int dst_field,\n\n int flags)\n\n{\n\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);\n\n int hsub = desc->log2_chroma_w;\n\n int plane, vsub = desc->log2_chroma_h;\n\n int k = src_field == FIELD_UPPER_AND_LOWER ? 1 : 2;\n\n int h;\n\n\n\n for (plane = 0; plane < desc->nb_components; plane++) {\n\n int lines = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT(src_h, vsub) : src_h;\n\n int cols = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT( w, hsub) : w;\n\n uint8_t *dstp = dst[plane];\n\n const uint8_t *srcp = src[plane];\n\n int srcp_linesize = src_linesize[plane] * k;\n\n int dstp_linesize = dst_linesize[plane] * (interleave ? 2 : 1);\n\n\n\n lines = (lines + (src_field == FIELD_UPPER)) / k;\n\n if (src_field == FIELD_LOWER)\n\n srcp += src_linesize[plane];\n\n if (interleave && dst_field == FIELD_LOWER)\n\n dstp += dst_linesize[plane];\n\n // Low-pass filtering is required when creating an interlaced destination from\n\n // a progressive source which contains high-frequency vertical detail.\n\n // Filtering will reduce interlace 'twitter' and Moire patterning.\n\n if (flags & TINTERLACE_FLAG_VLPF || flags & TINTERLACE_FLAG_CVLPF) {\n\n int x = 0;\n\n if (flags & TINTERLACE_FLAG_CVLPF)\n\n x = 1;\n\n for (h = lines; h > 0; h--) {\n\n ptrdiff_t pref = src_linesize[plane];\n\n ptrdiff_t mref = -pref;\n\n if (h >= (lines - x)) mref = 0; // there is no line above\n\n else if (h <= (1 + x)) pref = 0; // there is no line below\n\n\n\n tinterlace->lowpass_line(dstp, cols, srcp, mref, pref);\n\n dstp += dstp_linesize;\n\n srcp += srcp_linesize;\n\n }\n\n } else {\n\n av_image_copy_plane(dstp, dstp_linesize, srcp, srcp_linesize, cols, lines);\n\n }\n\n }\n\n}\n", + "output": "0", + "index": 1581 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "MigrationInfo *qmp_query_migrate(Error **errp)\n\n{\n\n MigrationInfo *info = g_malloc0(sizeof(*info));\n\n MigrationState *s = migrate_get_current();\n\n\n\n switch (s->state) {\n\n case MIGRATION_STATUS_NONE:\n\n /* no migration has happened ever */\n\n break;\n\n case MIGRATION_STATUS_SETUP:\n\n info->has_status = true;\n\n info->status = MIGRATION_STATUS_SETUP;\n\n info->has_total_time = false;\n\n break;\n\n case MIGRATION_STATUS_ACTIVE:\n\n case MIGRATION_STATUS_CANCELLING:\n\n info->has_status = true;\n\n info->status = MIGRATION_STATUS_ACTIVE;\n\n info->has_total_time = true;\n\n info->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME)\n\n - s->total_time;\n\n info->has_expected_downtime = true;\n\n info->expected_downtime = s->expected_downtime;\n\n info->has_setup_time = true;\n\n info->setup_time = s->setup_time;\n\n\n\n info->has_ram = true;\n\n info->ram = g_malloc0(sizeof(*info->ram));\n\n info->ram->transferred = ram_bytes_transferred();\n\n info->ram->remaining = ram_bytes_remaining();\n\n info->ram->total = ram_bytes_total();\n\n info->ram->duplicate = dup_mig_pages_transferred();\n\n info->ram->skipped = skipped_mig_pages_transferred();\n\n info->ram->normal = norm_mig_pages_transferred();\n\n info->ram->normal_bytes = norm_mig_bytes_transferred();\n\n info->ram->dirty_pages_rate = s->dirty_pages_rate;\n\n info->ram->mbps = s->mbps;\n\n info->ram->dirty_sync_count = s->dirty_sync_count;\n\n\n\n if (blk_mig_active()) {\n\n info->has_disk = true;\n\n info->disk = g_malloc0(sizeof(*info->disk));\n\n info->disk->transferred = blk_mig_bytes_transferred();\n\n info->disk->remaining = blk_mig_bytes_remaining();\n\n info->disk->total = blk_mig_bytes_total();\n\n }\n\n\n\n get_xbzrle_cache_stats(info);\n\n break;\n\n case MIGRATION_STATUS_COMPLETED:\n\n get_xbzrle_cache_stats(info);\n\n\n\n info->has_status = true;\n\n info->status = MIGRATION_STATUS_COMPLETED;\n\n info->has_total_time = true;\n\n info->total_time = s->total_time;\n\n info->has_downtime = true;\n\n info->downtime = s->downtime;\n\n info->has_setup_time = true;\n\n info->setup_time = s->setup_time;\n\n\n\n info->has_ram = true;\n\n info->ram = g_malloc0(sizeof(*info->ram));\n\n info->ram->transferred = ram_bytes_transferred();\n\n info->ram->remaining = 0;\n\n info->ram->total = ram_bytes_total();\n\n info->ram->duplicate = dup_mig_pages_transferred();\n\n info->ram->skipped = skipped_mig_pages_transferred();\n\n info->ram->normal = norm_mig_pages_transferred();\n\n info->ram->normal_bytes = norm_mig_bytes_transferred();\n\n info->ram->mbps = s->mbps;\n\n info->ram->dirty_sync_count = s->dirty_sync_count;\n\n break;\n\n case MIGRATION_STATUS_FAILED:\n\n info->has_status = true;\n\n info->status = MIGRATION_STATUS_FAILED;\n\n break;\n\n case MIGRATION_STATUS_CANCELLED:\n\n info->has_status = true;\n\n info->status = MIGRATION_STATUS_CANCELLED;\n\n break;\n\n }\n\n\n\n return info;\n\n}\n", + "output": "0", + "index": 12725 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold int twin_decode_init(AVCodecContext *avctx)\n\n{\n\n int ret;\n\n TwinContext *tctx = avctx->priv_data;\n\n int isampf, ibps;\n\n\n\n tctx->avctx = avctx;\n\n avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;\n\n\n\n if (!avctx->extradata || avctx->extradata_size < 12) {\n\n av_log(avctx, AV_LOG_ERROR, \"Missing or incomplete extradata\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n avctx->channels = AV_RB32(avctx->extradata ) + 1;\n\n avctx->bit_rate = AV_RB32(avctx->extradata + 4) * 1000;\n\n isampf = AV_RB32(avctx->extradata + 8);\n\n switch (isampf) {\n\n case 44: avctx->sample_rate = 44100; break;\n\n case 22: avctx->sample_rate = 22050; break;\n\n case 11: avctx->sample_rate = 11025; break;\n\n default: avctx->sample_rate = isampf * 1000; break;\n\n }\n\n\n\n if (avctx->channels > CHANNELS_MAX) {\n\n av_log(avctx, AV_LOG_ERROR, \"Unsupported number of channels: %i\\n\",\n\n avctx->channels);\n\n return -1;\n\n }\n\n ibps = avctx->bit_rate / (1000 * avctx->channels);\n\n\n\n switch ((isampf << 8) + ibps) {\n\n case (8 <<8) + 8: tctx->mtab = &mode_08_08; break;\n\n case (11<<8) + 8: tctx->mtab = &mode_11_08; break;\n\n case (11<<8) + 10: tctx->mtab = &mode_11_10; break;\n\n case (16<<8) + 16: tctx->mtab = &mode_16_16; break;\n\n case (22<<8) + 20: tctx->mtab = &mode_22_20; break;\n\n case (22<<8) + 24: tctx->mtab = &mode_22_24; break;\n\n case (22<<8) + 32: tctx->mtab = &mode_22_32; break;\n\n case (44<<8) + 40: tctx->mtab = &mode_44_40; break;\n\n case (44<<8) + 48: tctx->mtab = &mode_44_48; break;\n\n default:\n\n av_log(avctx, AV_LOG_ERROR, \"This version does not support %d kHz - %d kbit/s/ch mode.\\n\", isampf, isampf);\n\n return -1;\n\n }\n\n\n\n ff_dsputil_init(&tctx->dsp, avctx);\n\n avpriv_float_dsp_init(&tctx->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);\n\n if ((ret = init_mdct_win(tctx))) {\n\n av_log(avctx, AV_LOG_ERROR, \"Error initializing MDCT\\n\");\n\n twin_decode_close(avctx);\n\n return ret;\n\n }\n\n init_bitstream_params(tctx);\n\n\n\n memset_float(tctx->bark_hist[0][0], 0.1, FF_ARRAY_ELEMS(tctx->bark_hist));\n\n\n\n avcodec_get_frame_defaults(&tctx->frame);\n\n avctx->coded_frame = &tctx->frame;\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 24119 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void mcf_fec_receive(void *opaque, const uint8_t *buf, size_t size)\n\n{\n\n mcf_fec_state *s = (mcf_fec_state *)opaque;\n\n mcf_fec_bd bd;\n\n uint32_t flags = 0;\n\n uint32_t addr;\n\n uint32_t crc;\n\n uint32_t buf_addr;\n\n uint8_t *crc_ptr;\n\n unsigned int buf_len;\n\n\n\n DPRINTF(\"do_rx len %d\\n\", size);\n\n if (!s->rx_enabled) {\n\n fprintf(stderr, \"mcf_fec_receive: Unexpected packet\\n\");\n\n }\n\n /* 4 bytes for the CRC. */\n\n size += 4;\n\n crc = cpu_to_be32(crc32(~0, buf, size));\n\n crc_ptr = (uint8_t *)&crc;\n\n /* Huge frames are truncted. */\n\n if (size > FEC_MAX_FRAME_SIZE) {\n\n size = FEC_MAX_FRAME_SIZE;\n\n flags |= FEC_BD_TR | FEC_BD_LG;\n\n }\n\n /* Frames larger than the user limit just set error flags. */\n\n if (size > (s->rcr >> 16)) {\n\n flags |= FEC_BD_LG;\n\n }\n\n addr = s->rx_descriptor;\n\n while (size > 0) {\n\n mcf_fec_read_bd(&bd, addr);\n\n if ((bd.flags & FEC_BD_E) == 0) {\n\n /* No descriptors available. Bail out. */\n\n /* FIXME: This is wrong. We should probably either save the\n\n remainder for when more RX buffers are available, or\n\n flag an error. */\n\n fprintf(stderr, \"mcf_fec: Lost end of frame\\n\");\n\n break;\n\n }\n\n buf_len = (size <= s->emrbr) ? size: s->emrbr;\n\n bd.length = buf_len;\n\n size -= buf_len;\n\n DPRINTF(\"rx_bd %x length %d\\n\", addr, bd.length);\n\n /* The last 4 bytes are the CRC. */\n\n if (size < 4)\n\n buf_len += size - 4;\n\n buf_addr = bd.data;\n\n cpu_physical_memory_write(buf_addr, buf, buf_len);\n\n buf += buf_len;\n\n if (size < 4) {\n\n cpu_physical_memory_write(buf_addr + buf_len, crc_ptr, 4 - size);\n\n crc_ptr += 4 - size;\n\n }\n\n bd.flags &= ~FEC_BD_E;\n\n if (size == 0) {\n\n /* Last buffer in frame. */\n\n bd.flags |= flags | FEC_BD_L;\n\n DPRINTF(\"rx frame flags %04x\\n\", bd.flags);\n\n s->eir |= FEC_INT_RXF;\n\n } else {\n\n s->eir |= FEC_INT_RXB;\n\n }\n\n mcf_fec_write_bd(&bd, addr);\n\n /* Advance to the next descriptor. */\n\n if ((bd.flags & FEC_BD_W) != 0) {\n\n addr = s->erdsr;\n\n } else {\n\n addr += 8;\n\n }\n\n }\n\n s->rx_descriptor = addr;\n\n mcf_fec_enable_rx(s);\n\n mcf_fec_update(s);\n\n}\n", + "output": "0", + "index": 18876 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int hdev_open(BlockDriverState *bs, QDict *options, int flags,\n\n Error **errp)\n\n{\n\n BDRVRawState *s = bs->opaque;\n\n Error *local_err = NULL;\n\n int ret;\n\n\n\n#if defined(__APPLE__) && defined(__MACH__)\n\n\n\n\n\n\n\n const char *filename = qdict_get_str(options, \"filename\");\n\n char bsd_path[MAXPATHLEN] = \"\";\n\n bool error_occurred = false;\n\n\n\n /* If using a real cdrom */\n\n if (strcmp(filename, \"/dev/cdrom\") == 0) {\n\n char *mediaType = NULL;\n\n kern_return_t ret_val;\n\n io_iterator_t mediaIterator = 0;\n\n\n\n mediaType = FindEjectableOpticalMedia(&mediaIterator);\n\n if (mediaType == NULL) {\n\n error_setg(errp, \"Please make sure your CD/DVD is in the optical\"\n\n \" drive\");\n\n error_occurred = true;\n\n goto hdev_open_Mac_error;\n\n }\n\n\n\n ret_val = GetBSDPath(mediaIterator, bsd_path, sizeof(bsd_path), flags);\n\n if (ret_val != KERN_SUCCESS) {\n\n error_setg(errp, \"Could not get BSD path for optical drive\");\n\n error_occurred = true;\n\n goto hdev_open_Mac_error;\n\n }\n\n\n\n /* If a real optical drive was not found */\n\n if (bsd_path[0] == '\\0') {\n\n error_setg(errp, \"Failed to obtain bsd path for optical drive\");\n\n error_occurred = true;\n\n goto hdev_open_Mac_error;\n\n }\n\n\n\n /* If using a cdrom disc and finding a partition on the disc failed */\n\n if (strncmp(mediaType, kIOCDMediaClass, 9) == 0 &&\n\n setup_cdrom(bsd_path, errp) == false) {\n\n print_unmounting_directions(bsd_path);\n\n error_occurred = true;\n\n goto hdev_open_Mac_error;\n\n }\n\n\n\n qdict_put(options, \"filename\", qstring_from_str(bsd_path));\n\n\n\nhdev_open_Mac_error:\n\n g_free(mediaType);\n\n if (mediaIterator) {\n\n IOObjectRelease(mediaIterator);\n\n }\n\n if (error_occurred) {\n\n return -ENOENT;\n\n }\n\n }\n\n#endif /* defined(__APPLE__) && defined(__MACH__) */\n\n\n\n s->type = FTYPE_FILE;\n\n\n\n ret = raw_open_common(bs, options, flags, 0, &local_err);\n\n if (ret < 0) {\n\n error_propagate(errp, local_err);\n\n#if defined(__APPLE__) && defined(__MACH__)\n\n if (*bsd_path) {\n\n filename = bsd_path;\n\n }\n\n /* if a physical device experienced an error while being opened */\n\n if (strncmp(filename, \"/dev/\", 5) == 0) {\n\n print_unmounting_directions(filename);\n\n }\n\n#endif /* defined(__APPLE__) && defined(__MACH__) */\n\n return ret;\n\n }\n\n\n\n /* Since this does ioctl the device must be already opened */\n\n bs->sg = hdev_is_sg(bs);\n\n\n\n if (flags & BDRV_O_RDWR) {\n\n ret = check_hdev_writable(s);\n\n if (ret < 0) {\n\n raw_close(bs);\n\n error_setg_errno(errp, -ret, \"The device is not writable\");\n\n return ret;\n\n }\n\n }\n\n\n\n return ret;\n\n}", + "output": "1", + "index": 19238 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int compand_delay(AVFilterContext *ctx, AVFrame *frame)\n\n{\n\n CompandContext *s = ctx->priv;\n\n AVFilterLink *inlink = ctx->inputs[0];\n\n const int channels = inlink->channels;\n\n const int nb_samples = frame->nb_samples;\n\n int chan, i, av_uninit(dindex), oindex, av_uninit(count);\n\n AVFrame *out_frame = NULL;\n\n\n\n if (s->pts == AV_NOPTS_VALUE) {\n\n s->pts = (frame->pts == AV_NOPTS_VALUE) ? 0 : frame->pts;\n\n }\n\n\n\n av_assert1(channels > 0); /* would corrupt delay_count and delay_index */\n\n\n\n for (chan = 0; chan < channels; chan++) {\n\n AVFrame *delay_frame = s->delay_frame;\n\n const double *src = (double *)frame->extended_data[chan];\n\n double *dbuf = (double *)delay_frame->extended_data[chan];\n\n ChanParam *cp = &s->channels[chan];\n\n double *dst;\n\n\n\n count = s->delay_count;\n\n dindex = s->delay_index;\n\n for (i = 0, oindex = 0; i < nb_samples; i++) {\n\n const double in = src[i];\n\n update_volume(cp, fabs(in));\n\n\n\n if (count >= s->delay_samples) {\n\n if (!out_frame) {\n\n out_frame = ff_get_audio_buffer(inlink, nb_samples - i);\n\n if (!out_frame) {\n\n av_frame_free(&frame);\n\n return AVERROR(ENOMEM);\n\n }\n\n av_frame_copy_props(out_frame, frame);\n\n out_frame->pts = s->pts;\n\n s->pts += av_rescale_q(nb_samples - i,\n\n (AVRational){ 1, inlink->sample_rate },\n\n inlink->time_base);\n\n }\n\n\n\n dst = (double *)out_frame->extended_data[chan];\n\n dst[oindex++] = av_clipd(dbuf[dindex] *\n\n get_volume(s, cp->volume), -1, 1);\n\n } else {\n\n count++;\n\n }\n\n\n\n dbuf[dindex] = in;\n\n dindex = MOD(dindex + 1, s->delay_samples);\n\n }\n\n }\n\n\n\n s->delay_count = count;\n\n s->delay_index = dindex;\n\n\n\n av_frame_free(&frame);\n\n return out_frame ? ff_filter_frame(ctx->outputs[0], out_frame) : 0;\n\n}\n", + "output": "0", + "index": 19627 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void qpeg_decode_intra(uint8_t *src, uint8_t *dst, int size,\n\n\t\t\t int stride, int width, int height)\n\n{\n\n int i;\n\n int code;\n\n int c0, c1;\n\n int run, copy;\n\n int filled = 0;\n\n \n\n height--;\n\n dst = dst + height * stride;\n\n \n\n while(size > 0) {\n\n\tcode = *src++;\n\n\tsize--;\n\n\trun = copy = 0;\n\n\tif(code == 0xFC) /* end-of-picture code */\n\n\t break;\n\n\tif(code >= 0xF8) { /* very long run */\n\n\t c0 = *src++;\n\n\t c1 = *src++;\n\n\t size -= 2;\n\n\t run = ((code & 0x7) << 16) + (c0 << 8) + c1 + 2;\n\n\t} else if (code >= 0xF0) { /* long run */\n\n\t c0 = *src++;\n\n\t size--;\n\n\t run = ((code & 0xF) << 8) + c0 + 2;\n\n\t} else if (code >= 0xE0) { /* short run */\n\n\t run = (code & 0x1F) + 2;\n\n\t} else if (code >= 0xC0) { /* very long copy */\n\n\t c0 = *src++;\n\n\t c1 = *src++;\n\n\t size -= 2;\n\n\t copy = ((code & 0x3F) << 16) + (c0 << 8) + c1 + 1;\n\n\t} else if (code >= 0x80) { /* long copy */\n\n\t c0 = *src++;\n\n\t size--;\n\n\t copy = ((code & 0x7F) << 8) + c0 + 1;\n\n\t} else { /* short copy */\n\n\t copy = code + 1;\n\n\t}\n\n\t\n\n\t/* perform actual run or copy */\n\n\tif(run) {\n\n\t int p;\n\n\t \n\n\t p = *src++;\n\n\t size--;\n\n\t for(i = 0; i < run; i++) {\n\n\t\tdst[filled++] = p;\n\n\t\tif (filled >= width) {\n\n\t\t filled = 0;\n\n\t\t dst -= stride;\n\n\t\t}\n\n\t }\n\n\t} else {\n\n\t for(i = 0; i < copy; i++) {\n\n\t\tdst[filled++] = *src++;\n\n\t\tif (filled >= width) {\n\n\t\t filled = 0;\n\n\t\t dst -= stride;\n\n\t\t}\n\n\t }\n\n\t size -= copy;\n\n\t}\n\n }\n\n}\n", + "output": "1", + "index": 10698 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void ff_aac_search_for_is(AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe)\n\n{\n\n SingleChannelElement *sce0 = &cpe->ch[0];\n\n SingleChannelElement *sce1 = &cpe->ch[1];\n\n int start = 0, count = 0, w, w2, g, i, prev_sf1 = -1;\n\n const float freq_mult = avctx->sample_rate/(1024.0f/sce0->ics.num_windows)/2.0f;\n\n uint8_t nextband1[128];\n\n\n\n if (!cpe->common_window)\n\n return;\n\n\n\n /** Scout out next nonzero bands */\n\n ff_init_nextband_map(sce1, nextband1);\n\n\n\n for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {\n\n start = 0;\n\n for (g = 0; g < sce0->ics.num_swb; g++) {\n\n if (start*freq_mult > INT_STEREO_LOW_LIMIT*(s->lambda/170.0f) &&\n\n cpe->ch[0].band_type[w*16+g] != NOISE_BT && !cpe->ch[0].zeroes[w*16+g] &&\n\n cpe->ch[1].band_type[w*16+g] != NOISE_BT && !cpe->ch[1].zeroes[w*16+g] &&\n\n ff_sfdelta_can_remove_band(sce1, nextband1, prev_sf1, w*16+g)) {\n\n float ener0 = 0.0f, ener1 = 0.0f, ener01 = 0.0f, ener01p = 0.0f;\n\n struct AACISError ph_err1, ph_err2, *best;\n\n if (sce0->band_type[w*16+g] == NOISE_BT ||\n\n sce1->band_type[w*16+g] == NOISE_BT) {\n\n start += sce0->ics.swb_sizes[g];\n\n continue;\n\n }\n\n for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {\n\n for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {\n\n float coef0 = fabsf(sce0->coeffs[start+(w+w2)*128+i]);\n\n float coef1 = fabsf(sce1->coeffs[start+(w+w2)*128+i]);\n\n ener0 += coef0*coef0;\n\n ener1 += coef1*coef1;\n\n ener01 += (coef0 + coef1)*(coef0 + coef1);\n\n ener01p += (coef0 - coef1)*(coef0 - coef1);\n\n }\n\n }\n\n ph_err1 = ff_aac_is_encoding_err(s, cpe, start, w, g,\n\n ener0, ener1, ener01p, 0, -1);\n\n ph_err2 = ff_aac_is_encoding_err(s, cpe, start, w, g,\n\n ener0, ener1, ener01, 0, +1);\n\n best = (ph_err1.pass && ph_err1.error < ph_err2.error) ? &ph_err1 : &ph_err2;\n\n if (best->pass) {\n\n cpe->is_mask[w*16+g] = 1;\n\n cpe->ms_mask[w*16+g] = 0;\n\n cpe->ch[0].is_ener[w*16+g] = sqrt(ener0 / best->ener01);\n\n cpe->ch[1].is_ener[w*16+g] = ener0/ener1;\n\n cpe->ch[1].band_type[w*16+g] = (best->phase > 0) ? INTENSITY_BT : INTENSITY_BT2;\n\n count++;\n\n }\n\n }\n\n if (!sce1->zeroes[w*16+g] && sce1->band_type[w*16+g] < RESERVED_BT)\n\n prev_sf1 = sce1->sf_idx[w*16+g];\n\n start += sce0->ics.swb_sizes[g];\n\n }\n\n }\n\n cpe->is_mode = !!count;\n\n}\n", + "output": "0", + "index": 22405 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size)\n\n{\n\n GetBitContext gb;\n\n int specific_config_bitindex;\n\n\n\n init_get_bits(&gb, buf, buf_size*8);\n\n c->object_type = get_object_type(&gb);\n\n c->sample_rate = get_sample_rate(&gb, &c->sampling_index);\n\n c->chan_config = get_bits(&gb, 4);\n\n if (c->chan_config < FF_ARRAY_ELEMS(ff_mpeg4audio_channels))\n\n c->channels = ff_mpeg4audio_channels[c->chan_config];\n\n c->sbr = -1;\n\n if (c->object_type == AOT_SBR || (c->object_type == AOT_PS &&\n\n // check for W6132 Annex YYYY draft MP3onMP4\n\n !(show_bits(&gb, 3) & 0x03 && !(show_bits(&gb, 9) & 0x3F)))) {\n\n c->ext_object_type = AOT_SBR;\n\n c->sbr = 1;\n\n c->ext_sample_rate = get_sample_rate(&gb, &c->ext_sampling_index);\n\n c->object_type = get_object_type(&gb);\n\n if (c->object_type == AOT_ER_BSAC)\n\n c->ext_chan_config = get_bits(&gb, 4);\n\n } else {\n\n c->ext_object_type = AOT_NULL;\n\n c->ext_sample_rate = 0;\n\n }\n\n specific_config_bitindex = get_bits_count(&gb);\n\n\n\n if (c->object_type == AOT_ALS) {\n\n skip_bits(&gb, 5);\n\n if (show_bits_long(&gb, 24) != MKBETAG('\\0','A','L','S'))\n\n skip_bits_long(&gb, 24);\n\n\n\n specific_config_bitindex = get_bits_count(&gb);\n\n\n\n if (parse_config_ALS(&gb, c))\n\n return -1;\n\n }\n\n\n\n if (c->ext_object_type != AOT_SBR) {\n\n int bits_left = buf_size*8 - get_bits_count(&gb);\n\n for (; bits_left > 15; bits_left--) {\n\n if (show_bits(&gb, 11) == 0x2b7) { // sync extension\n\n get_bits(&gb, 11);\n\n c->ext_object_type = get_object_type(&gb);\n\n if (c->ext_object_type == AOT_SBR && (c->sbr = get_bits1(&gb)) == 1)\n\n c->ext_sample_rate = get_sample_rate(&gb, &c->ext_sampling_index);\n\n break;\n\n } else\n\n get_bits1(&gb); // skip 1 bit\n\n }\n\n }\n\n return specific_config_bitindex;\n\n}\n", + "output": "0", + "index": 26047 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "main(\n\n int argc,\n\n char *argv[]\n\n) {\n\n GMainLoop *loop;\n\n GIOChannel *channel_stdin;\n\n char *qemu_host;\n\n char *qemu_port;\n\n VSCMsgHeader mhHeader;\n\n\n\n VCardEmulOptions *command_line_options = NULL;\n\n\n\n char *cert_names[MAX_CERTS];\n\n char *emul_args = NULL;\n\n int cert_count = 0;\n\n int c, sock;\n\n\n\n if (socket_init() != 0)\n\n return 1;\n\n\n\n while ((c = getopt(argc, argv, \"c:e:pd:\")) != -1) {\n\n switch (c) {\n\n case 'c':\n\n if (cert_count >= MAX_CERTS) {\n\n printf(\"too many certificates (max = %d)\\n\", MAX_CERTS);\n\n exit(5);\n\n }\n\n cert_names[cert_count++] = optarg;\n\n break;\n\n case 'e':\n\n emul_args = optarg;\n\n break;\n\n case 'p':\n\n print_usage();\n\n exit(4);\n\n break;\n\n case 'd':\n\n verbose = get_id_from_string(optarg, 1);\n\n break;\n\n }\n\n }\n\n\n\n if (argc - optind != 2) {\n\n print_usage();\n\n exit(4);\n\n }\n\n\n\n if (cert_count > 0) {\n\n char *new_args;\n\n int len, i;\n\n /* if we've given some -c options, we clearly we want do so some\n\n * software emulation. add that emulation now. this is NSS Emulator\n\n * specific */\n\n if (emul_args == NULL) {\n\n emul_args = (char *)\"db=\\\"/etc/pki/nssdb\\\"\";\n\n }\n\n#define SOFT_STRING \",soft=(,Virtual Reader,CAC,,\"\n\n /* 2 == close paren & null */\n\n len = strlen(emul_args) + strlen(SOFT_STRING) + 2;\n\n for (i = 0; i < cert_count; i++) {\n\n len += strlen(cert_names[i])+1; /* 1 == comma */\n\n }\n\n new_args = g_malloc(len);\n\n strcpy(new_args, emul_args);\n\n strcat(new_args, SOFT_STRING);\n\n for (i = 0; i < cert_count; i++) {\n\n strcat(new_args, cert_names[i]);\n\n strcat(new_args, \",\");\n\n }\n\n strcat(new_args, \")\");\n\n emul_args = new_args;\n\n }\n\n if (emul_args) {\n\n command_line_options = vcard_emul_options(emul_args);\n\n }\n\n\n\n qemu_host = g_strdup(argv[argc - 2]);\n\n qemu_port = g_strdup(argv[argc - 1]);\n\n sock = connect_to_qemu(qemu_host, qemu_port);\n\n if (sock == -1) {\n\n fprintf(stderr, \"error opening socket, exiting.\\n\");\n\n exit(5);\n\n }\n\n\n\n socket_to_send = g_byte_array_new();\n\n qemu_mutex_init(&socket_to_send_lock);\n\n qemu_mutex_init(&pending_reader_lock);\n\n qemu_cond_init(&pending_reader_condition);\n\n\n\n vcard_emul_init(command_line_options);\n\n\n\n loop = g_main_loop_new(NULL, true);\n\n\n\n printf(\"> \");\n\n fflush(stdout);\n\n\n\n#ifdef _WIN32\n\n channel_stdin = g_io_channel_win32_new_fd(STDIN_FILENO);\n\n#else\n\n channel_stdin = g_io_channel_unix_new(STDIN_FILENO);\n\n#endif\n\n g_io_add_watch(channel_stdin, G_IO_IN, do_command, NULL);\n\n#ifdef _WIN32\n\n channel_socket = g_io_channel_win32_new_socket(sock);\n\n#else\n\n channel_socket = g_io_channel_unix_new(sock);\n\n#endif\n\n g_io_channel_set_encoding(channel_socket, NULL, NULL);\n\n /* we buffer ourself for thread safety reasons */\n\n g_io_channel_set_buffered(channel_socket, FALSE);\n\n\n\n /* Send init message, Host responds (and then we send reader attachments) */\n\n VSCMsgInit init = {\n\n .version = htonl(VSCARD_VERSION),\n\n .magic = VSCARD_MAGIC,\n\n .capabilities = {0}\n\n };\n\n send_msg(VSC_Init, mhHeader.reader_id, &init, sizeof(init));\n\n\n\n g_main_loop_run(loop);\n\n g_main_loop_unref(loop);\n\n\n\n g_io_channel_unref(channel_stdin);\n\n g_io_channel_unref(channel_socket);\n\n g_byte_array_unref(socket_to_send);\n\n\n\n closesocket(sock);\n\n return 0;\n\n}\n", + "output": "1", + "index": 337 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int get_mmu_address(CPUState * env, target_ulong * physical,\n\n\t\t\t int *prot, target_ulong address,\n\n\t\t\t int rw, int access_type)\n\n{\n\n int use_asid, n;\n\n tlb_t *matching = NULL;\n\n\n\n use_asid = (env->mmucr & MMUCR_SV) == 0 || (env->sr & SR_MD) == 0;\n\n\n\n if (rw == 2) {\n\n\tn = find_itlb_entry(env, address, use_asid, 1);\n\n\tif (n >= 0) {\n\n\t matching = &env->itlb[n];\n\n\t if ((env->sr & SR_MD) & !(matching->pr & 2))\n\n\t\tn = MMU_ITLB_VIOLATION;\n\n\t else\n\n\t\t*prot = PAGE_READ;\n\n\t}\n\n } else {\n\n\tn = find_utlb_entry(env, address, use_asid);\n\n\tif (n >= 0) {\n\n\t matching = &env->utlb[n];\n\n\t switch ((matching->pr << 1) | ((env->sr & SR_MD) ? 1 : 0)) {\n\n\t case 0:\t\t/* 000 */\n\n\t case 2:\t\t/* 010 */\n\n\t\tn = (rw == 1) ? MMU_DTLB_VIOLATION_WRITE :\n\n\t\t MMU_DTLB_VIOLATION_READ;\n\n\t\tbreak;\n\n\t case 1:\t\t/* 001 */\n\n\t case 4:\t\t/* 100 */\n\n\t case 5:\t\t/* 101 */\n\n\t\tif (rw == 1)\n\n\t\t n = MMU_DTLB_VIOLATION_WRITE;\n\n\t\telse\n\n\t\t *prot = PAGE_READ;\n\n\t\tbreak;\n\n\t case 3:\t\t/* 011 */\n\n\t case 6:\t\t/* 110 */\n\n\t case 7:\t\t/* 111 */\n\n\t\t*prot = (rw == 1)? PAGE_WRITE : PAGE_READ;\n\n\t\tbreak;\n\n\t }\n\n\t} else if (n == MMU_DTLB_MISS) {\n\n\t n = (rw == 1) ? MMU_DTLB_MISS_WRITE :\n\n\t\tMMU_DTLB_MISS_READ;\n\n\t}\n\n }\n\n if (n >= 0) {\n\n\t*physical = ((matching->ppn << 10) & ~(matching->size - 1)) |\n\n\t (address & (matching->size - 1));\n\n\tif ((rw == 1) & !matching->d)\n\n\t n = MMU_DTLB_INITIAL_WRITE;\n\n\telse\n\n\t n = MMU_OK;\n\n }\n\n return n;\n\n}\n", + "output": "0", + "index": 7087 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,\n\n void (*init)(struct CharDriverState *s),\n\n Error **errp)\n\n{\n\n CharDriver *cd;\n\n CharDriverState *chr;\n\n GSList *i;\n\n\n\n if (qemu_opts_id(opts) == NULL) {\n\n error_setg(errp, \"chardev: no id specified\");\n\n goto err;\n\n }\n\n\n\n if (qemu_opt_get(opts, \"backend\") == NULL) {\n\n error_setg(errp, \"chardev: \\\"%s\\\" missing backend\",\n\n qemu_opts_id(opts));\n\n goto err;\n\n }\n\n for (i = backends; i; i = i->next) {\n\n cd = i->data;\n\n\n\n if (strcmp(cd->name, qemu_opt_get(opts, \"backend\")) == 0) {\n\n break;\n\n }\n\n }\n\n if (i == NULL) {\n\n error_setg(errp, \"chardev: backend \\\"%s\\\" not found\",\n\n qemu_opt_get(opts, \"backend\"));\n\n goto err;\n\n }\n\n\n\n if (!cd->open) {\n\n /* using new, qapi init */\n\n ChardevBackend *backend = g_new0(ChardevBackend, 1);\n\n ChardevReturn *ret = NULL;\n\n const char *id = qemu_opts_id(opts);\n\n const char *bid = NULL;\n\n\n\n if (qemu_opt_get_bool(opts, \"mux\", 0)) {\n\n bid = g_strdup_printf(\"%s-base\", id);\n\n }\n\n\n\n chr = NULL;\n\n backend->kind = cd->kind;\n\n if (cd->parse) {\n\n cd->parse(opts, backend, errp);\n\n if (error_is_set(errp)) {\n\n goto qapi_out;\n\n }\n\n }\n\n ret = qmp_chardev_add(bid ? bid : id, backend, errp);\n\n if (error_is_set(errp)) {\n\n goto qapi_out;\n\n }\n\n\n\n if (bid) {\n\n qapi_free_ChardevBackend(backend);\n\n qapi_free_ChardevReturn(ret);\n\n backend = g_new0(ChardevBackend, 1);\n\n backend->mux = g_new0(ChardevMux, 1);\n\n backend->kind = CHARDEV_BACKEND_KIND_MUX;\n\n backend->mux->chardev = g_strdup(bid);\n\n ret = qmp_chardev_add(id, backend, errp);\n\n if (error_is_set(errp)) {\n\n goto qapi_out;\n\n }\n\n }\n\n\n\n chr = qemu_chr_find(id);\n\n\n\n qapi_out:\n\n qapi_free_ChardevBackend(backend);\n\n qapi_free_ChardevReturn(ret);\n\n return chr;\n\n }\n\n\n\n chr = cd->open(opts);\n\n if (!chr) {\n\n error_setg(errp, \"chardev: opening backend \\\"%s\\\" failed\",\n\n qemu_opt_get(opts, \"backend\"));\n\n goto err;\n\n }\n\n\n\n if (!chr->filename)\n\n chr->filename = g_strdup(qemu_opt_get(opts, \"backend\"));\n\n chr->init = init;\n\n /* if we didn't create the chardev via qmp_chardev_add, we\n\n * need to send the OPENED event here\n\n */\n\n if (!chr->explicit_be_open) {\n\n qemu_chr_be_event(chr, CHR_EVENT_OPENED);\n\n }\n\n QTAILQ_INSERT_TAIL(&chardevs, chr, next);\n\n\n\n if (qemu_opt_get_bool(opts, \"mux\", 0)) {\n\n CharDriverState *base = chr;\n\n int len = strlen(qemu_opts_id(opts)) + 6;\n\n base->label = g_malloc(len);\n\n snprintf(base->label, len, \"%s-base\", qemu_opts_id(opts));\n\n chr = qemu_chr_open_mux(base);\n\n chr->filename = base->filename;\n\n chr->avail_connections = MAX_MUX;\n\n QTAILQ_INSERT_TAIL(&chardevs, chr, next);\n\n } else {\n\n chr->avail_connections = 1;\n\n }\n\n chr->label = g_strdup(qemu_opts_id(opts));\n\n chr->opts = opts;\n\n return chr;\n\n\n\nerr:\n\n qemu_opts_del(opts);\n\n return NULL;\n\n}\n", + "output": "1", + "index": 25340 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "exynos4210_combiner_read(void *opaque, target_phys_addr_t offset, unsigned size)\n\n{\n\n struct Exynos4210CombinerState *s =\n\n (struct Exynos4210CombinerState *)opaque;\n\n uint32_t req_quad_base_n; /* Base of registers quad. Multiply it by 4 and\n\n get a start of corresponding group quad */\n\n uint32_t grp_quad_base_n; /* Base of group quad */\n\n uint32_t reg_n; /* Register number inside the quad */\n\n uint32_t val;\n\n\n\n req_quad_base_n = offset >> 4;\n\n grp_quad_base_n = req_quad_base_n << 2;\n\n reg_n = (offset - (req_quad_base_n << 4)) >> 2;\n\n\n\n if (req_quad_base_n >= IIC_NGRP) {\n\n /* Read of ICIPSR register */\n\n return s->icipsr[reg_n];\n\n }\n\n\n\n val = 0;\n\n\n\n switch (reg_n) {\n\n /* IISTR */\n\n case 2:\n\n val |= s->group[grp_quad_base_n].src_pending;\n\n val |= s->group[grp_quad_base_n + 1].src_pending << 8;\n\n val |= s->group[grp_quad_base_n + 2].src_pending << 16;\n\n val |= s->group[grp_quad_base_n + 3].src_pending << 24;\n\n break;\n\n /* IIMSR */\n\n case 3:\n\n val |= s->group[grp_quad_base_n].src_mask &\n\n s->group[grp_quad_base_n].src_pending;\n\n val |= (s->group[grp_quad_base_n + 1].src_mask &\n\n s->group[grp_quad_base_n + 1].src_pending) << 8;\n\n val |= (s->group[grp_quad_base_n + 2].src_mask &\n\n s->group[grp_quad_base_n + 2].src_pending) << 16;\n\n val |= (s->group[grp_quad_base_n + 3].src_mask &\n\n s->group[grp_quad_base_n + 3].src_pending) << 24;\n\n break;\n\n default:\n\n if (offset >> 2 >= IIC_REGSET_SIZE) {\n\n hw_error(\"exynos4210.combiner: overflow of reg_set by 0x\"\n\n TARGET_FMT_plx \"offset\\n\", offset);\n\n }\n\n val = s->reg_set[offset >> 2];\n\n return 0;\n\n }\n\n return val;\n\n}\n", + "output": "0", + "index": 26452 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void hmp_info_block(Monitor *mon, const QDict *qdict)\n\n{\n\n BlockInfoList *block_list, *info;\n\n ImageInfo *image_info;\n\n const char *device = qdict_get_try_str(qdict, \"device\");\n\n bool verbose = qdict_get_try_bool(qdict, \"verbose\", 0);\n\n\n\n block_list = qmp_query_block(NULL);\n\n\n\n for (info = block_list; info; info = info->next) {\n\n if (device && strcmp(device, info->value->device)) {\n\n continue;\n\n }\n\n monitor_printf(mon, \"%s: removable=%d\",\n\n info->value->device, info->value->removable);\n\n\n\n if (info->value->removable) {\n\n monitor_printf(mon, \" locked=%d\", info->value->locked);\n\n monitor_printf(mon, \" tray-open=%d\", info->value->tray_open);\n\n }\n\n\n\n if (info->value->has_io_status) {\n\n monitor_printf(mon, \" io-status=%s\",\n\n BlockDeviceIoStatus_lookup[info->value->io_status]);\n\n }\n\n\n\n if (info->value->has_inserted) {\n\n monitor_printf(mon, \" file=\");\n\n monitor_print_filename(mon, info->value->inserted->file);\n\n\n\n if (info->value->inserted->has_backing_file) {\n\n monitor_printf(mon, \" backing_file=\");\n\n monitor_print_filename(mon, info->value->inserted->backing_file);\n\n monitor_printf(mon, \" backing_file_depth=%\" PRId64,\n\n info->value->inserted->backing_file_depth);\n\n }\n\n monitor_printf(mon, \" ro=%d drv=%s encrypted=%d\",\n\n info->value->inserted->ro,\n\n info->value->inserted->drv,\n\n info->value->inserted->encrypted);\n\n\n\n monitor_printf(mon, \" bps=%\" PRId64 \" bps_rd=%\" PRId64\n\n \" bps_wr=%\" PRId64 \" iops=%\" PRId64\n\n \" iops_rd=%\" PRId64 \" iops_wr=%\" PRId64,\n\n info->value->inserted->bps,\n\n info->value->inserted->bps_rd,\n\n info->value->inserted->bps_wr,\n\n info->value->inserted->iops,\n\n info->value->inserted->iops_rd,\n\n info->value->inserted->iops_wr);\n\n\n\n if (verbose) {\n\n monitor_printf(mon, \" images:\\n\");\n\n image_info = info->value->inserted->image;\n\n while (1) {\n\n bdrv_image_info_dump((fprintf_function)monitor_printf,\n\n mon, image_info);\n\n if (image_info->has_backing_image) {\n\n image_info = image_info->backing_image;\n\n } else {\n\n break;\n\n }\n\n }\n\n }\n\n } else {\n\n monitor_printf(mon, \" [not inserted]\");\n\n }\n\n\n\n monitor_printf(mon, \"\\n\");\n\n }\n\n\n\n qapi_free_BlockInfoList(block_list);\n\n}\n", + "output": "0", + "index": 23554 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void h263_encode_init(MpegEncContext *s)\n\n{\n\n static int done = 0;\n\n\n\n if (!done) {\n\n done = 1;\n\n\n\n init_uni_dc_tab();\n\n\n\n init_rl(&rl_inter);\n\n init_rl(&rl_intra);\n\n init_rl(&rl_intra_aic);\n\n \n\n init_uni_mpeg4_rl_tab(&rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);\n\n init_uni_mpeg4_rl_tab(&rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);\n\n\n\n init_uni_h263_rl_tab(&rl_intra_aic, NULL, uni_h263_intra_aic_rl_len);\n\n init_uni_h263_rl_tab(&rl_inter , NULL, uni_h263_inter_rl_len);\n\n\n\n init_mv_penalty_and_fcode(s);\n\n }\n\n s->me.mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p\n\n \n\n s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len;\n\n s->intra_ac_vlc_last_length=s->inter_ac_vlc_last_length= uni_h263_inter_rl_len + 128*64;\n\n if(s->h263_aic){\n\n s->intra_ac_vlc_length = uni_h263_intra_aic_rl_len;\n\n s->intra_ac_vlc_last_length= uni_h263_intra_aic_rl_len + 128*64;\n\n }\n\n s->ac_esc_length= 7+1+6+8;\n\n\n\n // use fcodes >1 only for mpeg4 & h263 & h263p FIXME\n\n switch(s->codec_id){\n\n case CODEC_ID_MPEG4:\n\n s->fcode_tab= fcode_tab;\n\n s->min_qcoeff= -2048;\n\n s->max_qcoeff= 2047;\n\n s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len;\n\n s->intra_ac_vlc_last_length= uni_mpeg4_intra_rl_len + 128*64;\n\n s->inter_ac_vlc_length = uni_mpeg4_inter_rl_len;\n\n s->inter_ac_vlc_last_length= uni_mpeg4_inter_rl_len + 128*64;\n\n s->luma_dc_vlc_length= uni_DCtab_lum_len;\n\n s->chroma_dc_vlc_length= uni_DCtab_chrom_len;\n\n s->ac_esc_length= 7+2+1+6+1+12+1;\n\n s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;\n\n s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;\n\n\n\n if(s->flags & CODEC_FLAG_GLOBAL_HEADER){\n\n\n\n s->avctx->extradata= av_malloc(1024);\n\n init_put_bits(&s->pb, s->avctx->extradata, 1024);\n\n \n\n mpeg4_encode_visual_object_header(s);\n\n mpeg4_encode_vol_header(s, 0, 0);\n\n\n\n// ff_mpeg4_stuffing(&s->pb); ?\n\n flush_put_bits(&s->pb);\n\n s->avctx->extradata_size= (put_bits_count(&s->pb)+7)>>3;\n\n }\n\n \n\n break;\n\n case CODEC_ID_H263P:\n\n if(s->umvplus)\n\n s->fcode_tab= umv_fcode_tab;\n\n if(s->modified_quant){\n\n s->min_qcoeff= -2047;\n\n s->max_qcoeff= 2047;\n\n }else{\n\n s->min_qcoeff= -127;\n\n s->max_qcoeff= 127;\n\n }\n\n break;\n\n //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later \n\n case CODEC_ID_FLV1:\n\n if (s->h263_flv > 1) {\n\n s->min_qcoeff= -1023;\n\n s->max_qcoeff= 1023;\n\n } else {\n\n s->min_qcoeff= -127;\n\n s->max_qcoeff= 127;\n\n }\n\n s->y_dc_scale_table=\n\n s->c_dc_scale_table= ff_mpeg1_dc_scale_table;\n\n break;\n\n default: //nothing needed default table allready set in mpegvideo.c\n\n s->min_qcoeff= -127;\n\n s->max_qcoeff= 127;\n\n s->y_dc_scale_table=\n\n s->c_dc_scale_table= ff_mpeg1_dc_scale_table;\n\n }\n\n}\n", + "output": "1", + "index": 13040 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int spapr_populate_drconf_memory(sPAPRMachineState *spapr, void *fdt)\n\n{\n\n MachineState *machine = MACHINE(spapr);\n\n int ret, i, offset;\n\n uint64_t lmb_size = SPAPR_MEMORY_BLOCK_SIZE;\n\n uint32_t prop_lmb_size[] = {0, cpu_to_be32(lmb_size)};\n\n uint32_t nr_lmbs = (machine->maxram_size - machine->ram_size)/lmb_size;\n\n uint32_t *int_buf, *cur_index, buf_len;\n\n int nr_nodes = nb_numa_nodes ? nb_numa_nodes : 1;\n\n\n\n /* Allocate enough buffer size to fit in ibm,dynamic-memory */\n\n buf_len = nr_lmbs * SPAPR_DR_LMB_LIST_ENTRY_SIZE * sizeof(uint32_t) +\n\n sizeof(uint32_t);\n\n cur_index = int_buf = g_malloc0(buf_len);\n\n\n\n offset = fdt_add_subnode(fdt, 0, \"ibm,dynamic-reconfiguration-memory\");\n\n\n\n ret = fdt_setprop(fdt, offset, \"ibm,lmb-size\", prop_lmb_size,\n\n sizeof(prop_lmb_size));\n\n if (ret < 0) {\n\n goto out;\n\n }\n\n\n\n ret = fdt_setprop_cell(fdt, offset, \"ibm,memory-flags-mask\", 0xff);\n\n if (ret < 0) {\n\n goto out;\n\n }\n\n\n\n ret = fdt_setprop_cell(fdt, offset, \"ibm,memory-preservation-time\", 0x0);\n\n if (ret < 0) {\n\n goto out;\n\n }\n\n\n\n /* ibm,dynamic-memory */\n\n int_buf[0] = cpu_to_be32(nr_lmbs);\n\n cur_index++;\n\n for (i = 0; i < nr_lmbs; i++) {\n\n sPAPRDRConnector *drc;\n\n sPAPRDRConnectorClass *drck;\n\n uint64_t addr = i * lmb_size + spapr->hotplug_memory.base;;\n\n uint32_t *dynamic_memory = cur_index;\n\n\n\n drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB,\n\n addr/lmb_size);\n\n g_assert(drc);\n\n drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);\n\n\n\n dynamic_memory[0] = cpu_to_be32(addr >> 32);\n\n dynamic_memory[1] = cpu_to_be32(addr & 0xffffffff);\n\n dynamic_memory[2] = cpu_to_be32(drck->get_index(drc));\n\n dynamic_memory[3] = cpu_to_be32(0); /* reserved */\n\n dynamic_memory[4] = cpu_to_be32(numa_get_node(addr, NULL));\n\n if (addr < machine->ram_size ||\n\n memory_region_present(get_system_memory(), addr)) {\n\n dynamic_memory[5] = cpu_to_be32(SPAPR_LMB_FLAGS_ASSIGNED);\n\n } else {\n\n dynamic_memory[5] = cpu_to_be32(0);\n\n }\n\n\n\n cur_index += SPAPR_DR_LMB_LIST_ENTRY_SIZE;\n\n }\n\n ret = fdt_setprop(fdt, offset, \"ibm,dynamic-memory\", int_buf, buf_len);\n\n if (ret < 0) {\n\n goto out;\n\n }\n\n\n\n /* ibm,associativity-lookup-arrays */\n\n cur_index = int_buf;\n\n int_buf[0] = cpu_to_be32(nr_nodes);\n\n int_buf[1] = cpu_to_be32(4); /* Number of entries per associativity list */\n\n cur_index += 2;\n\n for (i = 0; i < nr_nodes; i++) {\n\n uint32_t associativity[] = {\n\n cpu_to_be32(0x0),\n\n cpu_to_be32(0x0),\n\n cpu_to_be32(0x0),\n\n cpu_to_be32(i)\n\n };\n\n memcpy(cur_index, associativity, sizeof(associativity));\n\n cur_index += 4;\n\n }\n\n ret = fdt_setprop(fdt, offset, \"ibm,associativity-lookup-arrays\", int_buf,\n\n (cur_index - int_buf) * sizeof(uint32_t));\n\nout:\n\n g_free(int_buf);\n\n return ret;\n\n}\n", + "output": "1", + "index": 708 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int os_host_main_loop_wait(int64_t timeout)\n{\n GMainContext *context = g_main_context_default();\n GPollFD poll_fds[1024 * 2]; /* this is probably overkill */\n int select_ret = 0;\n int g_poll_ret, ret, i, n_poll_fds;\n PollingEntry *pe;\n WaitObjects *w = &wait_objects;\n gint poll_timeout;\n int64_t poll_timeout_ns;\n static struct timeval tv0;\n fd_set rfds, wfds, xfds;\n int nfds;\n /* XXX: need to suppress polling by better using win32 events */\n ret = 0;\n for (pe = first_polling_entry; pe != NULL; pe = pe->next) {\n ret |= pe->func(pe->opaque);\n }\n if (ret != 0) {\n return ret;\n }\n FD_ZERO(&rfds);\n FD_ZERO(&wfds);\n FD_ZERO(&xfds);\n nfds = pollfds_fill(gpollfds, &rfds, &wfds, &xfds);\n if (nfds >= 0) {\n select_ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv0);\n if (select_ret != 0) {\n timeout = 0;\n }\n if (select_ret > 0) {\n pollfds_poll(gpollfds, nfds, &rfds, &wfds, &xfds);\n }\n }\n g_main_context_prepare(context, &max_priority);\n n_poll_fds = g_main_context_query(context, max_priority, &poll_timeout,\n poll_fds, ARRAY_SIZE(poll_fds));\n g_assert(n_poll_fds <= ARRAY_SIZE(poll_fds));\n for (i = 0; i < w->num; i++) {\n poll_fds[n_poll_fds + i].fd = (DWORD_PTR)w->events[i];\n poll_fds[n_poll_fds + i].events = G_IO_IN;\n }\n if (poll_timeout < 0) {\n poll_timeout_ns = -1;\n } else {\n poll_timeout_ns = (int64_t)poll_timeout * (int64_t)SCALE_MS;\n }\n poll_timeout_ns = qemu_soonest_timeout(poll_timeout_ns, timeout);\n qemu_mutex_unlock_iothread();\n g_poll_ret = qemu_poll_ns(poll_fds, n_poll_fds + w->num, poll_timeout_ns);\n qemu_mutex_lock_iothread();\n if (g_poll_ret > 0) {\n for (i = 0; i < w->num; i++) {\n w->revents[i] = poll_fds[n_poll_fds + i].revents;\n }\n for (i = 0; i < w->num; i++) {\n if (w->revents[i] && w->func[i]) {\n w->func[i](w->opaque[i]);\n }\n }\n }\n if (g_main_context_check(context, max_priority, poll_fds, n_poll_fds)) {\n g_main_context_dispatch(context);\n }\n return select_ret || g_poll_ret;\n}", + "output": "1", + "index": 11113 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int dnxhd_init_vlc(DNXHDEncContext *ctx)\n\n{\n\n int i, j, level, run;\n\n int max_level = 1<<(ctx->cid_table->bit_depth+2);\n\n\n\n FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes), fail);\n\n FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits, max_level*4*sizeof(*ctx->vlc_bits) , fail);\n\n FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2, fail);\n\n FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits, 63, fail);\n\n\n\n ctx->vlc_codes += max_level*2;\n\n ctx->vlc_bits += max_level*2;\n\n for (level = -max_level; level < max_level; level++) {\n\n for (run = 0; run < 2; run++) {\n\n int index = (level<<1)|run;\n\n int sign, offset = 0, alevel = level;\n\n\n\n MASK_ABS(sign, alevel);\n\n if (alevel > 64) {\n\n offset = (alevel-1)>>6;\n\n alevel -= offset<<6;\n\n }\n\n for (j = 0; j < 257; j++) {\n\n if (ctx->cid_table->ac_level[j] >> 1 == alevel &&\n\n (!offset || (ctx->cid_table->ac_index_flag[j] && offset)) &&\n\n (!run || (ctx->cid_table->ac_run_flag [j] && run))) {\n\n assert(!ctx->vlc_codes[index]);\n\n if (alevel) {\n\n ctx->vlc_codes[index] = (ctx->cid_table->ac_codes[j]<<1)|(sign&1);\n\n ctx->vlc_bits [index] = ctx->cid_table->ac_bits[j]+1;\n\n } else {\n\n ctx->vlc_codes[index] = ctx->cid_table->ac_codes[j];\n\n ctx->vlc_bits [index] = ctx->cid_table->ac_bits [j];\n\n }\n\n break;\n\n }\n\n }\n\n assert(!alevel || j < 257);\n\n if (offset) {\n\n ctx->vlc_codes[index] = (ctx->vlc_codes[index]<cid_table->index_bits)|offset;\n\n ctx->vlc_bits [index]+= ctx->cid_table->index_bits;\n\n }\n\n }\n\n }\n\n for (i = 0; i < 62; i++) {\n\n int run = ctx->cid_table->run[i];\n\n assert(run < 63);\n\n ctx->run_codes[run] = ctx->cid_table->run_codes[i];\n\n ctx->run_bits [run] = ctx->cid_table->run_bits[i];\n\n }\n\n return 0;\n\n fail:\n\n return -1;\n\n}\n", + "output": "0", + "index": 18223 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, int flags)\n\n{\n\n FFMContext *ffm = s->priv_data;\n\n int64_t pos_min, pos_max, pos;\n\n int64_t pts_min, pts_max, pts;\n\n double pos1;\n\n\n\n av_dlog(s, \"wanted_pts=%0.6f\\n\", wanted_pts / 1000000.0);\n\n /* find the position using linear interpolation (better than\n\n dichotomy in typical cases) */\n\n if (ffm->write_index && ffm->write_index < ffm->file_size) {\n\n if (get_dts(s, FFM_PACKET_SIZE) < wanted_pts) {\n\n pos_min = FFM_PACKET_SIZE;\n\n pos_max = ffm->write_index - FFM_PACKET_SIZE;\n\n } else {\n\n pos_min = ffm->write_index;\n\n pos_max = ffm->file_size - FFM_PACKET_SIZE;\n\n }\n\n } else {\n\n pos_min = FFM_PACKET_SIZE;\n\n pos_max = ffm->file_size - FFM_PACKET_SIZE;\n\n }\n\n while (pos_min <= pos_max) {\n\n pts_min = get_dts(s, pos_min);\n\n pts_max = get_dts(s, pos_max);\n\n if (pts_min > wanted_pts || pts_max < wanted_pts) {\n\n pos = pts_min > wanted_pts ? pos_min : pos_max;\n\n goto found;\n\n }\n\n /* linear interpolation */\n\n pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) /\n\n (double)(pts_max - pts_min);\n\n pos = (((int64_t)pos1) / FFM_PACKET_SIZE) * FFM_PACKET_SIZE;\n\n if (pos <= pos_min)\n\n pos = pos_min;\n\n else if (pos >= pos_max)\n\n pos = pos_max;\n\n pts = get_dts(s, pos);\n\n /* check if we are lucky */\n\n if (pts == wanted_pts) {\n\n goto found;\n\n } else if (pts > wanted_pts) {\n\n pos_max = pos - FFM_PACKET_SIZE;\n\n } else {\n\n pos_min = pos + FFM_PACKET_SIZE;\n\n }\n\n }\n\n pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max;\n\n\n\n found:\n\n if (ffm_seek1(s, pos) < 0)\n\n return -1;\n\n\n\n /* reset read state */\n\n ffm->read_state = READ_HEADER;\n\n ffm->packet_ptr = ffm->packet;\n\n ffm->packet_end = ffm->packet;\n\n ffm->first_packet = 1;\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 9526 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int av_opt_is_set_to_default(void *obj, const AVOption *o)\n\n{\n\n int64_t i64;\n\n double d, d2;\n\n float f;\n\n AVRational q;\n\n int ret, w, h;\n\n char *str;\n\n void *dst;\n\n\n\n if (!o || !obj)\n\n return AVERROR(EINVAL);\n\n\n\n dst = ((uint8_t*)obj) + o->offset;\n\n\n\n switch (o->type) {\n\n case AV_OPT_TYPE_CONST:\n\n return 1;\n\n case AV_OPT_TYPE_FLAGS:\n\n case AV_OPT_TYPE_PIXEL_FMT:\n\n case AV_OPT_TYPE_SAMPLE_FMT:\n\n case AV_OPT_TYPE_INT:\n\n case AV_OPT_TYPE_CHANNEL_LAYOUT:\n\n case AV_OPT_TYPE_DURATION:\n\n case AV_OPT_TYPE_INT64:\n\n read_number(o, dst, NULL, NULL, &i64);\n\n return o->default_val.i64 == i64;\n\n case AV_OPT_TYPE_STRING:\n\n str = *(char **)dst;\n\n if (str == o->default_val.str) //2 NULLs\n\n return 1;\n\n if (!str || !o->default_val.str) //1 NULL\n\n return 0;\n\n return !strcmp(str, o->default_val.str);\n\n case AV_OPT_TYPE_DOUBLE:\n\n read_number(o, dst, &d, NULL, NULL);\n\n return o->default_val.dbl == d;\n\n case AV_OPT_TYPE_FLOAT:\n\n read_number(o, dst, &d, NULL, NULL);\n\n f = o->default_val.dbl;\n\n d2 = f;\n\n return d2 == d;\n\n case AV_OPT_TYPE_RATIONAL:\n\n q = av_d2q(o->default_val.dbl, INT_MAX);\n\n return !av_cmp_q(*(AVRational*)dst, q);\n\n case AV_OPT_TYPE_BINARY: {\n\n struct {\n\n uint8_t *data;\n\n int size;\n\n } tmp = {0};\n\n int opt_size = *(int *)((void **)dst + 1);\n\n void *opt_ptr = *(void **)dst;\n\n if (!opt_ptr && (!o->default_val.str || !strlen(o->default_val.str)))\n\n return 1;\n\n if (opt_ptr && o->default_val.str && !strlen(o->default_val.str))\n\n return 0;\n\n if (opt_size != strlen(o->default_val.str) / 2)\n\n return 0;\n\n ret = set_string_binary(NULL, NULL, o->default_val.str, &tmp.data);\n\n if (!ret)\n\n ret = !memcmp(opt_ptr, tmp.data, tmp.size);\n\n av_free(tmp.data);\n\n return ret;\n\n }\n\n case AV_OPT_TYPE_DICT:\n\n /* Binary and dict have not default support yet. Any pointer is not default. */\n\n return !!(*(void **)dst);\n\n case AV_OPT_TYPE_IMAGE_SIZE:\n\n if (!o->default_val.str || !strcmp(o->default_val.str, \"none\"))\n\n w = h = 0;\n\n else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0)\n\n return ret;\n\n return (w == *(int *)dst) && (h == *((int *)dst+1));\n\n case AV_OPT_TYPE_VIDEO_RATE:\n\n q = (AVRational){0, 0};\n\n if (o->default_val.str)\n\n av_parse_video_rate(&q, o->default_val.str);\n\n return !av_cmp_q(*(AVRational*)dst, q);\n\n case AV_OPT_TYPE_COLOR: {\n\n uint8_t color[4] = {0, 0, 0, 0};\n\n if (o->default_val.str)\n\n av_parse_color(color, o->default_val.str, -1, NULL);\n\n return !memcmp(color, dst, sizeof(color));\n\n }\n\n default:\n\n av_log(obj, AV_LOG_WARNING, \"Not supported option type: %d, option name: %s\\n\", o->type, o->name);\n\n break;\n\n }\n\n return AVERROR_PATCHWELCOME;\n\n}\n", + "output": "0", + "index": 25308 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int encode_slices(VC2EncContext *s)\n\n{\n\n uint8_t *buf;\n\n int i, slice_x, slice_y, skip = 0;\n\n int bytes_left = 0;\n\n SliceArgs *enc_args = s->slice_args;\n\n\n\n int bytes_top[SLICE_REDIST_TOTAL] = {0};\n\n SliceArgs *top_loc[SLICE_REDIST_TOTAL] = {NULL};\n\n\n\n avpriv_align_put_bits(&s->pb);\n\n flush_put_bits(&s->pb);\n\n buf = put_bits_ptr(&s->pb);\n\n\n\n for (slice_y = 0; slice_y < s->num_y; slice_y++) {\n\n for (slice_x = 0; slice_x < s->num_x; slice_x++) {\n\n SliceArgs *args = &enc_args[s->num_x*slice_y + slice_x];\n\n bytes_left += args->bytes_left;\n\n for (i = 0; i < FFMIN(SLICE_REDIST_TOTAL, s->num_x*s->num_y); i++) {\n\n if (args->bytes > bytes_top[i]) {\n\n bytes_top[i] = args->bytes;\n\n top_loc[i] = args;\n\n break;\n\n }\n\n }\n\n }\n\n }\n\n\n\n while (1) {\n\n int distributed = 0;\n\n for (i = 0; i < FFMIN(SLICE_REDIST_TOTAL, s->num_x*s->num_y); i++) {\n\n SliceArgs *args;\n\n int bits, bytes, diff, prev_bytes, new_idx;\n\n if (bytes_left <= 0)\n\n break;\n\n if (!top_loc[i] || !top_loc[i]->quant_idx)\n\n break;\n\n args = top_loc[i];\n\n prev_bytes = args->bytes;\n\n new_idx = av_clip(args->quant_idx - 1, 0, s->q_ceil);\n\n bits = count_hq_slice(s, args->cache, args->x, args->y, new_idx);\n\n bytes = FFALIGN((bits >> 3), s->size_scaler) + 4 + s->prefix_bytes;\n\n diff = bytes - prev_bytes;\n\n if ((bytes_left - diff) >= 0) {\n\n args->quant_idx = new_idx;\n\n args->bytes = bytes;\n\n bytes_left -= diff;\n\n distributed++;\n\n }\n\n }\n\n if (!distributed)\n\n break;\n\n }\n\n\n\n for (slice_y = 0; slice_y < s->num_y; slice_y++) {\n\n for (slice_x = 0; slice_x < s->num_x; slice_x++) {\n\n SliceArgs *args = &enc_args[s->num_x*slice_y + slice_x];\n\n init_put_bits(&args->pb, buf + skip, args->bytes);\n\n s->q_avg = (s->q_avg + args->quant_idx)/2;\n\n skip += args->bytes;\n\n }\n\n }\n\n\n\n s->avctx->execute(s->avctx, encode_hq_slice, enc_args, NULL, s->num_x*s->num_y,\n\n sizeof(SliceArgs));\n\n\n\n skip_put_bytes(&s->pb, skip);\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 2769 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void ff_fft_calc_sse(FFTContext *s, FFTComplex *z)\n\n{\n\n int ln = s->nbits;\n\n long i, j;\n\n long nblocks, nloops;\n\n FFTComplex *p, *cptr;\n\n\n\n asm volatile(\n\n \"movaps %0, %%xmm4 \\n\\t\"\n\n \"movaps %1, %%xmm5 \\n\\t\"\n\n ::\"m\"(*p1p1m1m1),\n\n \"m\"(*(s->inverse ? p1p1m1p1 : p1p1p1m1))\n\n );\n\n\n\n i = 8 << ln;\n\n asm volatile(\n\n \"1: \\n\\t\"\n\n \"sub $32, %0 \\n\\t\"\n\n /* do the pass 0 butterfly */\n\n \"movaps (%0,%1), %%xmm0 \\n\\t\"\n\n \"movaps %%xmm0, %%xmm1 \\n\\t\"\n\n \"shufps $0x4E, %%xmm0, %%xmm0 \\n\\t\"\n\n \"xorps %%xmm4, %%xmm1 \\n\\t\"\n\n \"addps %%xmm1, %%xmm0 \\n\\t\"\n\n \"movaps 16(%0,%1), %%xmm2 \\n\\t\"\n\n \"movaps %%xmm2, %%xmm3 \\n\\t\"\n\n \"shufps $0x4E, %%xmm2, %%xmm2 \\n\\t\"\n\n \"xorps %%xmm4, %%xmm3 \\n\\t\"\n\n \"addps %%xmm3, %%xmm2 \\n\\t\"\n\n /* multiply third by -i */\n\n /* by toggling the sign bit */\n\n \"shufps $0xB4, %%xmm2, %%xmm2 \\n\\t\"\n\n \"xorps %%xmm5, %%xmm2 \\n\\t\"\n\n /* do the pass 1 butterfly */\n\n \"movaps %%xmm0, %%xmm1 \\n\\t\"\n\n \"addps %%xmm2, %%xmm0 \\n\\t\"\n\n \"subps %%xmm2, %%xmm1 \\n\\t\"\n\n \"movaps %%xmm0, (%0,%1) \\n\\t\"\n\n \"movaps %%xmm1, 16(%0,%1) \\n\\t\"\n\n \"jg 1b \\n\\t\"\n\n :\"+r\"(i)\n\n :\"r\"(z)\n\n );\n\n /* pass 2 .. ln-1 */\n\n\n\n nblocks = 1 << (ln-3);\n\n nloops = 1 << 2;\n\n cptr = s->exptab1;\n\n do {\n\n p = z;\n\n j = nblocks;\n\n do {\n\n i = nloops*8;\n\n asm volatile(\n\n \"1: \\n\\t\"\n\n \"sub $16, %0 \\n\\t\"\n\n \"movaps (%2,%0), %%xmm1 \\n\\t\"\n\n \"movaps (%1,%0), %%xmm0 \\n\\t\"\n\n \"movaps %%xmm1, %%xmm2 \\n\\t\"\n\n \"shufps $0xA0, %%xmm1, %%xmm1 \\n\\t\"\n\n \"shufps $0xF5, %%xmm2, %%xmm2 \\n\\t\"\n\n \"mulps (%3,%0,2), %%xmm1 \\n\\t\" // cre*re cim*re\n\n \"mulps 16(%3,%0,2), %%xmm2 \\n\\t\" // -cim*im cre*im\n\n \"addps %%xmm2, %%xmm1 \\n\\t\"\n\n \"movaps %%xmm0, %%xmm3 \\n\\t\"\n\n \"addps %%xmm1, %%xmm0 \\n\\t\"\n\n \"subps %%xmm1, %%xmm3 \\n\\t\"\n\n \"movaps %%xmm0, (%1,%0) \\n\\t\"\n\n \"movaps %%xmm3, (%2,%0) \\n\\t\"\n\n \"jg 1b \\n\\t\"\n\n :\"+r\"(i)\n\n :\"r\"(p), \"r\"(p + nloops), \"r\"(cptr)\n\n );\n\n p += nloops*2;\n\n } while (--j);\n\n cptr += nloops*2;\n\n nblocks >>= 1;\n\n nloops <<= 1;\n\n } while (nblocks != 0);\n\n}\n", + "output": "0", + "index": 10119 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void idct_col(int16_t *blk, const uint8_t *quant)\n\n{\n\n int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, tA, tB, tC, tD, tE, tF;\n\n int t10, t11, t12, t13;\n\n int s0, s1, s2, s3, s4, s5, s6, s7;\n\n\n\n s0 = (int) blk[0 * 8] * quant[0 * 8];\n\n s1 = (int) blk[1 * 8] * quant[1 * 8];\n\n s2 = (int) blk[2 * 8] * quant[2 * 8];\n\n s3 = (int) blk[3 * 8] * quant[3 * 8];\n\n s4 = (int) blk[4 * 8] * quant[4 * 8];\n\n s5 = (int) blk[5 * 8] * quant[5 * 8];\n\n s6 = (int) blk[6 * 8] * quant[6 * 8];\n\n s7 = (int) blk[7 * 8] * quant[7 * 8];\n\n\n\n t0 = (s3 * 19266 + s5 * 12873) >> 15;\n\n t1 = (s5 * 19266 - s3 * 12873) >> 15;\n\n t2 = ((s7 * 4520 + s1 * 22725) >> 15) - t0;\n\n t3 = ((s1 * 4520 - s7 * 22725) >> 15) - t1;\n\n t4 = t0 * 2 + t2;\n\n t5 = t1 * 2 + t3;\n\n t6 = t2 - t3;\n\n t7 = t3 * 2 + t6;\n\n t8 = (t6 * 11585) >> 14;\n\n t9 = (t7 * 11585) >> 14;\n\n tA = (s2 * 8867 - s6 * 21407) >> 14;\n\n tB = (s6 * 8867 + s2 * 21407) >> 14;\n\n tC = (s0 >> 1) - (s4 >> 1);\n\n tD = (s4 >> 1) * 2 + tC;\n\n tE = tC - (tA >> 1);\n\n tF = tD - (tB >> 1);\n\n t10 = tF - t5;\n\n t11 = tE - t8;\n\n t12 = tE + (tA >> 1) * 2 - t9;\n\n t13 = tF + (tB >> 1) * 2 - t4;\n\n\n\n blk[0 * 8] = t13 + t4 * 2;\n\n blk[1 * 8] = t12 + t9 * 2;\n\n blk[2 * 8] = t11 + t8 * 2;\n\n blk[3 * 8] = t10 + t5 * 2;\n\n blk[4 * 8] = t10;\n\n blk[5 * 8] = t11;\n\n blk[6 * 8] = t12;\n\n blk[7 * 8] = t13;\n\n}\n", + "output": "1", + "index": 25081 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,\n\n void *logctx, int is_nalff, int nal_length_size,\n\n enum AVCodecID codec_id)\n\n{\n\n int consumed, ret = 0;\n\n const uint8_t *next_avc = buf + (is_nalff ? 0 : length);\n\n\n\n pkt->nb_nals = 0;\n\n while (length >= 4) {\n\n H2645NAL *nal;\n\n int extract_length = 0;\n\n int skip_trailing_zeros = 1;\n\n\n\n /*\n\n * Only parse an AVC1 length field if one is expected at the current\n\n * buffer position. There are unfortunately streams with multiple\n\n * NAL units covered by the length field. Those NAL units are delimited\n\n * by Annex B start code prefixes. ff_h2645_extract_rbsp() detects it\n\n * correctly and consumes only the first NAL unit. The additional NAL\n\n * units are handled here in the Annex B parsing code.\n\n */\n\n if (buf == next_avc) {\n\n int i;\n\n for (i = 0; i < nal_length_size; i++)\n\n extract_length = (extract_length << 8) | buf[i];\n\n\n\n if (extract_length > length) {\n\n av_log(logctx, AV_LOG_ERROR,\n\n \"Invalid NAL unit size (%d > %d).\\n\",\n\n extract_length, length);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n buf += nal_length_size;\n\n length -= nal_length_size;\n\n // keep track of the next AVC1 length field\n\n next_avc = buf + extract_length;\n\n } else {\n\n /*\n\n * expected to return immediately except for streams with mixed\n\n * NAL unit coding\n\n */\n\n int buf_index = find_next_start_code(buf, next_avc);\n\n\n\n buf += buf_index;\n\n length -= buf_index;\n\n\n\n /*\n\n * break if an AVC1 length field is expected at the current buffer\n\n * position\n\n */\n\n if (buf == next_avc)\n\n continue;\n\n\n\n if (length > 0) {\n\n extract_length = length;\n\n } else if (pkt->nb_nals == 0) {\n\n av_log(logctx, AV_LOG_ERROR, \"No NAL unit found\\n\");\n\n return AVERROR_INVALIDDATA;\n\n } else {\n\n break;\n\n }\n\n }\n\n\n\n if (pkt->nals_allocated < pkt->nb_nals + 1) {\n\n int new_size = pkt->nals_allocated + 1;\n\n H2645NAL *tmp = av_realloc_array(pkt->nals, new_size, sizeof(*tmp));\n\n if (!tmp)\n\n return AVERROR(ENOMEM);\n\n\n\n pkt->nals = tmp;\n\n memset(pkt->nals + pkt->nals_allocated, 0,\n\n (new_size - pkt->nals_allocated) * sizeof(*tmp));\n\n pkt->nals_allocated = new_size;\n\n }\n\n nal = &pkt->nals[pkt->nb_nals++];\n\n\n\n consumed = ff_h2645_extract_rbsp(buf, extract_length, nal);\n\n if (consumed < 0)\n\n return consumed;\n\n\n\n /* see commit 3566042a0 */\n\n if (consumed < length - 3 &&\n\n buf[consumed] == 0x00 && buf[consumed + 1] == 0x00 &&\n\n buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)\n\n skip_trailing_zeros = 0;\n\n\n\n nal->size_bits = get_bit_length(nal, skip_trailing_zeros);\n\n\n\n ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);\n\n if (ret < 0)\n\n return ret;\n\n\n\n if (codec_id == AV_CODEC_ID_HEVC)\n\n ret = hevc_parse_nal_header(nal, logctx);\n\n else\n\n ret = h264_parse_nal_header(nal, logctx);\n\n if (ret <= 0) {\n\n if (ret < 0) {\n\n av_log(logctx, AV_LOG_ERROR, \"Invalid NAL unit %d, skipping.\\n\",\n\n nal->type);\n\n }\n\n pkt->nb_nals--;\n\n }\n\n\n\n buf += consumed;\n\n length -= consumed;\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 18207 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void virtio_blk_handle_request(VirtIOBlockReq *req,\n\n MultiReqBuffer *mrb)\n\n{\n\n uint32_t type;\n\n struct iovec *iov = req->elem->out_sg;\n\n unsigned out_num = req->elem->out_num;\n\n\n\n if (req->elem->out_num < 1 || req->elem->in_num < 1) {\n\n error_report(\"virtio-blk missing headers\");\n\n exit(1);\n\n }\n\n\n\n if (req->elem->out_sg[0].iov_len < sizeof(req->out) ||\n\n req->elem->in_sg[req->elem->in_num - 1].iov_len < sizeof(*req->in)) {\n\n error_report(\"virtio-blk header not in correct element\");\n\n exit(1);\n\n }\n\n\n\n if (unlikely(iov_to_buf(iov, out_num, 0, &req->out,\n\n sizeof(req->out)) != sizeof(req->out))) {\n\n error_report(\"virtio-blk request outhdr too short\");\n\n exit(1);\n\n }\n\n iov_discard_front(&iov, &out_num, sizeof(req->out));\n\n req->in = (void *)req->elem->in_sg[req->elem->in_num - 1].iov_base;\n\n\n\n type = ldl_p(&req->out.type);\n\n\n\n if (type & VIRTIO_BLK_T_FLUSH) {\n\n virtio_blk_handle_flush(req, mrb);\n\n } else if (type & VIRTIO_BLK_T_SCSI_CMD) {\n\n virtio_blk_handle_scsi(req);\n\n } else if (type & VIRTIO_BLK_T_GET_ID) {\n\n VirtIOBlock *s = req->dev;\n\n\n\n /*\n\n * NB: per existing s/n string convention the string is\n\n * terminated by '\\0' only when shorter than buffer.\n\n */\n\n strncpy(req->elem->in_sg[0].iov_base,\n\n s->blk.serial ? s->blk.serial : \"\",\n\n MIN(req->elem->in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));\n\n virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);\n\n virtio_blk_free_request(req);\n\n } else if (type & VIRTIO_BLK_T_OUT) {\n\n qemu_iovec_init_external(&req->qiov, &req->elem->out_sg[1],\n\n req->elem->out_num - 1);\n\n virtio_blk_handle_write(req, mrb);\n\n } else if (type == VIRTIO_BLK_T_IN || type == VIRTIO_BLK_T_BARRIER) {\n\n /* VIRTIO_BLK_T_IN is 0, so we can't just & it. */\n\n qemu_iovec_init_external(&req->qiov, &req->elem->in_sg[0],\n\n req->elem->in_num - 1);\n\n virtio_blk_handle_read(req);\n\n } else {\n\n virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP);\n\n virtio_blk_free_request(req);\n\n }\n\n}\n", + "output": "0", + "index": 22192 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void setup_frame(int sig, struct target_sigaction *ka,\n\n target_sigset_t *set, CPUPPCState *env)\n\n{\n\n struct target_sigframe *frame;\n\n struct target_sigcontext *sc;\n\n target_ulong frame_addr, newsp;\n\n int err = 0;\n\n int signal;\n\n\n\n frame_addr = get_sigframe(ka, env, sizeof(*frame));\n\n if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 1))\n\n goto sigsegv;\n\n sc = &frame->sctx;\n\n\n\n signal = current_exec_domain_sig(sig);\n\n\n\n __put_user(ka->_sa_handler, &sc->handler);\n\n __put_user(set->sig[0], &sc->oldmask);\n\n#if defined(TARGET_PPC64)\n\n __put_user(set->sig[0] >> 32, &sc->_unused[3]);\n\n#else\n\n __put_user(set->sig[1], &sc->_unused[3]);\n\n#endif\n\n __put_user(h2g(&frame->mctx), &sc->regs);\n\n __put_user(sig, &sc->signal);\n\n\n\n /* Save user regs. */\n\n err |= save_user_regs(env, &frame->mctx, TARGET_NR_sigreturn);\n\n\n\n /* The kernel checks for the presence of a VDSO here. We don't\n\n emulate a vdso, so use a sigreturn system call. */\n\n env->lr = (target_ulong) h2g(frame->mctx.tramp);\n\n\n\n /* Turn off all fp exceptions. */\n\n env->fpscr = 0;\n\n\n\n /* Create a stack frame for the caller of the handler. */\n\n newsp = frame_addr - SIGNAL_FRAMESIZE;\n\n err |= put_user(env->gpr[1], newsp, target_ulong);\n\n\n\n if (err)\n\n goto sigsegv;\n\n\n\n /* Set up registers for signal handler. */\n\n env->gpr[1] = newsp;\n\n env->gpr[3] = signal;\n\n env->gpr[4] = frame_addr + offsetof(struct target_sigframe, sctx);\n\n env->nip = (target_ulong) ka->_sa_handler;\n\n /* Signal handlers are entered in big-endian mode. */\n\n env->msr &= ~MSR_LE;\n\n\n\n unlock_user_struct(frame, frame_addr, 1);\n\n return;\n\n\n\nsigsegv:\n\n unlock_user_struct(frame, frame_addr, 1);\n\n qemu_log(\"segfaulting from setup_frame\\n\");\n\n force_sig(TARGET_SIGSEGV);\n\n}\n", + "output": "0", + "index": 26961 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void encode_cblk(Jpeg2000EncoderContext *s, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, Jpeg2000Tile *tile,\n\n int width, int height, int bandpos, int lev)\n\n{\n\n int pass_t = 2, passno, x, y, max=0, nmsedec, bpno;\n\n int64_t wmsedec = 0;\n\n\n\n memset(t1->flags, 0, t1->stride * (height + 2) * sizeof(*t1->flags));\n\n\n\n for (y = 0; y < height; y++){\n\n for (x = 0; x < width; x++){\n\n if (t1->data[(y) * t1->stride + x] < 0){\n\n t1->flags[(y+1) * t1->stride + x+1] |= JPEG2000_T1_SGN;\n\n t1->data[(y) * t1->stride + x] = -t1->data[(y) * t1->stride + x];\n\n }\n\n max = FFMAX(max, t1->data[(y) * t1->stride + x]);\n\n }\n\n }\n\n\n\n if (max == 0){\n\n cblk->nonzerobits = 0;\n\n bpno = 0;\n\n } else{\n\n cblk->nonzerobits = av_log2(max) + 1 - NMSEDEC_FRACBITS;\n\n bpno = cblk->nonzerobits - 1;\n\n }\n\n\n\n ff_mqc_initenc(&t1->mqc, cblk->data);\n\n\n\n for (passno = 0; bpno >= 0; passno++){\n\n nmsedec=0;\n\n\n\n switch(pass_t){\n\n case 0: encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno);\n\n break;\n\n case 1: encode_refpass(t1, width, height, &nmsedec, bpno);\n\n break;\n\n case 2: encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno);\n\n break;\n\n }\n\n\n\n cblk->passes[passno].rate = ff_mqc_flush_to(&t1->mqc, cblk->passes[passno].flushed, &cblk->passes[passno].flushed_len);\n\n wmsedec += (int64_t)nmsedec << (2*bpno);\n\n cblk->passes[passno].disto = wmsedec;\n\n\n\n if (++pass_t == 3){\n\n pass_t = 0;\n\n bpno--;\n\n }\n\n }\n\n cblk->npasses = passno;\n\n cblk->ninclpasses = passno;\n\n\n\n cblk->passes[passno-1].rate = ff_mqc_flush_to(&t1->mqc, cblk->passes[passno-1].flushed, &cblk->passes[passno-1].flushed_len);\n\n}\n", + "output": "1", + "index": 1460 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void memory_dump(int count, int format, int wsize,\n\n target_phys_addr_t addr, int is_physical)\n\n{\n\n CPUState *env;\n\n int nb_per_line, l, line_size, i, max_digits, len;\n\n uint8_t buf[16];\n\n uint64_t v;\n\n\n\n if (format == 'i') {\n\n int flags;\n\n flags = 0;\n\n env = mon_get_cpu();\n\n if (!env && !is_physical)\n\n return;\n\n#ifdef TARGET_I386\n\n if (wsize == 2) {\n\n flags = 1;\n\n } else if (wsize == 4) {\n\n flags = 0;\n\n } else {\n\n /* as default we use the current CS size */\n\n flags = 0;\n\n if (env) {\n\n#ifdef TARGET_X86_64\n\n if ((env->efer & MSR_EFER_LMA) &&\n\n (env->segs[R_CS].flags & DESC_L_MASK))\n\n flags = 2;\n\n else\n\n#endif\n\n if (!(env->segs[R_CS].flags & DESC_B_MASK))\n\n flags = 1;\n\n }\n\n }\n\n#endif\n\n monitor_disas(env, addr, count, is_physical, flags);\n\n return;\n\n }\n\n\n\n len = wsize * count;\n\n if (wsize == 1)\n\n line_size = 8;\n\n else\n\n line_size = 16;\n\n nb_per_line = line_size / wsize;\n\n max_digits = 0;\n\n\n\n switch(format) {\n\n case 'o':\n\n max_digits = (wsize * 8 + 2) / 3;\n\n break;\n\n default:\n\n case 'x':\n\n max_digits = (wsize * 8) / 4;\n\n break;\n\n case 'u':\n\n case 'd':\n\n max_digits = (wsize * 8 * 10 + 32) / 33;\n\n break;\n\n case 'c':\n\n wsize = 1;\n\n break;\n\n }\n\n\n\n while (len > 0) {\n\n if (is_physical)\n\n term_printf(TARGET_FMT_plx \":\", addr);\n\n else\n\n term_printf(TARGET_FMT_lx \":\", (target_ulong)addr);\n\n l = len;\n\n if (l > line_size)\n\n l = line_size;\n\n if (is_physical) {\n\n cpu_physical_memory_rw(addr, buf, l, 0);\n\n } else {\n\n env = mon_get_cpu();\n\n if (!env)\n\n break;\n\n cpu_memory_rw_debug(env, addr, buf, l, 0);\n\n }\n\n i = 0;\n\n while (i < l) {\n\n switch(wsize) {\n\n default:\n\n case 1:\n\n v = ldub_raw(buf + i);\n\n break;\n\n case 2:\n\n v = lduw_raw(buf + i);\n\n break;\n\n case 4:\n\n v = (uint32_t)ldl_raw(buf + i);\n\n break;\n\n case 8:\n\n v = ldq_raw(buf + i);\n\n break;\n\n }\n\n term_printf(\" \");\n\n switch(format) {\n\n case 'o':\n\n term_printf(\"%#*\" PRIo64, max_digits, v);\n\n break;\n\n case 'x':\n\n term_printf(\"0x%0*\" PRIx64, max_digits, v);\n\n break;\n\n case 'u':\n\n term_printf(\"%*\" PRIu64, max_digits, v);\n\n break;\n\n case 'd':\n\n term_printf(\"%*\" PRId64, max_digits, v);\n\n break;\n\n case 'c':\n\n term_printc(v);\n\n break;\n\n }\n\n i += wsize;\n\n }\n\n term_printf(\"\\n\");\n\n addr += l;\n\n len -= l;\n\n }\n\n}\n", + "output": "0", + "index": 8956 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int mxf_read_generic_descriptor(MXFDescriptor *descriptor, ByteIOContext *pb, int tag, int size, UID uid)\n\n{\n\n switch(tag) {\n\n case 0x3F01:\n\n descriptor->sub_descriptors_count = get_be32(pb);\n\n if (descriptor->sub_descriptors_count >= UINT_MAX / sizeof(UID))\n\n return -1;\n\n descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID));\n\n if (!descriptor->sub_descriptors_refs)\n\n return -1;\n\n url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */\n\n get_buffer(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID));\n\n break;\n\n case 0x3004:\n\n get_buffer(pb, descriptor->essence_container_ul, 16);\n\n break;\n\n case 0x3006:\n\n descriptor->linked_track_id = get_be32(pb);\n\n break;\n\n case 0x3201: /* PictureEssenceCoding */\n\n get_buffer(pb, descriptor->essence_codec_ul, 16);\n\n break;\n\n case 0x3203:\n\n descriptor->width = get_be32(pb);\n\n break;\n\n case 0x3202:\n\n descriptor->height = get_be32(pb);\n\n break;\n\n case 0x320E:\n\n descriptor->aspect_ratio.num = get_be32(pb);\n\n descriptor->aspect_ratio.den = get_be32(pb);\n\n break;\n\n case 0x3D03:\n\n descriptor->sample_rate.num = get_be32(pb);\n\n descriptor->sample_rate.den = get_be32(pb);\n\n break;\n\n case 0x3D06: /* SoundEssenceCompression */\n\n get_buffer(pb, descriptor->essence_codec_ul, 16);\n\n break;\n\n case 0x3D07:\n\n descriptor->channels = get_be32(pb);\n\n break;\n\n case 0x3D01:\n\n descriptor->bits_per_sample = get_be32(pb);\n\n break;\n\n case 0x3401:\n\n mxf_read_pixel_layout(pb, descriptor);\n\n break;\n\n default:\n\n /* Private uid used by SONY C0023S01.mxf */\n\n if (IS_KLV_KEY(uid, mxf_sony_mpeg4_extradata)) {\n\n descriptor->extradata = av_malloc(size);\n\n if (!descriptor->extradata)\n\n return -1;\n\n descriptor->extradata_size = size;\n\n get_buffer(pb, descriptor->extradata, size);\n\n }\n\n break;\n\n }\n\n return 0;\n\n}\n", + "output": "1", + "index": 2020 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void test_misc(void)\n\n{\n\n char table[256];\n\n long res, i;\n\n\n\n for(i=0;i<256;i++) table[i] = 256 - i;\n\n res = 0x12345678;\n\n asm (\"xlat\" : \"=a\" (res) : \"b\" (table), \"0\" (res));\n\n printf(\"xlat: EAX=\" FMTLX \"\\n\", res);\n\n\n\n#if defined(__x86_64__)\n\n#if 0\n\n {\n\n /* XXX: see if Intel Core2 and AMD64 behavior really\n\n differ. Here we implemented the Intel way which is not\n\n compatible yet with QEMU. */\n\n static struct __attribute__((packed)) {\n\n uint64_t offset;\n\n uint16_t seg;\n\n } desc;\n\n long cs_sel;\n\n\n\n asm volatile (\"mov %%cs, %0\" : \"=r\" (cs_sel));\n\n\n\n asm volatile (\"push %1\\n\"\n\n \"call func_lret\\n\"\n\n : \"=a\" (res)\n\n : \"r\" (cs_sel) : \"memory\", \"cc\");\n\n printf(\"func_lret=\" FMTLX \"\\n\", res);\n\n\n\n desc.offset = (long)&func_lret;\n\n desc.seg = cs_sel;\n\n\n\n asm volatile (\"xor %%rax, %%rax\\n\"\n\n \"rex64 lcall *(%%rcx)\\n\"\n\n : \"=a\" (res)\n\n : \"c\" (&desc)\n\n : \"memory\", \"cc\");\n\n printf(\"func_lret2=\" FMTLX \"\\n\", res);\n\n\n\n asm volatile (\"push %2\\n\"\n\n \"mov $ 1f, %%rax\\n\"\n\n \"push %%rax\\n\"\n\n \"rex64 ljmp *(%%rcx)\\n\"\n\n \"1:\\n\"\n\n : \"=a\" (res)\n\n : \"c\" (&desc), \"b\" (cs_sel)\n\n : \"memory\", \"cc\");\n\n printf(\"func_lret3=\" FMTLX \"\\n\", res);\n\n }\n\n#endif\n\n#else\n\n asm volatile (\"push %%cs ; call %1\"\n\n : \"=a\" (res)\n\n : \"m\" (func_lret): \"memory\", \"cc\");\n\n printf(\"func_lret=\" FMTLX \"\\n\", res);\n\n\n\n asm volatile (\"pushf ; push %%cs ; call %1\"\n\n : \"=a\" (res)\n\n : \"m\" (func_iret): \"memory\", \"cc\");\n\n printf(\"func_iret=\" FMTLX \"\\n\", res);\n\n#endif\n\n\n\n#if defined(__x86_64__)\n\n /* specific popl test */\n\n asm volatile (\"push $12345432 ; push $0x9abcdef ; pop (%%rsp) ; pop %0\"\n\n : \"=g\" (res));\n\n printf(\"popl esp=\" FMTLX \"\\n\", res);\n\n#else\n\n /* specific popl test */\n\n asm volatile (\"pushl $12345432 ; pushl $0x9abcdef ; popl (%%esp) ; popl %0\"\n\n : \"=g\" (res));\n\n printf(\"popl esp=\" FMTLX \"\\n\", res);\n\n\n\n /* specific popw test */\n\n asm volatile (\"pushl $12345432 ; pushl $0x9abcdef ; popw (%%esp) ; addl $2, %%esp ; popl %0\"\n\n : \"=g\" (res));\n\n printf(\"popw esp=\" FMTLX \"\\n\", res);\n\n#endif\n\n}\n", + "output": "0", + "index": 4442 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int get_cookies(HTTPContext *s, char **cookies, const char *path,\n\n const char *domain)\n\n{\n\n // cookie strings will look like Set-Cookie header field values. Multiple\n\n // Set-Cookie fields will result in multiple values delimited by a newline\n\n int ret = 0;\n\n char *next, *cookie, *set_cookies = av_strdup(s->cookies), *cset_cookies = set_cookies;\n\n\n\n if (!set_cookies) return AVERROR(EINVAL);\n\n\n\n *cookies = NULL;\n\n while ((cookie = av_strtok(set_cookies, \"\\n\", &next))) {\n\n int domain_offset = 0;\n\n char *param, *next_param, *cdomain = NULL, *cpath = NULL, *cvalue = NULL;\n\n set_cookies = NULL;\n\n\n\n while ((param = av_strtok(cookie, \"; \", &next_param))) {\n\n cookie = NULL;\n\n if (!av_strncasecmp(\"path=\", param, 5)) {\n\n\n cpath = av_strdup(¶m[5]);\n\n } else if (!av_strncasecmp(\"domain=\", param, 7)) {\n\n\n cdomain = av_strdup(¶m[7]);\n\n } else if (!av_strncasecmp(\"secure\", param, 6) ||\n\n !av_strncasecmp(\"comment\", param, 7) ||\n\n !av_strncasecmp(\"max-age\", param, 7) ||\n\n !av_strncasecmp(\"version\", param, 7)) {\n\n // ignore Comment, Max-Age, Secure and Version\n\n } else {\n\n av_free(cvalue);\n\n cvalue = av_strdup(param);\n\n }\n\n }\n\n\n\n // ensure all of the necessary values are valid\n\n if (!cdomain || !cpath || !cvalue) {\n\n av_log(s, AV_LOG_WARNING,\n\n \"Invalid cookie found, no value, path or domain specified\\n\");\n\n goto done_cookie;\n\n }\n\n\n\n // check if the request path matches the cookie path\n\n if (av_strncasecmp(path, cpath, strlen(cpath)))\n\n goto done_cookie;\n\n\n\n // the domain should be at least the size of our cookie domain\n\n domain_offset = strlen(domain) - strlen(cdomain);\n\n if (domain_offset < 0)\n\n goto done_cookie;\n\n\n\n // match the cookie domain\n\n if (av_strcasecmp(&domain[domain_offset], cdomain))\n\n goto done_cookie;\n\n\n\n // cookie parameters match, so copy the value\n\n if (!*cookies) {\n\n if (!(*cookies = av_strdup(cvalue))) {\n\n ret = AVERROR(ENOMEM);\n\n goto done_cookie;\n\n }\n\n } else {\n\n char *tmp = *cookies;\n\n size_t str_size = strlen(cvalue) + strlen(*cookies) + 3;\n\n if (!(*cookies = av_malloc(str_size))) {\n\n ret = AVERROR(ENOMEM);\n\n goto done_cookie;\n\n }\n\n snprintf(*cookies, str_size, \"%s; %s\", tmp, cvalue);\n\n av_free(tmp);\n\n }\n\n\n\n done_cookie:\n\n\n\n av_free(cvalue);\n\n if (ret < 0) {\n\n if (*cookies) av_freep(cookies);\n\n av_free(cset_cookies);\n\n return ret;\n\n }\n\n }\n\n\n\n av_free(cset_cookies);\n\n\n\n return 0;\n\n}", + "output": "1", + "index": 12244 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int coroutine_fn do_perform_cow(BlockDriverState *bs,\n\n uint64_t src_cluster_offset,\n\n uint64_t cluster_offset,\n\n int offset_in_cluster,\n\n int bytes)\n\n{\n\n BDRVQcow2State *s = bs->opaque;\n\n QEMUIOVector qiov;\n\n struct iovec iov;\n\n int ret;\n\n\n\n iov.iov_len = bytes;\n\n iov.iov_base = qemu_try_blockalign(bs, iov.iov_len);\n\n if (iov.iov_base == NULL) {\n\n return -ENOMEM;\n\n }\n\n\n\n qemu_iovec_init_external(&qiov, &iov, 1);\n\n\n\n BLKDBG_EVENT(bs->file, BLKDBG_COW_READ);\n\n\n\n if (!bs->drv) {\n\n ret = -ENOMEDIUM;\n\n goto out;\n\n }\n\n\n\n /* Call .bdrv_co_readv() directly instead of using the public block-layer\n\n * interface. This avoids double I/O throttling and request tracking,\n\n * which can lead to deadlock when block layer copy-on-read is enabled.\n\n */\n\n ret = bs->drv->bdrv_co_preadv(bs, src_cluster_offset + offset_in_cluster,\n\n bytes, &qiov, 0);\n\n if (ret < 0) {\n\n goto out;\n\n }\n\n\n\n if (bs->encrypted) {\n\n Error *err = NULL;\n\n int64_t sector = (cluster_offset + offset_in_cluster)\n\n >> BDRV_SECTOR_BITS;\n\n assert(s->cipher);\n\n assert((offset_in_cluster & ~BDRV_SECTOR_MASK) == 0);\n\n assert((bytes & ~BDRV_SECTOR_MASK) == 0);\n\n if (qcow2_encrypt_sectors(s, sector, iov.iov_base, iov.iov_base,\n\n bytes >> BDRV_SECTOR_BITS, true, &err) < 0) {\n\n ret = -EIO;\n\n error_free(err);\n\n goto out;\n\n }\n\n }\n\n\n\n ret = qcow2_pre_write_overlap_check(bs, 0,\n\n cluster_offset + offset_in_cluster, bytes);\n\n if (ret < 0) {\n\n goto out;\n\n }\n\n\n\n BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE);\n\n ret = bdrv_co_pwritev(bs->file->bs, cluster_offset + offset_in_cluster,\n\n bytes, &qiov, 0);\n\n if (ret < 0) {\n\n goto out;\n\n }\n\n\n\n ret = 0;\n\nout:\n\n qemu_vfree(iov.iov_base);\n\n return ret;\n\n}\n", + "output": "0", + "index": 15423 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "POWERPC_FAMILY(POWER7P)(ObjectClass *oc, void *data)\n\n{\n\n DeviceClass *dc = DEVICE_CLASS(oc);\n\n PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);\n\n\n\n dc->fw_name = \"PowerPC,POWER7+\";\n\n dc->desc = \"POWER7+\";\n\n dc->props = powerpc_servercpu_properties;\n\n pcc->pvr_match = ppc_pvr_match_power7;\n\n pcc->pcr_mask = PCR_COMPAT_2_05 | PCR_COMPAT_2_06;\n\n pcc->init_proc = init_proc_POWER7;\n\n pcc->check_pow = check_pow_nocheck;\n\n pcc->insns_flags = PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB |\n\n PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES |\n\n PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE |\n\n PPC_FLOAT_FRSQRTES |\n\n PPC_FLOAT_STFIWX |\n\n PPC_FLOAT_EXT |\n\n PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ |\n\n PPC_MEM_SYNC | PPC_MEM_EIEIO |\n\n PPC_MEM_TLBIE | PPC_MEM_TLBSYNC |\n\n PPC_64B | PPC_ALTIVEC |\n\n PPC_SEGMENT_64B | PPC_SLBI |\n\n PPC_POPCNTB | PPC_POPCNTWD;\n\n pcc->insns_flags2 = PPC2_VSX | PPC2_DFP | PPC2_DBRX | PPC2_ISA205 |\n\n PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |\n\n PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |\n\n PPC2_FP_TST_ISA206;\n\n pcc->msr_mask = (1ull << MSR_SF) |\n\n (1ull << MSR_VR) |\n\n (1ull << MSR_VSX) |\n\n (1ull << MSR_EE) |\n\n (1ull << MSR_PR) |\n\n (1ull << MSR_FP) |\n\n (1ull << MSR_ME) |\n\n (1ull << MSR_FE0) |\n\n (1ull << MSR_SE) |\n\n (1ull << MSR_DE) |\n\n (1ull << MSR_FE1) |\n\n (1ull << MSR_IR) |\n\n (1ull << MSR_DR) |\n\n (1ull << MSR_PMM) |\n\n (1ull << MSR_RI) |\n\n (1ull << MSR_LE);\n\n pcc->mmu_model = POWERPC_MMU_2_06;\n\n#if defined(CONFIG_SOFTMMU)\n\n pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault;\n\n#endif\n\n pcc->excp_model = POWERPC_EXCP_POWER7;\n\n pcc->bus_model = PPC_FLAGS_INPUT_POWER7;\n\n pcc->bfd_mach = bfd_mach_ppc64;\n\n pcc->flags = POWERPC_FLAG_VRE | POWERPC_FLAG_SE |\n\n POWERPC_FLAG_BE | POWERPC_FLAG_PMM |\n\n POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_CFAR |\n\n POWERPC_FLAG_VSX;\n\n pcc->l1_dcache_size = 0x8000;\n\n pcc->l1_icache_size = 0x8000;\n\n pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_lpcr;\n\n}\n", + "output": "0", + "index": 6746 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_frame_headers(Indeo3DecodeContext *ctx, AVCodecContext *avctx,\n\n const uint8_t *buf, int buf_size)\n\n{\n\n const uint8_t *buf_ptr = buf, *bs_hdr;\n\n uint32_t frame_num, word2, check_sum, data_size;\n\n uint32_t y_offset, u_offset, v_offset, starts[3], ends[3];\n\n uint16_t height, width;\n\n int i, j;\n\n\n\n /* parse and check the OS header */\n\n frame_num = bytestream_get_le32(&buf_ptr);\n\n word2 = bytestream_get_le32(&buf_ptr);\n\n check_sum = bytestream_get_le32(&buf_ptr);\n\n data_size = bytestream_get_le32(&buf_ptr);\n\n\n\n if ((frame_num ^ word2 ^ data_size ^ OS_HDR_ID) != check_sum) {\n\n av_log(avctx, AV_LOG_ERROR, \"OS header checksum mismatch!\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n /* parse the bitstream header */\n\n bs_hdr = buf_ptr;\n\n\n\n if (bytestream_get_le16(&buf_ptr) != 32) {\n\n av_log(avctx, AV_LOG_ERROR, \"Unsupported codec version!\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n ctx->frame_num = frame_num;\n\n ctx->frame_flags = bytestream_get_le16(&buf_ptr);\n\n ctx->data_size = (bytestream_get_le32(&buf_ptr) + 7) >> 3;\n\n ctx->cb_offset = *buf_ptr++;\n\n\n\n if (ctx->data_size == 16)\n\n return 4;\n\n if (ctx->data_size > buf_size)\n\n ctx->data_size = buf_size;\n\n\n\n buf_ptr += 3; // skip reserved byte and checksum\n\n\n\n /* check frame dimensions */\n\n height = bytestream_get_le16(&buf_ptr);\n\n width = bytestream_get_le16(&buf_ptr);\n\n if (av_image_check_size(width, height, 0, avctx))\n\n return AVERROR_INVALIDDATA;\n\n\n\n if (width != ctx->width || height != ctx->height) {\n\n av_dlog(avctx, \"Frame dimensions changed!\\n\");\n\n\n\n ctx->width = width;\n\n ctx->height = height;\n\n\n\n free_frame_buffers(ctx);\n\n allocate_frame_buffers(ctx, avctx);\n\n avcodec_set_dimensions(avctx, width, height);\n\n }\n\n\n\n y_offset = bytestream_get_le32(&buf_ptr);\n\n v_offset = bytestream_get_le32(&buf_ptr);\n\n u_offset = bytestream_get_le32(&buf_ptr);\n\n\n\n /* unfortunately there is no common order of planes in the buffer */\n\n /* so we use that sorting algo for determining planes data sizes */\n\n starts[0] = y_offset;\n\n starts[1] = v_offset;\n\n starts[2] = u_offset;\n\n\n\n for (j = 0; j < 3; j++) {\n\n ends[j] = ctx->data_size;\n\n for (i = 2; i >= 0; i--)\n\n if (starts[i] < ends[j] && starts[i] > starts[j])\n\n ends[j] = starts[i];\n\n }\n\n\n\n ctx->y_data_size = ends[0] - starts[0];\n\n ctx->v_data_size = ends[1] - starts[1];\n\n ctx->u_data_size = ends[2] - starts[2];\n\n if (FFMAX3(y_offset, v_offset, u_offset) >= ctx->data_size - 16 ||\n\n FFMIN3(ctx->y_data_size, ctx->v_data_size, ctx->u_data_size) <= 0) {\n\n av_log(avctx, AV_LOG_ERROR, \"One of the y/u/v offsets is invalid\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n ctx->y_data_ptr = bs_hdr + y_offset;\n\n ctx->v_data_ptr = bs_hdr + v_offset;\n\n ctx->u_data_ptr = bs_hdr + u_offset;\n\n ctx->alt_quant = buf_ptr + sizeof(uint32_t);\n\n\n\n if (ctx->data_size == 16) {\n\n av_log(avctx, AV_LOG_DEBUG, \"Sync frame encountered!\\n\");\n\n return 16;\n\n }\n\n\n\n if (ctx->frame_flags & BS_8BIT_PEL) {\n\n av_log_ask_for_sample(avctx, \"8-bit pixel format\\n\");\n\n return AVERROR_PATCHWELCOME;\n\n }\n\n\n\n if (ctx->frame_flags & BS_MV_X_HALF || ctx->frame_flags & BS_MV_Y_HALF) {\n\n av_log_ask_for_sample(avctx, \"halfpel motion vectors\\n\");\n\n return AVERROR_PATCHWELCOME;\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 21139 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void init_proc_power5plus(CPUPPCState *env)\n\n{\n\n gen_spr_ne_601(env);\n\n gen_spr_7xx(env);\n\n /* Time base */\n\n gen_tbl(env);\n\n /* Hardware implementation registers */\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_HID0, \"HID0\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_clear,\n\n 0x60000000);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_HID1, \"HID1\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_750FX_HID2, \"HID2\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_970_HID5, \"HID5\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n POWERPC970_HID5_INIT);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_L2CR, \"L2CR\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, NULL,\n\n 0x00000000);\n\n /* Memory management */\n\n /* XXX: not correct */\n\n gen_low_BATs(env);\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_MMUCFG, \"MMUCFG\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, SPR_NOACCESS,\n\n 0x00000000); /* TOFIX */\n\n /* XXX : not implemented */\n\n spr_register(env, SPR_MMUCSR0, \"MMUCSR0\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000); /* TOFIX */\n\n spr_register(env, SPR_HIOR, \"SPR_HIOR\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_hior, &spr_write_hior,\n\n 0x00000000);\n\n spr_register(env, SPR_CTRL, \"SPR_CTRL\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n spr_register(env, SPR_UCTRL, \"SPR_UCTRL\",\n\n SPR_NOACCESS, SPR_NOACCESS,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n spr_register(env, SPR_VRSAVE, \"SPR_VRSAVE\",\n\n &spr_read_generic, &spr_write_generic,\n\n &spr_read_generic, &spr_write_generic,\n\n 0x00000000);\n\n#if !defined(CONFIG_USER_ONLY)\n\n env->slb_nr = 64;\n\n#endif\n\n init_excp_970(env);\n\n env->dcache_line_size = 128;\n\n env->icache_line_size = 128;\n\n /* Allocate hardware IRQ controller */\n\n ppc970_irq_init(env);\n\n /* Can't find information on what this should be on reset. This\n\n * value is the one used by 74xx processors. */\n\n vscr_init(env, 0x00010000);\n\n}\n", + "output": "1", + "index": 4760 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "soread(so)\n\n\tstruct socket *so;\n\n{\n\n\tint n, nn, lss, total;\n\n\tstruct sbuf *sb = &so->so_snd;\n\n\tint len = sb->sb_datalen - sb->sb_cc;\n\n\tstruct iovec iov[2];\n\n\tint mss = so->so_tcpcb->t_maxseg;\n\n\t\n\n\tDEBUG_CALL(\"soread\");\n\n\tDEBUG_ARG(\"so = %lx\", (long )so);\n\n\t\n\n\t/* \n\n\t * No need to check if there's enough room to read.\n\n\t * soread wouldn't have been called if there weren't\n\n\t */\n\n\t\n\n\tlen = sb->sb_datalen - sb->sb_cc;\n\n\t\n\n\tiov[0].iov_base = sb->sb_wptr;\n\n\tif (sb->sb_wptr < sb->sb_rptr) {\n\n\t\tiov[0].iov_len = sb->sb_rptr - sb->sb_wptr;\n\n\t\t/* Should never succeed, but... */\n\n\t\tif (iov[0].iov_len > len)\n\n\t\t iov[0].iov_len = len;\n\n\t\tif (iov[0].iov_len > mss)\n\n\t\t iov[0].iov_len -= iov[0].iov_len%mss;\n\n\t\tn = 1;\n\n\t} else {\n\n\t\tiov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_wptr;\n\n\t\t/* Should never succeed, but... */\n\n\t\tif (iov[0].iov_len > len) iov[0].iov_len = len;\n\n\t\tlen -= iov[0].iov_len;\n\n\t\tif (len) {\n\n\t\t\tiov[1].iov_base = sb->sb_data;\n\n\t\t\tiov[1].iov_len = sb->sb_rptr - sb->sb_data;\n\n\t\t\tif(iov[1].iov_len > len)\n\n\t\t\t iov[1].iov_len = len;\n\n\t\t\ttotal = iov[0].iov_len + iov[1].iov_len;\n\n\t\t\tif (total > mss) {\n\n\t\t\t\tlss = total%mss;\n\n\t\t\t\tif (iov[1].iov_len > lss) {\n\n\t\t\t\t\tiov[1].iov_len -= lss;\n\n\t\t\t\t\tn = 2;\n\n\t\t\t\t} else {\n\n\t\t\t\t\tlss -= iov[1].iov_len;\n\n\t\t\t\t\tiov[0].iov_len -= lss;\n\n\t\t\t\t\tn = 1;\n\n\t\t\t\t}\n\n\t\t\t} else\n\n\t\t\t\tn = 2;\n\n\t\t} else {\n\n\t\t\tif (iov[0].iov_len > mss)\n\n\t\t\t iov[0].iov_len -= iov[0].iov_len%mss;\n\n\t\t\tn = 1;\n\n\t\t}\n\n\t}\n\n\t\n\n#ifdef HAVE_READV\n\n\tnn = readv(so->s, (struct iovec *)iov, n);\n\n\tDEBUG_MISC((dfd, \" ... read nn = %d bytes\\n\", nn));\n\n#else\n\n\tnn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);\n\n#endif\t\n\n\tif (nn <= 0) {\n\n\t\tif (nn < 0 && (errno == EINTR || errno == EAGAIN))\n\n\t\t\treturn 0;\n\n\t\telse {\n\n\t\t\tDEBUG_MISC((dfd, \" --- soread() disconnected, nn = %d, errno = %d-%s\\n\", nn, errno,strerror(errno)));\n\n\t\t\tsofcantrcvmore(so);\n\n\t\t\ttcp_sockclosed(sototcpcb(so));\n\n\t\t\treturn -1;\n\n\t\t}\n\n\t}\n\n\t\n\n#ifndef HAVE_READV\n\n\t/*\n\n\t * If there was no error, try and read the second time round\n\n\t * We read again if n = 2 (ie, there's another part of the buffer)\n\n\t * and we read as much as we could in the first read\n\n\t * We don't test for <= 0 this time, because there legitimately\n\n\t * might not be any more data (since the socket is non-blocking),\n\n\t * a close will be detected on next iteration.\n\n\t * A return of -1 wont (shouldn't) happen, since it didn't happen above\n\n\t */\n\n\tif (n == 2 && nn == iov[0].iov_len)\n\n\t nn += recv(so->s, iov[1].iov_base, iov[1].iov_len,0);\n\n\t\n\n\tDEBUG_MISC((dfd, \" ... read nn = %d bytes\\n\", nn));\n\n#endif\n\n\t\n\n\t/* Update fields */\n\n\tsb->sb_cc += nn;\n\n\tsb->sb_wptr += nn;\n\n\tif (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen))\n\n\t\tsb->sb_wptr -= sb->sb_datalen;\n\n\treturn nn;\n\n}\n", + "output": "0", + "index": 4462 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static target_ulong h_register_logical_lan(CPUPPCState *env,\n\n sPAPREnvironment *spapr,\n\n target_ulong opcode,\n\n target_ulong *args)\n\n{\n\n target_ulong reg = args[0];\n\n target_ulong buf_list = args[1];\n\n target_ulong rec_queue = args[2];\n\n target_ulong filter_list = args[3];\n\n VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);\n\n VIOsPAPRVLANDevice *dev = (VIOsPAPRVLANDevice *)sdev;\n\n vlan_bd_t filter_list_bd;\n\n\n\n if (!dev) {\n\n return H_PARAMETER;\n\n }\n\n\n\n if (dev->isopen) {\n\n hcall_dprintf(\"H_REGISTER_LOGICAL_LAN called twice without \"\n\n \"H_FREE_LOGICAL_LAN\\n\");\n\n return H_RESOURCE;\n\n }\n\n\n\n if (check_bd(dev, VLAN_VALID_BD(buf_list, SPAPR_VIO_TCE_PAGE_SIZE),\n\n SPAPR_VIO_TCE_PAGE_SIZE) < 0) {\n\n hcall_dprintf(\"Bad buf_list 0x\" TARGET_FMT_lx \"\\n\", buf_list);\n\n return H_PARAMETER;\n\n }\n\n\n\n filter_list_bd = VLAN_VALID_BD(filter_list, SPAPR_VIO_TCE_PAGE_SIZE);\n\n if (check_bd(dev, filter_list_bd, SPAPR_VIO_TCE_PAGE_SIZE) < 0) {\n\n hcall_dprintf(\"Bad filter_list 0x\" TARGET_FMT_lx \"\\n\", filter_list);\n\n return H_PARAMETER;\n\n }\n\n\n\n if (!(rec_queue & VLAN_BD_VALID)\n\n || (check_bd(dev, rec_queue, VLAN_RQ_ALIGNMENT) < 0)) {\n\n hcall_dprintf(\"Bad receive queue\\n\");\n\n return H_PARAMETER;\n\n }\n\n\n\n dev->buf_list = buf_list;\n\n sdev->signal_state = 0;\n\n\n\n rec_queue &= ~VLAN_BD_TOGGLE;\n\n\n\n /* Initialize the buffer list */\n\n stq_tce(sdev, buf_list, rec_queue);\n\n stq_tce(sdev, buf_list + 8, filter_list_bd);\n\n spapr_tce_dma_zero(sdev, buf_list + VLAN_RX_BDS_OFF,\n\n SPAPR_VIO_TCE_PAGE_SIZE - VLAN_RX_BDS_OFF);\n\n dev->add_buf_ptr = VLAN_RX_BDS_OFF - 8;\n\n dev->use_buf_ptr = VLAN_RX_BDS_OFF - 8;\n\n dev->rx_bufs = 0;\n\n dev->rxq_ptr = 0;\n\n\n\n /* Initialize the receive queue */\n\n spapr_tce_dma_zero(sdev, VLAN_BD_ADDR(rec_queue), VLAN_BD_LEN(rec_queue));\n\n\n\n dev->isopen = 1;\n\n return H_SUCCESS;\n\n}\n", + "output": "1", + "index": 3501 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int tta_read_header(AVFormatContext *s)\n\n{\n\n TTAContext *c = s->priv_data;\n\n AVStream *st;\n\n int i, channels, bps, samplerate;\n\n uint64_t framepos, start_offset;\n\n uint32_t nb_samples, crc;\n\n\n\n ff_id3v1_read(s);\n\n\n\n start_offset = avio_tell(s->pb);\n\n ffio_init_checksum(s->pb, tta_check_crc, UINT32_MAX);\n\n if (avio_rl32(s->pb) != AV_RL32(\"TTA1\"))\n\n return AVERROR_INVALIDDATA;\n\n\n\n avio_skip(s->pb, 2); // FIXME: flags\n\n channels = avio_rl16(s->pb);\n\n bps = avio_rl16(s->pb);\n\n samplerate = avio_rl32(s->pb);\n\n if(samplerate <= 0 || samplerate > 1000000){\n\n av_log(s, AV_LOG_ERROR, \"nonsense samplerate\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n nb_samples = avio_rl32(s->pb);\n\n if (!nb_samples) {\n\n av_log(s, AV_LOG_ERROR, \"invalid number of samples\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n crc = ffio_get_checksum(s->pb) ^ UINT32_MAX;\n\n if (crc != avio_rl32(s->pb)) {\n\n av_log(s, AV_LOG_ERROR, \"Header CRC error\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n c->frame_size = samplerate * 256 / 245;\n\n c->last_frame_size = nb_samples % c->frame_size;\n\n if (!c->last_frame_size)\n\n c->last_frame_size = c->frame_size;\n\n c->totalframes = nb_samples / c->frame_size + (c->last_frame_size < c->frame_size);\n\n c->currentframe = 0;\n\n\n\n if(c->totalframes >= UINT_MAX/sizeof(uint32_t) || c->totalframes <= 0){\n\n av_log(s, AV_LOG_ERROR, \"totalframes %d invalid\\n\", c->totalframes);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n st = avformat_new_stream(s, NULL);\n\n if (!st)\n\n return AVERROR(ENOMEM);\n\n\n\n avpriv_set_pts_info(st, 64, 1, samplerate);\n\n st->start_time = 0;\n\n st->duration = nb_samples;\n\n\n\n framepos = avio_tell(s->pb) + 4*c->totalframes + 4;\n\n\n\n if (ff_alloc_extradata(st->codec, avio_tell(s->pb) - start_offset))\n\n return AVERROR(ENOMEM);\n\n\n\n avio_seek(s->pb, start_offset, SEEK_SET);\n\n avio_read(s->pb, st->codec->extradata, st->codec->extradata_size);\n\n\n\n ffio_init_checksum(s->pb, tta_check_crc, UINT32_MAX);\n\n for (i = 0; i < c->totalframes; i++) {\n\n uint32_t size = avio_rl32(s->pb);\n\n av_add_index_entry(st, framepos, i * c->frame_size, size, 0,\n\n AVINDEX_KEYFRAME);\n\n framepos += size;\n\n }\n\n crc = ffio_get_checksum(s->pb) ^ UINT32_MAX;\n\n if (crc != avio_rl32(s->pb)) {\n\n av_log(s, AV_LOG_ERROR, \"Seek table CRC error\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n st->codec->codec_id = AV_CODEC_ID_TTA;\n\n st->codec->channels = channels;\n\n st->codec->sample_rate = samplerate;\n\n st->codec->bits_per_coded_sample = bps;\n\n\n\n if (s->pb->seekable) {\n\n int64_t pos = avio_tell(s->pb);\n\n ff_ape_parse_tag(s);\n\n avio_seek(s->pb, pos, SEEK_SET);\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 16679 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int discard_single_l2(BlockDriverState *bs, uint64_t offset,\n\n uint64_t nb_clusters, enum qcow2_discard_type type,\n\n bool full_discard)\n\n{\n\n BDRVQcow2State *s = bs->opaque;\n\n uint64_t *l2_table;\n\n int l2_index;\n\n int ret;\n\n int i;\n\n\n\n ret = get_cluster_table(bs, offset, &l2_table, &l2_index);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n /* Limit nb_clusters to one L2 table */\n\n nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);\n\n assert(nb_clusters <= INT_MAX);\n\n\n\n for (i = 0; i < nb_clusters; i++) {\n\n uint64_t old_l2_entry;\n\n\n\n old_l2_entry = be64_to_cpu(l2_table[l2_index + i]);\n\n\n\n /*\n\n * If full_discard is false, make sure that a discarded area reads back\n\n * as zeroes for v3 images (we cannot do it for v2 without actually\n\n * writing a zero-filled buffer). We can skip the operation if the\n\n * cluster is already marked as zero, or if it's unallocated and we\n\n * don't have a backing file.\n\n *\n\n * TODO We might want to use bdrv_get_block_status(bs) here, but we're\n\n * holding s->lock, so that doesn't work today.\n\n *\n\n * If full_discard is true, the sector should not read back as zeroes,\n\n * but rather fall through to the backing file.\n\n */\n\n switch (qcow2_get_cluster_type(old_l2_entry)) {\n\n case QCOW2_CLUSTER_UNALLOCATED:\n\n if (full_discard || !bs->backing) {\n\n continue;\n\n }\n\n break;\n\n\n\n case QCOW2_CLUSTER_ZERO_PLAIN:\n\n if (!full_discard) {\n\n continue;\n\n }\n\n break;\n\n\n\n case QCOW2_CLUSTER_ZERO_ALLOC:\n\n case QCOW2_CLUSTER_NORMAL:\n\n case QCOW2_CLUSTER_COMPRESSED:\n\n break;\n\n\n\n default:\n\n abort();\n\n }\n\n\n\n /* First remove L2 entries */\n\n qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache, l2_table);\n\n if (!full_discard && s->qcow_version >= 3) {\n\n l2_table[l2_index + i] = cpu_to_be64(QCOW_OFLAG_ZERO);\n\n } else {\n\n l2_table[l2_index + i] = cpu_to_be64(0);\n\n }\n\n\n\n /* Then decrease the refcount */\n\n qcow2_free_any_clusters(bs, old_l2_entry, 1, type);\n\n }\n\n\n\n qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table);\n\n\n\n return nb_clusters;\n\n}\n", + "output": "0", + "index": 10222 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_pre_estimate_p_frame_motion(MpegEncContext * s,\n\n int mb_x, int mb_y)\n\n{\n\n int mx, my, range, dmin;\n\n int xmin, ymin, xmax, ymax;\n\n int rel_xmin, rel_ymin, rel_xmax, rel_ymax;\n\n int pred_x=0, pred_y=0;\n\n int P[10][2];\n\n const int shift= 1+s->quarter_sample;\n\n uint16_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;\n\n const int mv_stride= s->mb_width + 2;\n\n const int xy= mb_x + 1 + (mb_y + 1)*mv_stride;\n\n \n\n assert(s->quarter_sample==0 || s->quarter_sample==1);\n\n\n\n s->me.pre_penalty_factor = get_penalty_factor(s, s->avctx->me_pre_cmp);\n\n\n\n get_limits(s, &range, &xmin, &ymin, &xmax, &ymax, s->f_code);\n\n rel_xmin= xmin - mb_x*16;\n\n rel_xmax= xmax - mb_x*16;\n\n rel_ymin= ymin - mb_y*16;\n\n rel_ymax= ymax - mb_y*16;\n\n s->me.skip=0;\n\n\n\n P_LEFT[0] = s->p_mv_table[xy + 1][0];\n\n P_LEFT[1] = s->p_mv_table[xy + 1][1];\n\n\n\n if(P_LEFT[0] < (rel_xmin<mb_height-1) {\n\n pred_x= P_LEFT[0];\n\n pred_y= P_LEFT[1];\n\n P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=\n\n P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME \n\n } else {\n\n P_TOP[0] = s->p_mv_table[xy + mv_stride ][0];\n\n P_TOP[1] = s->p_mv_table[xy + mv_stride ][1];\n\n P_TOPRIGHT[0] = s->p_mv_table[xy + mv_stride - 1][0];\n\n P_TOPRIGHT[1] = s->p_mv_table[xy + mv_stride - 1][1];\n\n if(P_TOP[1] < (rel_ymin< (rel_xmax<me.pre_motion_search(s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, \n\n &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty);\n\n\n\n s->p_mv_table[xy][0] = mx<p_mv_table[xy][1] = my< argc - 2) {\n\n return command_usage(&readv_cmd);\n\n }\n\n\n\n\n\n offset = cvtnum(argv[optind]);\n\n if (offset < 0) {\n\n printf(\"non-numeric length argument -- %s\\n\", argv[optind]);\n\n return 0;\n\n }\n\n optind++;\n\n\n\n if (offset & 0x1ff) {\n\n printf(\"offset %\" PRId64 \" is not sector aligned\\n\",\n\n offset);\n\n return 0;\n\n }\n\n\n\n nr_iov = argc - optind;\n\n buf = create_iovec(&qiov, &argv[optind], nr_iov, 0xab);\n\n if (buf == NULL) {\n\n return 0;\n\n }\n\n\n\n gettimeofday(&t1, NULL);\n\n cnt = do_aio_readv(&qiov, offset, &total);\n\n gettimeofday(&t2, NULL);\n\n\n\n if (cnt < 0) {\n\n printf(\"readv failed: %s\\n\", strerror(-cnt));\n\n goto out;\n\n }\n\n\n\n if (Pflag) {\n\n void *cmp_buf = malloc(qiov.size);\n\n memset(cmp_buf, pattern, qiov.size);\n\n if (memcmp(buf, cmp_buf, qiov.size)) {\n\n printf(\"Pattern verification failed at offset %\"\n\n PRId64 \", %zd bytes\\n\", offset, qiov.size);\n\n }\n\n free(cmp_buf);\n\n }\n\n\n\n if (qflag) {\n\n goto out;\n\n }\n\n\n\n if (vflag) {\n\n dump_buffer(buf, offset, qiov.size);\n\n }\n\n\n\n /* Finally, report back -- -C gives a parsable format */\n\n t2 = tsub(t2, t1);\n\n print_report(\"read\", &t2, offset, qiov.size, total, cnt, Cflag);\n\n\n\nout:\n\n qemu_io_free(buf);\n\n return 0;\n\n}\n", + "output": "0", + "index": 16067 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int av_dict_set(AVDictionary **pm, const char *key, const char *value,\n\n int flags)\n\n{\n\n AVDictionary *m = *pm;\n\n AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);\n\n char *oldval = NULL, *copy_key = NULL, *copy_value = NULL;\n\n\n\n if (flags & AV_DICT_DONT_STRDUP_KEY)\n\n copy_key = (void *)key;\n\n else\n\n copy_key = av_strdup(key);\n\n if (flags & AV_DICT_DONT_STRDUP_VAL)\n\n copy_value = (void *)value;\n\n else if (copy_key)\n\n copy_value = av_strdup(value);\n\n if (!m)\n\n m = *pm = av_mallocz(sizeof(*m));\n\n if (!m || (key && !copy_key) || (value && !copy_value))\n\n goto err_out;\n\n\n\n if (tag) {\n\n if (flags & AV_DICT_DONT_OVERWRITE) {\n\n av_free(copy_key);\n\n av_free(copy_value);\n\n return 0;\n\n }\n\n if (flags & AV_DICT_APPEND)\n\n oldval = tag->value;\n\n else\n\n av_free(tag->value);\n\n av_free(tag->key);\n\n *tag = m->elems[--m->count];\n\n } else {\n\n AVDictionaryEntry *tmp = av_realloc(m->elems,\n\n (m->count + 1) * sizeof(*m->elems));\n\n if (!tmp)\n\n goto err_out;\n\n m->elems = tmp;\n\n }\n\n if (copy_value) {\n\n m->elems[m->count].key = copy_key;\n\n m->elems[m->count].value = copy_value;\n\n if (oldval && flags & AV_DICT_APPEND) {\n\n size_t len = strlen(oldval) + strlen(copy_value) + 1;\n\n char *newval = av_mallocz(len);\n\n if (!newval)\n\n goto err_out;\n\n av_strlcat(newval, oldval, len);\n\n av_freep(&oldval);\n\n av_strlcat(newval, copy_value, len);\n\n m->elems[m->count].value = newval;\n\n av_freep(©_value);\n\n }\n\n m->count++;\n\n } else {\n\n av_freep(©_key);\n\n }\n\n if (!m->count) {\n\n av_freep(&m->elems);\n\n av_freep(pm);\n\n }\n\n\n\n return 0;\n\n\n\nerr_out:\n\n if (m && !m->count) {\n\n av_freep(&m->elems);\n\n av_freep(pm);\n\n }\n\n av_free(copy_key);\n\n av_free(copy_value);\n\n return AVERROR(ENOMEM);\n\n}\n", + "output": "0", + "index": 9885 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)\n{\n int i;\n GICState *s = KVM_ARM_GIC(dev);\n SysBusDevice *sbd = SYS_BUS_DEVICE(dev);\n KVMARMGICClass *kgc = KVM_ARM_GIC_GET_CLASS(s);\n Error *local_err = NULL;\n int ret;\n kgc->parent_realize(dev, &local_err);\n if (local_err) {\n error_propagate(errp, local_err);\n i = s->num_irq - GIC_INTERNAL;\n /* For the GIC, also expose incoming GPIO lines for PPIs for each CPU.\n * GPIO array layout is thus:\n * [0..N-1] SPIs\n * [N..N+31] PPIs for CPU 0\n * [N+32..N+63] PPIs for CPU 1\n * ...\n */\n i += (GIC_INTERNAL * s->num_cpu);\n qdev_init_gpio_in(dev, kvm_arm_gic_set_irq, i);\n /* We never use our outbound IRQ/FIQ lines but provide them so that\n * we maintain the same interface as the non-KVM GIC.\n */\n for (i = 0; i < s->num_cpu; i++) {\n sysbus_init_irq(sbd, &s->parent_irq[i]);\n for (i = 0; i < s->num_cpu; i++) {\n sysbus_init_irq(sbd, &s->parent_fiq[i]);\n /* Try to create the device via the device control API */\n s->dev_fd = -1;\n ret = kvm_create_device(kvm_state, KVM_DEV_TYPE_ARM_VGIC_V2, false);\n if (ret >= 0) {\n s->dev_fd = ret;\n } else if (ret != -ENODEV && ret != -ENOTSUP) {\n error_setg_errno(errp, -ret, \"error creating in-kernel VGIC\");\n if (kvm_gic_supports_attr(s, KVM_DEV_ARM_VGIC_GRP_NR_IRQS, 0)) {\n uint32_t numirqs = s->num_irq;\n kvm_gic_access(s, KVM_DEV_ARM_VGIC_GRP_NR_IRQS, 0, 0, &numirqs, 1);\n /* Tell the kernel to complete VGIC initialization now */\n if (kvm_gic_supports_attr(s, KVM_DEV_ARM_VGIC_GRP_CTRL,\n KVM_DEV_ARM_VGIC_CTRL_INIT)) {\n kvm_gic_access(s, KVM_DEV_ARM_VGIC_GRP_CTRL,\n KVM_DEV_ARM_VGIC_CTRL_INIT, 0, 0, 1);\n /* Distributor */\n memory_region_init_reservation(&s->iomem, OBJECT(s),\n \"kvm-gic_dist\", 0x1000);\n sysbus_init_mmio(sbd, &s->iomem);\n kvm_arm_register_device(&s->iomem,\n (KVM_ARM_DEVICE_VGIC_V2 << KVM_ARM_DEVICE_ID_SHIFT)\n | KVM_VGIC_V2_ADDR_TYPE_DIST,\n KVM_DEV_ARM_VGIC_GRP_ADDR,\n KVM_VGIC_V2_ADDR_TYPE_DIST,\n s->dev_fd);\n /* CPU interface for current core. Unlike arm_gic, we don't\n * provide the \"interface for core #N\" memory regions, because\n * cores with a VGIC don't have those.\n */\n memory_region_init_reservation(&s->cpuiomem[0], OBJECT(s),\n \"kvm-gic_cpu\", 0x1000);\n sysbus_init_mmio(sbd, &s->cpuiomem[0]);\n kvm_arm_register_device(&s->cpuiomem[0],\n (KVM_ARM_DEVICE_VGIC_V2 << KVM_ARM_DEVICE_ID_SHIFT)\n | KVM_VGIC_V2_ADDR_TYPE_CPU,\n KVM_DEV_ARM_VGIC_GRP_ADDR,\n KVM_VGIC_V2_ADDR_TYPE_CPU,\n s->dev_fd);", + "output": "1", + "index": 10912 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int pcm_decode_frame(AVCodecContext *avctx,\n\n void *data, int *data_size,\n\n uint8_t *buf, int buf_size)\n\n{\n\n PCMDecode *s = avctx->priv_data;\n\n int n;\n\n short *samples;\n\n uint8_t *src;\n\n\n\n samples = data;\n\n src = buf;\n\n\n\n if(buf_size > AVCODEC_MAX_AUDIO_FRAME_SIZE/2)\n\n buf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE/2;\n\n\n\n switch(avctx->codec->id) {\n\n case CODEC_ID_PCM_S32LE:\n\n decode_to16(4, 1, 0, &src, &samples, buf_size);\n\n break;\n\n case CODEC_ID_PCM_S32BE:\n\n decode_to16(4, 0, 0, &src, &samples, buf_size);\n\n break;\n\n case CODEC_ID_PCM_U32LE:\n\n decode_to16(4, 1, 1, &src, &samples, buf_size);\n\n break;\n\n case CODEC_ID_PCM_U32BE:\n\n decode_to16(4, 0, 1, &src, &samples, buf_size);\n\n break;\n\n case CODEC_ID_PCM_S24LE:\n\n decode_to16(3, 1, 0, &src, &samples, buf_size);\n\n break;\n\n case CODEC_ID_PCM_S24BE:\n\n decode_to16(3, 0, 0, &src, &samples, buf_size);\n\n break;\n\n case CODEC_ID_PCM_U24LE:\n\n decode_to16(3, 1, 1, &src, &samples, buf_size);\n\n break;\n\n case CODEC_ID_PCM_U24BE:\n\n decode_to16(3, 0, 1, &src, &samples, buf_size);\n\n break;\n\n case CODEC_ID_PCM_S24DAUD:\n\n n = buf_size / 3;\n\n for(;n>0;n--) {\n\n uint32_t v = src[0] << 16 | src[1] << 8 | src[2];\n\n v >>= 4; // sync flags are here\n\n *samples++ = ff_reverse[(v >> 8) & 0xff] +\n\n (ff_reverse[v & 0xff] << 8);\n\n src += 3;\n\n }\n\n break;\n\n case CODEC_ID_PCM_S16LE:\n\n n = buf_size >> 1;\n\n for(;n>0;n--) {\n\n *samples++ = src[0] | (src[1] << 8);\n\n src += 2;\n\n }\n\n break;\n\n case CODEC_ID_PCM_S16BE:\n\n n = buf_size >> 1;\n\n for(;n>0;n--) {\n\n *samples++ = (src[0] << 8) | src[1];\n\n src += 2;\n\n }\n\n break;\n\n case CODEC_ID_PCM_U16LE:\n\n n = buf_size >> 1;\n\n for(;n>0;n--) {\n\n *samples++ = (src[0] | (src[1] << 8)) - 0x8000;\n\n src += 2;\n\n }\n\n break;\n\n case CODEC_ID_PCM_U16BE:\n\n n = buf_size >> 1;\n\n for(;n>0;n--) {\n\n *samples++ = ((src[0] << 8) | src[1]) - 0x8000;\n\n src += 2;\n\n }\n\n break;\n\n case CODEC_ID_PCM_S8:\n\n n = buf_size;\n\n for(;n>0;n--) {\n\n *samples++ = src[0] << 8;\n\n src++;\n\n }\n\n break;\n\n case CODEC_ID_PCM_U8:\n\n n = buf_size;\n\n for(;n>0;n--) {\n\n *samples++ = ((int)src[0] - 128) << 8;\n\n src++;\n\n }\n\n break;\n\n case CODEC_ID_PCM_ALAW:\n\n case CODEC_ID_PCM_MULAW:\n\n n = buf_size;\n\n for(;n>0;n--) {\n\n *samples++ = s->table[src[0]];\n\n src++;\n\n }\n\n break;\n\n default:\n\n return -1;\n\n }\n\n *data_size = (uint8_t *)samples - (uint8_t *)data;\n\n return src - buf;\n\n}\n", + "output": "0", + "index": 18638 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int a52_decode_init(AVCodecContext *avctx)\n\n{\n\n AC3DecodeState *s = avctx->priv_data;\n\n\n\n#ifdef CONFIG_LIBA52BIN\n\n s->handle = dlopen(liba52name, RTLD_LAZY);\n\n if (!s->handle)\n\n {\n\n av_log( avctx, AV_LOG_ERROR, \"A52 library %s could not be opened! \\n%s\\n\", liba52name, dlerror());\n\n return -1;\n\n }\n\n s->a52_init = (a52_state_t* (*)(uint32_t)) dlsymm(s->handle, \"a52_init\");\n\n s->a52_samples = (sample_t* (*)(a52_state_t*)) dlsymm(s->handle, \"a52_samples\");\n\n s->a52_syncinfo = (int (*)(uint8_t*, int*, int*, int*)) dlsymm(s->handle, \"a52_syncinfo\");\n\n s->a52_frame = (int (*)(a52_state_t*, uint8_t*, int*, sample_t*, sample_t)) dlsymm(s->handle, \"a52_frame\");\n\n s->a52_block = (int (*)(a52_state_t*)) dlsymm(s->handle, \"a52_block\");\n\n s->a52_free = (void (*)(a52_state_t*)) dlsymm(s->handle, \"a52_free\");\n\n if (!s->a52_init || !s->a52_samples || !s->a52_syncinfo\n\n || !s->a52_frame || !s->a52_block || !s->a52_free)\n\n {\n\n dlclose(s->handle);\n\n return -1;\n\n }\n\n#else\n\n s->handle = 0;\n\n s->a52_init = a52_init;\n\n s->a52_samples = a52_samples;\n\n s->a52_syncinfo = a52_syncinfo;\n\n s->a52_frame = a52_frame;\n\n s->a52_block = a52_block;\n\n s->a52_free = a52_free;\n\n#endif\n\n s->state = s->a52_init(0); /* later use CPU flags */\n\n s->samples = s->a52_samples(s->state);\n\n s->inbuf_ptr = s->inbuf;\n\n s->frame_size = 0;\n\n\n\n /* allow downmixing to stereo or mono */\n\n if (avctx->channels > 0 && avctx->request_channels > 0 &&\n\n avctx->request_channels < avctx->channels &&\n\n avctx->request_channels <= 2) {\n\n avctx->channels = avctx->request_channels;\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 4745 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)\n\n{\n\n if (*spec <= '9' && *spec >= '0') /* opt:index */\n\n return strtol(spec, NULL, 0) == st->index;\n\n else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||\n\n *spec == 't') { /* opt:[vasdt] */\n\n enum AVMediaType type;\n\n\n\n switch (*spec++) {\n\n case 'v': type = AVMEDIA_TYPE_VIDEO; break;\n\n case 'a': type = AVMEDIA_TYPE_AUDIO; break;\n\n case 's': type = AVMEDIA_TYPE_SUBTITLE; break;\n\n case 'd': type = AVMEDIA_TYPE_DATA; break;\n\n case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;\n\n\n }\n\n if (type != st->codec->codec_type)\n\n return 0;\n\n if (*spec++ == ':') { /* possibly followed by :index */\n\n int i, index = strtol(spec, NULL, 0);\n\n for (i = 0; i < s->nb_streams; i++)\n\n if (s->streams[i]->codec->codec_type == type && index-- == 0)\n\n return i == st->index;\n\n return 0;\n\n }\n\n return 1;\n\n } else if (*spec == 'p' && *(spec + 1) == ':') {\n\n int prog_id, i, j;\n\n char *endptr;\n\n spec += 2;\n\n prog_id = strtol(spec, &endptr, 0);\n\n for (i = 0; i < s->nb_programs; i++) {\n\n if (s->programs[i]->id != prog_id)\n\n continue;\n\n\n\n if (*endptr++ == ':') {\n\n int stream_idx = strtol(endptr, NULL, 0);\n\n return stream_idx >= 0 &&\n\n stream_idx < s->programs[i]->nb_stream_indexes &&\n\n st->index == s->programs[i]->stream_index[stream_idx];\n\n }\n\n\n\n for (j = 0; j < s->programs[i]->nb_stream_indexes; j++)\n\n if (st->index == s->programs[i]->stream_index[j])\n\n return 1;\n\n }\n\n return 0;\n\n } else if (!*spec) /* empty specifier, matches everything */\n\n return 1;\n\n\n\n av_log(s, AV_LOG_ERROR, \"Invalid stream specifier: %s.\\n\", spec);\n\n return AVERROR(EINVAL);\n\n}", + "output": "1", + "index": 6434 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static float pvq_band_cost(CeltPVQ *pvq, CeltFrame *f, OpusRangeCoder *rc, int band,\n\n float *bits, float lambda)\n\n{\n\n int i, b = 0;\n\n uint32_t cm[2] = { (1 << f->blocks) - 1, (1 << f->blocks) - 1 };\n\n const int band_size = ff_celt_freq_range[band] << f->size;\n\n float buf[176 * 2], lowband_scratch[176], norm1[176], norm2[176];\n\n float dist, cost, err_x = 0.0f, err_y = 0.0f;\n\n float *X = buf;\n\n float *X_orig = f->block[0].coeffs + (ff_celt_freq_bands[band] << f->size);\n\n float *Y = (f->channels == 2) ? &buf[176] : NULL;\n\n float *Y_orig = f->block[1].coeffs + (ff_celt_freq_bands[band] << f->size);\n\n OPUS_RC_CHECKPOINT_SPAWN(rc);\n\n\n\n memcpy(X, X_orig, band_size*sizeof(float));\n\n if (Y)\n\n memcpy(Y, Y_orig, band_size*sizeof(float));\n\n\n\n f->remaining2 = ((f->framebits << 3) - f->anticollapse_needed) - opus_rc_tell_frac(rc) - 1;\n\n if (band <= f->coded_bands - 1) {\n\n int curr_balance = f->remaining / FFMIN(3, f->coded_bands - band);\n\n b = av_clip_uintp2(FFMIN(f->remaining2 + 1, f->pulses[band] + curr_balance), 14);\n\n }\n\n\n\n if (f->dual_stereo) {\n\n pvq->quant_band(pvq, f, rc, band, X, NULL, band_size, b / 2, f->blocks, NULL,\n\n f->size, norm1, 0, 1.0f, lowband_scratch, cm[0]);\n\n\n\n pvq->quant_band(pvq, f, rc, band, Y, NULL, band_size, b / 2, f->blocks, NULL,\n\n f->size, norm2, 0, 1.0f, lowband_scratch, cm[1]);\n\n } else {\n\n pvq->quant_band(pvq, f, rc, band, X, Y, band_size, b, f->blocks, NULL, f->size,\n\n norm1, 0, 1.0f, lowband_scratch, cm[0] | cm[1]);\n\n }\n\n\n\n for (i = 0; i < band_size; i++) {\n\n err_x += (X[i] - X_orig[i])*(X[i] - X_orig[i]);\n\n if (Y)\n\n err_y += (Y[i] - Y_orig[i])*(Y[i] - Y_orig[i]);\n\n }\n\n\n\n dist = sqrtf(err_x) + sqrtf(err_y);\n\n cost = OPUS_RC_CHECKPOINT_BITS(rc)/8.0f;\n\n *bits += cost;\n\n\n\n OPUS_RC_CHECKPOINT_ROLLBACK(rc);\n\n\n\n return lambda*dist*cost;\n\n}\n", + "output": "0", + "index": 6305 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void configure_icount(QemuOpts *opts, Error **errp)\n\n{\n\n const char *option;\n\n char *rem_str = NULL;\n\n\n\n option = qemu_opt_get(opts, \"shift\");\n\n if (!option) {\n\n if (qemu_opt_get(opts, \"align\") != NULL) {\n\n error_setg(errp, \"Please specify shift option when using align\");\n\n }\n\n return;\n\n }\n\n\n\n icount_sleep = qemu_opt_get_bool(opts, \"sleep\", true);\n\n if (icount_sleep) {\n\n icount_warp_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL_RT,\n\n icount_dummy_timer, NULL);\n\n }\n\n\n\n icount_align_option = qemu_opt_get_bool(opts, \"align\", false);\n\n\n\n if (icount_align_option && !icount_sleep) {\n\n error_setg(errp, \"align=on and sleep=off are incompatible\");\n\n }\n\n if (strcmp(option, \"auto\") != 0) {\n\n errno = 0;\n\n icount_time_shift = strtol(option, &rem_str, 0);\n\n if (errno != 0 || *rem_str != '\\0' || !strlen(option)) {\n\n error_setg(errp, \"icount: Invalid shift value\");\n\n }\n\n use_icount = 1;\n\n return;\n\n } else if (icount_align_option) {\n\n error_setg(errp, \"shift=auto and align=on are incompatible\");\n\n } else if (!icount_sleep) {\n\n error_setg(errp, \"shift=auto and sleep=off are incompatible\");\n\n }\n\n\n\n use_icount = 2;\n\n\n\n /* 125MIPS seems a reasonable initial guess at the guest speed.\n\n It will be corrected fairly quickly anyway. */\n\n icount_time_shift = 3;\n\n\n\n /* Have both realtime and virtual time triggers for speed adjustment.\n\n The realtime trigger catches emulated time passing too slowly,\n\n the virtual time trigger catches emulated time passing too fast.\n\n Realtime triggers occur even when idle, so use them less frequently\n\n than VM triggers. */\n\n icount_rt_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL_RT,\n\n icount_adjust_rt, NULL);\n\n timer_mod(icount_rt_timer,\n\n qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_RT) + 1000);\n\n icount_vm_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,\n\n icount_adjust_vm, NULL);\n\n timer_mod(icount_vm_timer,\n\n qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +\n\n get_ticks_per_sec() / 10);\n\n}\n", + "output": "0", + "index": 17709 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src, int linesize, int block_w, int block_h,\n\n int src_x, int src_y, int w, int h){\n\n int x, y;\n\n int start_y, start_x, end_y, end_x;\n\n\n\n if(src_y>= h){\n\n src+= (h-1-src_y)*linesize;\n\n src_y=h-1;\n\n }else if(src_y<=-block_h){\n\n src+= (1-block_h-src_y)*linesize;\n\n src_y=1-block_h;\n\n }\n\n if(src_x>= w){\n\n src+= (w-1-src_x)*sizeof(pixel);\n\n src_x=w-1;\n\n }else if(src_x<=-block_w){\n\n src+= (1-block_w-src_x)*sizeof(pixel);\n\n src_x=1-block_w;\n\n }\n\n\n\n start_y= FFMAX(0, -src_y);\n\n start_x= FFMAX(0, -src_x);\n\n end_y= FFMIN(block_h, h-src_y);\n\n end_x= FFMIN(block_w, w-src_x);\n\n av_assert2(start_y < end_y && block_h);\n\n av_assert2(start_x < end_x && block_w);\n\n\n\n w = end_x - start_x;\n\n src += start_y*linesize + start_x*sizeof(pixel);\n\n buf += start_x*sizeof(pixel);\n\n\n\n //top\n\n for(y=0; yy_dc_scale;\n\n } else {\n\n *dc_val = level * s->c_dc_scale;\n\n }\n\n\n\n /* do the prediction */\n\n level -= pred;\n\n\n\n if(s->msmpeg4_version<=2){\n\n if (n < 4) {\n\n put_bits(&s->pb,\n\n ff_v2_dc_lum_table[level + 256][1],\n\n ff_v2_dc_lum_table[level + 256][0]);\n\n }else{\n\n put_bits(&s->pb,\n\n ff_v2_dc_chroma_table[level + 256][1],\n\n ff_v2_dc_chroma_table[level + 256][0]);\n\n }\n\n }else{\n\n sign = 0;\n\n if (level < 0) {\n\n level = -level;\n\n sign = 1;\n\n }\n\n code = level;\n\n if (code > DC_MAX)\n\n code = DC_MAX;\n\n else if( s->msmpeg4_version>=6 ) {\n\n if( s->qscale == 1 ) {\n\n extquant = (level + 3) & 0x3;\n\n code = ((level+3)>>2);\n\n } else if( s->qscale == 2 ) {\n\n extquant = (level + 1) & 0x1;\n\n code = ((level+1)>>1);\n\n }\n\n }\n\n\n\n if (s->dc_table_index == 0) {\n\n if (n < 4) {\n\n put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);\n\n } else {\n\n put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);\n\n }\n\n } else {\n\n if (n < 4) {\n\n put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);\n\n } else {\n\n put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);\n\n }\n\n }\n\n\n\n if(s->msmpeg4_version>=6 && s->qscale<=2)\n\n extrabits = 3 - s->qscale;\n\n\n\n if (code == DC_MAX)\n\n put_bits(&s->pb, 8 + extrabits, level);\n\n else if(extrabits > 0)//== VC1 && s->qscale<=2\n\n put_bits(&s->pb, extrabits, extquant);\n\n\n\n if (level != 0) {\n\n put_bits(&s->pb, 1, sign);\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 10420 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)\n\n{\n\n AVFilterContext *ctx = inlink->dst;\n\n AVFilterLink *outlink = ctx->outputs[0];\n\n ShowWavesContext *showwaves = ctx->priv;\n\n const int nb_samples = insamples->audio->nb_samples;\n\n AVFilterBufferRef *outpicref = showwaves->outpicref;\n\n int linesize = outpicref ? outpicref->linesize[0] : 0;\n\n int16_t *p = (int16_t *)insamples->data[0];\n\n int nb_channels = av_get_channel_layout_nb_channels(insamples->audio->channel_layout);\n\n int i, j, h;\n\n const int n = showwaves->n;\n\n const int x = 255 / (nb_channels * n); /* multiplication factor, pre-computed to avoid in-loop divisions */\n\n\n\n /* draw data in the buffer */\n\n for (i = 0; i < nb_samples; i++) {\n\n if (showwaves->buf_idx == 0 && showwaves->sample_count_mod == 0) {\n\n showwaves->outpicref = outpicref =\n\n ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_ALIGN,\n\n outlink->w, outlink->h);\n\n outpicref->video->w = outlink->w;\n\n outpicref->video->h = outlink->h;\n\n outpicref->pts = insamples->pts +\n\n av_rescale_q((p - (int16_t *)insamples->data[0]) / nb_channels,\n\n (AVRational){ 1, inlink->sample_rate },\n\n outlink->time_base);\n\n outlink->out_buf = outpicref;\n\n linesize = outpicref->linesize[0];\n\n memset(outpicref->data[0], 0, showwaves->h*linesize);\n\n }\n\n for (j = 0; j < nb_channels; j++) {\n\n h = showwaves->h/2 - av_rescale(*p++, showwaves->h/2, MAX_INT16);\n\n if (h >= 0 && h < outlink->h)\n\n *(outpicref->data[0] + showwaves->buf_idx + h * linesize) += x;\n\n }\n\n showwaves->sample_count_mod++;\n\n if (showwaves->sample_count_mod == n) {\n\n showwaves->sample_count_mod = 0;\n\n showwaves->buf_idx++;\n\n }\n\n if (showwaves->buf_idx == showwaves->w)\n\n push_frame(outlink);\n\n }\n\n\n\n avfilter_unref_buffer(insamples);\n\n return 0;\n\n}\n", + "output": "1", + "index": 4018 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int encode_superframe(AVCodecContext *avctx,\n unsigned char *buf, int buf_size, void *data){\n WMACodecContext *s = avctx->priv_data;\n const short *samples = data;\n int i, total_gain;\n s->block_len_bits= s->frame_len_bits; //required by non variable block len\n s->block_len = 1 << s->block_len_bits;\n apply_window_and_mdct(avctx, samples, avctx->frame_size);\n if (s->ms_stereo) {\n float a, b;\n int i;\n for(i = 0; i < s->block_len; i++) {\n a = s->coefs[0][i]*0.5;\n b = s->coefs[1][i]*0.5;\n s->coefs[0][i] = a + b;\n s->coefs[1][i] = a - b;\n#if 1\n total_gain= 128;\n for(i=64; i; i>>=1){\n int error= encode_frame(s, s->coefs, buf, buf_size, total_gain-i);\n if(error<0)\n total_gain-= i;\n#else\n total_gain= 90;\n best= encode_frame(s, s->coefs, buf, buf_size, total_gain);\n for(i=32; i; i>>=1){\n int scoreL= encode_frame(s, s->coefs, buf, buf_size, total_gain-i);\n int scoreR= encode_frame(s, s->coefs, buf, buf_size, total_gain+i);\n av_log(NULL, AV_LOG_ERROR, \"%d %d %d (%d)\\n\", scoreL, best, scoreR, total_gain);\n if(scoreL < FFMIN(best, scoreR)){\n best = scoreL;\n total_gain -= i;\n }else if(scoreR < best){\n best = scoreR;\n total_gain += i;\n#endif\n encode_frame(s, s->coefs, buf, buf_size, total_gain);\n assert((put_bits_count(&s->pb) & 7) == 0);\n i= s->block_align - (put_bits_count(&s->pb)+7)/8;\n assert(i>=0);\n while(i--)\n put_bits(&s->pb, 8, 'N');\n flush_put_bits(&s->pb);\n return put_bits_ptr(&s->pb) - s->pb.buf;", + "output": "1", + "index": 14758 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component)\n\n{\n\n const int dst_linesize = out->linesize[component] / 2;\n\n const int bg = s->bg_color[component] * (s->size / 256);\n\n const int limit = s->size - 1;\n\n const int is_chroma = (component == 1 || component == 2);\n\n const int shift_w = (is_chroma ? s->desc->log2_chroma_w : 0);\n\n const int shift_h = (is_chroma ? s->desc->log2_chroma_h : 0);\n\n const int dst_h = FF_CEIL_RSHIFT(out->height, shift_h);\n\n const int dst_w = FF_CEIL_RSHIFT(out->width, shift_w);\n\n const int start = s->estart[plane];\n\n const int end = s->eend[plane];\n\n int *emax = s->emax[plane][component];\n\n int *emin = s->emin[plane][component];\n\n uint16_t *dst;\n\n int x, y;\n\n\n\n if (s->mode) {\n\n for (x = 0; x < dst_w; x++) {\n\n for (y = start; y < end && y < emin[x]; y++) {\n\n dst = (uint16_t *)out->data[component] + y * dst_linesize + x;\n\n if (dst[0] != bg) {\n\n emin[x] = y;\n\n break;\n\n }\n\n }\n\n for (y = end - 1; y >= start && y >= emax[x]; y--) {\n\n dst = (uint16_t *)out->data[component] + y * dst_linesize + x;\n\n if (dst[0] != bg) {\n\n emax[x] = y;\n\n break;\n\n }\n\n }\n\n }\n\n\n\n if (s->envelope == 3)\n\n envelope_instant16(s, out, plane, component);\n\n\n\n for (x = 0; x < dst_w; x++) {\n\n dst = (uint16_t *)out->data[component] + emin[x] * dst_linesize + x;\n\n dst[0] = limit;\n\n dst = (uint16_t *)out->data[component] + emax[x] * dst_linesize + x;\n\n dst[0] = limit;\n\n }\n\n } else {\n\n for (y = 0; y < dst_h; y++) {\n\n dst = (uint16_t *)out->data[component] + y * dst_linesize;\n\n for (x = start; x < end && x < emin[y]; x++) {\n\n if (dst[x] != bg) {\n\n emin[y] = x;\n\n break;\n\n }\n\n }\n\n for (x = end - 1; x >= start && x >= emax[y]; x--) {\n\n if (dst[x] != bg) {\n\n emax[y] = x;\n\n break;\n\n }\n\n }\n\n }\n\n\n\n if (s->envelope == 3)\n\n envelope_instant16(s, out, plane, component);\n\n\n\n for (y = 0; y < dst_h; y++) {\n\n dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y];\n\n dst[0] = limit;\n\n dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y];\n\n dst[0] = limit;\n\n }\n\n }\n\n}\n", + "output": "0", + "index": 3407 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int scsi_req_length(SCSIRequest *req, uint8_t *cmd)\n\n{\n\n switch (cmd[0] >> 5) {\n\n case 0:\n\n req->cmd.xfer = cmd[4];\n\n req->cmd.len = 6;\n\n /* length 0 means 256 blocks */\n\n if (req->cmd.xfer == 0)\n\n req->cmd.xfer = 256;\n\n break;\n\n case 1:\n\n case 2:\n\n req->cmd.xfer = cmd[8] | (cmd[7] << 8);\n\n req->cmd.len = 10;\n\n break;\n\n case 4:\n\n req->cmd.xfer = cmd[13] | (cmd[12] << 8) | (cmd[11] << 16) | (cmd[10] << 24);\n\n req->cmd.len = 16;\n\n break;\n\n case 5:\n\n req->cmd.xfer = cmd[9] | (cmd[8] << 8) | (cmd[7] << 16) | (cmd[6] << 24);\n\n req->cmd.len = 12;\n\n break;\n\n default:\n\n trace_scsi_req_parse_bad(req->dev->id, req->lun, req->tag, cmd[0]);\n\n return -1;\n\n }\n\n\n\n switch(cmd[0]) {\n\n case TEST_UNIT_READY:\n\n case START_STOP:\n\n case SEEK_6:\n\n case WRITE_FILEMARKS:\n\n case SPACE:\n\n case RESERVE:\n\n case RELEASE:\n\n case ERASE:\n\n case ALLOW_MEDIUM_REMOVAL:\n\n case VERIFY:\n\n case SEEK_10:\n\n case SYNCHRONIZE_CACHE:\n\n case LOCK_UNLOCK_CACHE:\n\n case LOAD_UNLOAD:\n\n case SET_CD_SPEED:\n\n case SET_LIMITS:\n\n case WRITE_LONG:\n\n case MOVE_MEDIUM:\n\n case UPDATE_BLOCK:\n\n req->cmd.xfer = 0;\n\n break;\n\n case MODE_SENSE:\n\n break;\n\n case WRITE_SAME:\n\n req->cmd.xfer = 1;\n\n break;\n\n case READ_CAPACITY:\n\n req->cmd.xfer = 8;\n\n break;\n\n case READ_BLOCK_LIMITS:\n\n req->cmd.xfer = 6;\n\n break;\n\n case READ_POSITION:\n\n req->cmd.xfer = 20;\n\n break;\n\n case SEND_VOLUME_TAG:\n\n req->cmd.xfer *= 40;\n\n break;\n\n case MEDIUM_SCAN:\n\n req->cmd.xfer *= 8;\n\n break;\n\n case WRITE_10:\n\n case WRITE_VERIFY:\n\n case WRITE_6:\n\n case WRITE_12:\n\n case WRITE_VERIFY_12:\n\n case WRITE_16:\n\n case WRITE_VERIFY_16:\n\n req->cmd.xfer *= req->dev->blocksize;\n\n break;\n\n case READ_10:\n\n case READ_6:\n\n case READ_REVERSE:\n\n case RECOVER_BUFFERED_DATA:\n\n case READ_12:\n\n case READ_16:\n\n req->cmd.xfer *= req->dev->blocksize;\n\n break;\n\n case INQUIRY:\n\n req->cmd.xfer = cmd[4] | (cmd[3] << 8);\n\n break;\n\n case MAINTENANCE_OUT:\n\n case MAINTENANCE_IN:\n\n if (req->dev->type == TYPE_ROM) {\n\n /* GPCMD_REPORT_KEY and GPCMD_SEND_KEY from multi media commands */\n\n req->cmd.xfer = cmd[9] | (cmd[8] << 8);\n\n }\n\n break;\n\n }\n\n return 0;\n\n}\n", + "output": "1", + "index": 1783 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap)\n\n{\n\n struct video_data *s = s1->priv_data;\n\n AVStream *st;\n\n int width, height;\n\n int res, frame_rate, frame_rate_base;\n\n uint32_t desired_format, capabilities;\n\n const char *video_device;\n\n\n\n if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {\n\n av_log(s1, AV_LOG_ERROR, \"Missing/Wrong parameters\\n\");\n\n\n\n return -1;\n\n }\n\n\n\n width = ap->width;\n\n height = ap->height;\n\n frame_rate = ap->time_base.den;\n\n frame_rate_base = ap->time_base.num;\n\n\n\n if((unsigned)width > 32767 || (unsigned)height > 32767) {\n\n av_log(s1, AV_LOG_ERROR, \"Wrong size %dx%d\\n\", width, height);\n\n\n\n return -1;\n\n }\n\n\n\n st = av_new_stream(s1, 0);\n\n if (!st) {\n\n return -ENOMEM;\n\n }\n\n av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */\n\n\n\n s->width = width;\n\n s->height = height;\n\n s->frame_rate = frame_rate;\n\n s->frame_rate_base = frame_rate_base;\n\n\n\n video_device = ap->device;\n\n if (!video_device) {\n\n video_device = \"/dev/video\";\n\n }\n\n capabilities = 0;\n\n s->fd = device_open(video_device, &capabilities);\n\n if (s->fd < 0) {\n\n av_free(st);\n\n\n\n return AVERROR_IO;\n\n }\n\n av_log(s1, AV_LOG_ERROR, \"[%d]Capabilities: %x\\n\", s->fd, capabilities);\n\n\n\n desired_format = fmt_ff2v4l(ap->pix_fmt);\n\n if (desired_format == 0 || (device_init(s->fd, &width, &height, desired_format) < 0)) {\n\n int i, done;\n\n\n\n done = 0; i = 0;\n\n while (!done) {\n\n desired_format = fmt_conversion_table[i].v4l2_fmt;\n\n if (device_init(s->fd, &width, &height, desired_format) < 0) {\n\n desired_format = 0;\n\n i++;\n\n } else {\n\n done = 1;\n\n }\n\n if (i == sizeof(fmt_conversion_table) / sizeof(struct fmt_map)) {\n\n done = 1;\n\n }\n\n }\n\n }\n\n if (desired_format == 0) {\n\n av_log(s1, AV_LOG_ERROR, \"Cannot find a proper format.\\n\");\n\n close(s->fd);\n\n av_free(st);\n\n\n\n return AVERROR_IO;\n\n }\n\n s->frame_format = desired_format;\n\n\n\n st->codec->pix_fmt = fmt_v4l2ff(desired_format);\n\n s->frame_size = avpicture_get_size(st->codec->pix_fmt, width, height);\n\n if (capabilities & V4L2_CAP_STREAMING) {\n\n s->io_method = io_mmap;\n\n res = mmap_init(s);\n\n res = mmap_start(s);\n\n } else {\n\n s->io_method = io_read;\n\n res = read_init(s);\n\n }\n\n if (res < 0) {\n\n close(s->fd);\n\n av_free(st);\n\n\n\n return AVERROR_IO;\n\n }\n\n s->top_field_first = first_field(s->fd);\n\n\n\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n\n st->codec->codec_id = CODEC_ID_RAWVIDEO;\n\n st->codec->width = width;\n\n st->codec->height = height;\n\n st->codec->time_base.den = frame_rate;\n\n st->codec->time_base.num = frame_rate_base;\n\n st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8;\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 16333 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static uint64_t omap_pin_cfg_read(void *opaque, target_phys_addr_t addr,\n\n unsigned size)\n\n{\n\n struct omap_mpu_state_s *s = (struct omap_mpu_state_s *) opaque;\n\n\n\n if (size != 4) {\n\n return omap_badwidth_read32(opaque, addr);\n\n }\n\n\n\n switch (addr) {\n\n case 0x00:\t/* FUNC_MUX_CTRL_0 */\n\n case 0x04:\t/* FUNC_MUX_CTRL_1 */\n\n case 0x08:\t/* FUNC_MUX_CTRL_2 */\n\n return s->func_mux_ctrl[addr >> 2];\n\n\n\n case 0x0c:\t/* COMP_MODE_CTRL_0 */\n\n return s->comp_mode_ctrl[0];\n\n\n\n case 0x10:\t/* FUNC_MUX_CTRL_3 */\n\n case 0x14:\t/* FUNC_MUX_CTRL_4 */\n\n case 0x18:\t/* FUNC_MUX_CTRL_5 */\n\n case 0x1c:\t/* FUNC_MUX_CTRL_6 */\n\n case 0x20:\t/* FUNC_MUX_CTRL_7 */\n\n case 0x24:\t/* FUNC_MUX_CTRL_8 */\n\n case 0x28:\t/* FUNC_MUX_CTRL_9 */\n\n case 0x2c:\t/* FUNC_MUX_CTRL_A */\n\n case 0x30:\t/* FUNC_MUX_CTRL_B */\n\n case 0x34:\t/* FUNC_MUX_CTRL_C */\n\n case 0x38:\t/* FUNC_MUX_CTRL_D */\n\n return s->func_mux_ctrl[(addr >> 2) - 1];\n\n\n\n case 0x40:\t/* PULL_DWN_CTRL_0 */\n\n case 0x44:\t/* PULL_DWN_CTRL_1 */\n\n case 0x48:\t/* PULL_DWN_CTRL_2 */\n\n case 0x4c:\t/* PULL_DWN_CTRL_3 */\n\n return s->pull_dwn_ctrl[(addr & 0xf) >> 2];\n\n\n\n case 0x50:\t/* GATE_INH_CTRL_0 */\n\n return s->gate_inh_ctrl[0];\n\n\n\n case 0x60:\t/* VOLTAGE_CTRL_0 */\n\n return s->voltage_ctrl[0];\n\n\n\n case 0x70:\t/* TEST_DBG_CTRL_0 */\n\n return s->test_dbg_ctrl[0];\n\n\n\n case 0x80:\t/* MOD_CONF_CTRL_0 */\n\n return s->mod_conf_ctrl[0];\n\n }\n\n\n\n OMAP_BAD_REG(addr);\n\n return 0;\n\n}\n", + "output": "0", + "index": 979 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void stm32f2xx_timer_write(void *opaque, hwaddr offset,\n\n uint64_t val64, unsigned size)\n\n{\n\n STM32F2XXTimerState *s = opaque;\n\n uint32_t value = val64;\n\n int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);\n\n uint32_t timer_val = 0;\n\n\n\n DB_PRINT(\"Write 0x%x, 0x%\"HWADDR_PRIx\"\\n\", value, offset);\n\n\n\n switch (offset) {\n\n case TIM_CR1:\n\n s->tim_cr1 = value;\n\n return;\n\n case TIM_CR2:\n\n s->tim_cr2 = value;\n\n return;\n\n case TIM_SMCR:\n\n s->tim_smcr = value;\n\n return;\n\n case TIM_DIER:\n\n s->tim_dier = value;\n\n return;\n\n case TIM_SR:\n\n /* This is set by hardware and cleared by software */\n\n s->tim_sr &= value;\n\n return;\n\n case TIM_EGR:\n\n s->tim_egr = value;\n\n if (s->tim_egr & TIM_EGR_UG) {\n\n timer_val = 0;\n\n break;\n\n }\n\n return;\n\n case TIM_CCMR1:\n\n s->tim_ccmr1 = value;\n\n return;\n\n case TIM_CCMR2:\n\n s->tim_ccmr2 = value;\n\n return;\n\n case TIM_CCER:\n\n s->tim_ccer = value;\n\n return;\n\n case TIM_PSC:\n\n timer_val = stm32f2xx_ns_to_ticks(s, now) - s->tick_offset;\n\n s->tim_psc = value;\n\n value = timer_val;\n\n break;\n\n case TIM_CNT:\n\n timer_val = value;\n\n break;\n\n case TIM_ARR:\n\n s->tim_arr = value;\n\n stm32f2xx_timer_set_alarm(s, now);\n\n return;\n\n case TIM_CCR1:\n\n s->tim_ccr1 = value;\n\n return;\n\n case TIM_CCR2:\n\n s->tim_ccr2 = value;\n\n return;\n\n case TIM_CCR3:\n\n s->tim_ccr3 = value;\n\n return;\n\n case TIM_CCR4:\n\n s->tim_ccr4 = value;\n\n return;\n\n case TIM_DCR:\n\n s->tim_dcr = value;\n\n return;\n\n case TIM_DMAR:\n\n s->tim_dmar = value;\n\n return;\n\n case TIM_OR:\n\n s->tim_or = value;\n\n return;\n\n default:\n\n qemu_log_mask(LOG_GUEST_ERROR,\n\n \"%s: Bad offset 0x%\"HWADDR_PRIx\"\\n\", __func__, offset);\n\n return;\n\n }\n\n\n\n /* This means that a register write has affected the timer in a way that\n\n * requires a refresh of both tick_offset and the alarm.\n\n */\n\n s->tick_offset = stm32f2xx_ns_to_ticks(s, now) - timer_val;\n\n stm32f2xx_timer_set_alarm(s, now);\n\n}\n", + "output": "1", + "index": 6437 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,\n\n const AVFrame *pict, int *got_packet)\n\n{\n\n SVQ1EncContext *const s = avctx->priv_data;\n\n AVFrame *const p = avctx->coded_frame;\n\n int i, ret;\n\n\n\n if (!pkt->data &&\n\n (ret = av_new_packet(pkt, s->y_block_width * s->y_block_height *\n\n MAX_MB_BYTES * 3 + FF_MIN_BUFFER_SIZE)) < 0) {\n\n av_log(avctx, AV_LOG_ERROR, \"Error getting output packet.\\n\");\n\n return ret;\n\n }\n\n\n\n if (avctx->pix_fmt != AV_PIX_FMT_YUV410P) {\n\n av_log(avctx, AV_LOG_ERROR, \"unsupported pixel format\\n\");\n\n return -1;\n\n }\n\n\n\n if (!s->current_picture->data[0]) {\n\n ret = ff_get_buffer(avctx, s->current_picture, 0);\n\n if (ret < 0)\n\n return ret;\n\n }\n\n if (!s->last_picture->data[0]) {\n\n ret = ff_get_buffer(avctx, s->last_picture, 0);\n\n if (ret < 0)\n\n return ret;\n\n }\n\n if (!s->scratchbuf) {\n\n s->scratchbuf = av_malloc(s->current_picture->linesize[0] * 16 * 2);\n\n if (!s->scratchbuf)\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n FFSWAP(AVFrame*, s->current_picture, s->last_picture);\n\n\n\n init_put_bits(&s->pb, pkt->data, pkt->size);\n\n\n\n p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ?\n\n AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;\n\n p->key_frame = p->pict_type == AV_PICTURE_TYPE_I;\n\n p->quality = pict->quality;\n\n\n\n svq1_write_header(s, p->pict_type);\n\n for (i = 0; i < 3; i++)\n\n if (svq1_encode_plane(s, i,\n\n pict->data[i],\n\n s->last_picture->data[i],\n\n s->current_picture->data[i],\n\n s->frame_width / (i ? 4 : 1),\n\n s->frame_height / (i ? 4 : 1),\n\n pict->linesize[i],\n\n s->current_picture->linesize[i]) < 0)\n\n return -1;\n\n\n\n // avpriv_align_put_bits(&s->pb);\n\n while (put_bits_count(&s->pb) & 31)\n\n put_bits(&s->pb, 1, 0);\n\n\n\n flush_put_bits(&s->pb);\n\n\n\n pkt->size = put_bits_count(&s->pb) / 8;\n\n if (p->pict_type == AV_PICTURE_TYPE_I)\n\n pkt->flags |= AV_PKT_FLAG_KEY;\n\n *got_packet = 1;\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 13925 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int raw_create(const char *filename, QemuOpts *opts, Error **errp)\n\n{\n\n int fd;\n\n int result = 0;\n\n int64_t total_size = 0;\n\n bool nocow = false;\n\n PreallocMode prealloc;\n\n char *buf = NULL;\n\n Error *local_err = NULL;\n\n\n\n strstart(filename, \"file:\", &filename);\n\n\n\n /* Read out options */\n\n total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),\n\n BDRV_SECTOR_SIZE);\n\n nocow = qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false);\n\n buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);\n\n prealloc = qapi_enum_parse(PreallocMode_lookup, buf,\n\n PREALLOC_MODE_MAX, PREALLOC_MODE_OFF,\n\n &local_err);\n\n g_free(buf);\n\n if (local_err) {\n\n error_propagate(errp, local_err);\n\n result = -EINVAL;\n\n goto out;\n\n }\n\n\n\n fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,\n\n 0644);\n\n if (fd < 0) {\n\n result = -errno;\n\n error_setg_errno(errp, -result, \"Could not create file\");\n\n goto out;\n\n }\n\n\n\n if (nocow) {\n\n#ifdef __linux__\n\n /* Set NOCOW flag to solve performance issue on fs like btrfs.\n\n * This is an optimisation. The FS_IOC_SETFLAGS ioctl return value\n\n * will be ignored since any failure of this operation should not\n\n * block the left work.\n\n */\n\n int attr;\n\n if (ioctl(fd, FS_IOC_GETFLAGS, &attr) == 0) {\n\n attr |= FS_NOCOW_FL;\n\n ioctl(fd, FS_IOC_SETFLAGS, &attr);\n\n }\n\n#endif\n\n }\n\n\n\n if (ftruncate(fd, total_size) != 0) {\n\n result = -errno;\n\n error_setg_errno(errp, -result, \"Could not resize file\");\n\n goto out_close;\n\n }\n\n\n\n switch (prealloc) {\n\n#ifdef CONFIG_POSIX_FALLOCATE\n\n case PREALLOC_MODE_FALLOC:\n\n /* posix_fallocate() doesn't set errno. */\n\n result = -posix_fallocate(fd, 0, total_size);\n\n if (result != 0) {\n\n error_setg_errno(errp, -result,\n\n \"Could not preallocate data for the new file\");\n\n }\n\n break;\n\n#endif\n\n case PREALLOC_MODE_FULL:\n\n {\n\n int64_t num = 0, left = total_size;\n\n buf = g_malloc0(65536);\n\n\n\n while (left > 0) {\n\n num = MIN(left, 65536);\n\n result = write(fd, buf, num);\n\n if (result < 0) {\n\n result = -errno;\n\n error_setg_errno(errp, -result,\n\n \"Could not write to the new file\");\n\n break;\n\n }\n\n left -= result;\n\n }\n\n fsync(fd);\n\n g_free(buf);\n\n break;\n\n }\n\n case PREALLOC_MODE_OFF:\n\n break;\n\n default:\n\n result = -EINVAL;\n\n error_setg(errp, \"Unsupported preallocation mode: %s\",\n\n PreallocMode_lookup[prealloc]);\n\n break;\n\n }\n\n\n\nout_close:\n\n if (qemu_close(fd) != 0 && result == 0) {\n\n result = -errno;\n\n error_setg_errno(errp, -result, \"Could not close the new file\");\n\n }\n\nout:\n\n return result;\n\n}\n", + "output": "0", + "index": 19277 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int parse_presentation_segment(AVCodecContext *avctx,\n\n const uint8_t *buf, int buf_size,\n\n int64_t pts)\n\n{\n\n PGSSubContext *ctx = avctx->priv_data;\n\n int i, state, ret;\n\n\n\n\n // Video descriptor\n\n int w = bytestream_get_be16(&buf);\n\n int h = bytestream_get_be16(&buf);\n\n\n\n uint16_t object_index;\n\n\n\n ctx->presentation.pts = pts;\n\n\n\n av_dlog(avctx, \"Video Dimensions %dx%d\\n\",\n\n w, h);\n\n ret = ff_set_dimensions(avctx, w, h);\n\n if (ret < 0)\n\n return ret;\n\n\n\n /* Skip 1 bytes of unknown, frame rate */\n\n buf++;\n\n\n\n // Composition descriptor\n\n ctx->presentation.id_number = bytestream_get_be16(&buf);\n\n /*\n\n * state is a 2 bit field that defines pgs epoch boundaries\n\n * 00 - Normal, previously defined objects and palettes are still valid\n\n * 01 - Acquisition point, previous objects and palettes can be released\n\n * 10 - Epoch start, previous objects and palettes can be released\n\n * 11 - Epoch continue, previous objects and palettes can be released\n\n *\n\n * reserved 6 bits discarded\n\n */\n\n state = bytestream_get_byte(&buf) >> 6;\n\n if (state != 0) {\n\n flush_cache(avctx);\n\n }\n\n\n\n /*\n\n * skip palette_update_flag (0x80),\n\n */\n\n buf += 1;\n\n ctx->presentation.palette_id = bytestream_get_byte(&buf);\n\n ctx->presentation.object_count = bytestream_get_byte(&buf);\n\n if (ctx->presentation.object_count > MAX_OBJECT_REFS) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Invalid number of presentation objects %d\\n\",\n\n ctx->presentation.object_count);\n\n ctx->presentation.object_count = 2;\n\n if (avctx->err_recognition & AV_EF_EXPLODE) {\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n\n\n\n\n for (i = 0; i < ctx->presentation.object_count; i++)\n\n {\n\n\n\n if (buf_end - buf < 8) {\n\n av_log(avctx, AV_LOG_ERROR, \"Insufficent space for object\\n\");\n\n ctx->presentation.object_count = i;\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n ctx->presentation.objects[i].id = bytestream_get_be16(&buf);\n\n ctx->presentation.objects[i].window_id = bytestream_get_byte(&buf);\n\n ctx->presentation.objects[i].composition_flag = bytestream_get_byte(&buf);\n\n\n\n ctx->presentation.objects[i].x = bytestream_get_be16(&buf);\n\n ctx->presentation.objects[i].y = bytestream_get_be16(&buf);\n\n\n\n // If cropping\n\n if (ctx->presentation.objects[i].composition_flag & 0x80) {\n\n ctx->presentation.objects[i].crop_x = bytestream_get_be16(&buf);\n\n ctx->presentation.objects[i].crop_y = bytestream_get_be16(&buf);\n\n ctx->presentation.objects[i].crop_w = bytestream_get_be16(&buf);\n\n ctx->presentation.objects[i].crop_h = bytestream_get_be16(&buf);\n\n }\n\n\n\n av_dlog(avctx, \"Subtitle Placement x=%d, y=%d\\n\",\n\n ctx->presentation.objects[i].x, ctx->presentation.objects[i].y);\n\n\n\n if (ctx->presentation.objects[i].x > avctx->width ||\n\n ctx->presentation.objects[i].y > avctx->height) {\n\n av_log(avctx, AV_LOG_ERROR, \"Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\\n\",\n\n ctx->presentation.objects[i].x,\n\n ctx->presentation.objects[i].y,\n\n avctx->width, avctx->height);\n\n ctx->presentation.objects[i].x = 0;\n\n ctx->presentation.objects[i].y = 0;\n\n if (avctx->err_recognition & AV_EF_EXPLODE) {\n\n return AVERROR_INVALIDDATA;\n\n }\n\n }\n\n }\n\n\n\n return 0;\n\n}", + "output": "1", + "index": 20447 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "CPUState *ppc440ep_init(MemoryRegion *address_space_mem, ram_addr_t *ram_size,\n\n PCIBus **pcip, const unsigned int pci_irq_nrs[4],\n\n int do_init, const char *cpu_model)\n\n{\n\n MemoryRegion *ram_memories\n\n = g_malloc(PPC440EP_SDRAM_NR_BANKS * sizeof(*ram_memories));\n\n target_phys_addr_t ram_bases[PPC440EP_SDRAM_NR_BANKS];\n\n target_phys_addr_t ram_sizes[PPC440EP_SDRAM_NR_BANKS];\n\n CPUState *env;\n\n qemu_irq *pic;\n\n qemu_irq *irqs;\n\n qemu_irq *pci_irqs;\n\n\n\n if (cpu_model == NULL) {\n\n cpu_model = \"440-Xilinx\"; // XXX: should be 440EP\n\n }\n\n env = cpu_init(cpu_model);\n\n if (!env) {\n\n fprintf(stderr, \"Unable to initialize CPU!\\n\");\n\n exit(1);\n\n }\n\n\n\n ppc_booke_timers_init(env, 400000000, 0);\n\n ppc_dcr_init(env, NULL, NULL);\n\n\n\n /* interrupt controller */\n\n irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);\n\n irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];\n\n irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];\n\n pic = ppcuic_init(env, irqs, 0x0C0, 0, 1);\n\n\n\n /* SDRAM controller */\n\n memset(ram_bases, 0, sizeof(ram_bases));\n\n memset(ram_sizes, 0, sizeof(ram_sizes));\n\n *ram_size = ppc4xx_sdram_adjust(*ram_size, PPC440EP_SDRAM_NR_BANKS,\n\n ram_memories,\n\n ram_bases, ram_sizes,\n\n ppc440ep_sdram_bank_sizes);\n\n /* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */\n\n ppc4xx_sdram_init(env, pic[14], PPC440EP_SDRAM_NR_BANKS, ram_memories,\n\n ram_bases, ram_sizes, do_init);\n\n\n\n /* PCI */\n\n pci_irqs = g_malloc(sizeof(qemu_irq) * 4);\n\n pci_irqs[0] = pic[pci_irq_nrs[0]];\n\n pci_irqs[1] = pic[pci_irq_nrs[1]];\n\n pci_irqs[2] = pic[pci_irq_nrs[2]];\n\n pci_irqs[3] = pic[pci_irq_nrs[3]];\n\n *pcip = ppc4xx_pci_init(env, pci_irqs,\n\n PPC440EP_PCI_CONFIG,\n\n PPC440EP_PCI_INTACK,\n\n PPC440EP_PCI_SPECIAL,\n\n PPC440EP_PCI_REGS);\n\n if (!*pcip)\n\n printf(\"couldn't create PCI controller!\\n\");\n\n\n\n isa_mmio_init(PPC440EP_PCI_IO, PPC440EP_PCI_IOLEN);\n\n\n\n if (serial_hds[0] != NULL) {\n\n serial_mm_init(address_space_mem, 0xef600300, 0, pic[0],\n\n PPC_SERIAL_MM_BAUDBASE, serial_hds[0],\n\n DEVICE_BIG_ENDIAN);\n\n }\n\n if (serial_hds[1] != NULL) {\n\n serial_mm_init(address_space_mem, 0xef600400, 0, pic[1],\n\n PPC_SERIAL_MM_BAUDBASE, serial_hds[1],\n\n DEVICE_BIG_ENDIAN);\n\n }\n\n\n\n return env;\n\n}\n", + "output": "0", + "index": 5875 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void ppc_translate_init(void)\n\n{\n\n int i;\n\n char* p;\n\n size_t cpu_reg_names_size;\n\n static int done_init = 0;\n\n\n\n if (done_init)\n\n return;\n\n\n\n cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, \"env\");\n\n\n\n p = cpu_reg_names;\n\n cpu_reg_names_size = sizeof(cpu_reg_names);\n\n\n\n for (i = 0; i < 8; i++) {\n\n snprintf(p, cpu_reg_names_size, \"crf%d\", i);\n\n cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,\n\n offsetof(CPUState, crf[i]), p);\n\n p += 5;\n\n cpu_reg_names_size -= 5;\n\n }\n\n\n\n for (i = 0; i < 32; i++) {\n\n snprintf(p, cpu_reg_names_size, \"r%d\", i);\n\n cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,\n\n offsetof(CPUState, gpr[i]), p);\n\n p += (i < 10) ? 3 : 4;\n\n cpu_reg_names_size -= (i < 10) ? 3 : 4;\n\n#if !defined(TARGET_PPC64)\n\n snprintf(p, cpu_reg_names_size, \"r%dH\", i);\n\n cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0,\n\n offsetof(CPUState, gprh[i]), p);\n\n p += (i < 10) ? 4 : 5;\n\n cpu_reg_names_size -= (i < 10) ? 4 : 5;\n\n#endif\n\n\n\n snprintf(p, cpu_reg_names_size, \"fp%d\", i);\n\n cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,\n\n offsetof(CPUState, fpr[i]), p);\n\n p += (i < 10) ? 4 : 5;\n\n cpu_reg_names_size -= (i < 10) ? 4 : 5;\n\n\n\n snprintf(p, cpu_reg_names_size, \"avr%dH\", i);\n\n#ifdef HOST_WORDS_BIGENDIAN\n\n cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,\n\n offsetof(CPUState, avr[i].u64[0]), p);\n\n#else\n\n cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,\n\n offsetof(CPUState, avr[i].u64[1]), p);\n\n#endif\n\n p += (i < 10) ? 6 : 7;\n\n cpu_reg_names_size -= (i < 10) ? 6 : 7;\n\n\n\n snprintf(p, cpu_reg_names_size, \"avr%dL\", i);\n\n#ifdef HOST_WORDS_BIGENDIAN\n\n cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,\n\n offsetof(CPUState, avr[i].u64[1]), p);\n\n#else\n\n cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,\n\n offsetof(CPUState, avr[i].u64[0]), p);\n\n#endif\n\n p += (i < 10) ? 6 : 7;\n\n cpu_reg_names_size -= (i < 10) ? 6 : 7;\n\n }\n\n\n\n cpu_nip = tcg_global_mem_new(TCG_AREG0,\n\n offsetof(CPUState, nip), \"nip\");\n\n\n\n cpu_msr = tcg_global_mem_new(TCG_AREG0,\n\n offsetof(CPUState, msr), \"msr\");\n\n\n\n cpu_ctr = tcg_global_mem_new(TCG_AREG0,\n\n offsetof(CPUState, ctr), \"ctr\");\n\n\n\n cpu_lr = tcg_global_mem_new(TCG_AREG0,\n\n offsetof(CPUState, lr), \"lr\");\n\n\n\n cpu_xer = tcg_global_mem_new(TCG_AREG0,\n\n offsetof(CPUState, xer), \"xer\");\n\n\n\n cpu_reserve = tcg_global_mem_new(TCG_AREG0,\n\n offsetof(CPUState, reserve), \"reserve\");\n\n\n\n cpu_fpscr = tcg_global_mem_new_i32(TCG_AREG0,\n\n offsetof(CPUState, fpscr), \"fpscr\");\n\n\n\n cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,\n\n offsetof(CPUState, access_type), \"access_type\");\n\n\n\n /* register helpers */\n\n#define GEN_HELPER 2\n\n#include \"helper.h\"\n\n\n\n done_init = 1;\n\n}\n", + "output": "0", + "index": 7360 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void config_parse(GAConfig *config, int argc, char **argv)\n\n{\n\n const char *sopt = \"hVvdm:p:l:f:F::b:s:t:D\";\n\n int opt_ind = 0, ch;\n\n const struct option lopt[] = {\n\n { \"help\", 0, NULL, 'h' },\n\n { \"version\", 0, NULL, 'V' },\n\n { \"dump-conf\", 0, NULL, 'D' },\n\n { \"logfile\", 1, NULL, 'l' },\n\n { \"pidfile\", 1, NULL, 'f' },\n\n#ifdef CONFIG_FSFREEZE\n\n { \"fsfreeze-hook\", 2, NULL, 'F' },\n\n#endif\n\n { \"verbose\", 0, NULL, 'v' },\n\n { \"method\", 1, NULL, 'm' },\n\n { \"path\", 1, NULL, 'p' },\n\n { \"daemonize\", 0, NULL, 'd' },\n\n { \"blacklist\", 1, NULL, 'b' },\n\n#ifdef _WIN32\n\n { \"service\", 1, NULL, 's' },\n\n#endif\n\n { \"statedir\", 1, NULL, 't' },\n\n { NULL, 0, NULL, 0 }\n\n };\n\n\n\n config->log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL;\n\n\n\n while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {\n\n switch (ch) {\n\n case 'm':\n\n g_free(config->method);\n\n config->method = g_strdup(optarg);\n\n break;\n\n case 'p':\n\n g_free(config->channel_path);\n\n config->channel_path = g_strdup(optarg);\n\n break;\n\n case 'l':\n\n g_free(config->log_filepath);\n\n config->log_filepath = g_strdup(optarg);\n\n break;\n\n case 'f':\n\n g_free(config->pid_filepath);\n\n config->pid_filepath = g_strdup(optarg);\n\n break;\n\n#ifdef CONFIG_FSFREEZE\n\n case 'F':\n\n g_free(config->fsfreeze_hook);\n\n config->fsfreeze_hook = g_strdup(optarg ?: QGA_FSFREEZE_HOOK_DEFAULT);\n\n break;\n\n#endif\n\n case 't':\n\n g_free(config->state_dir);\n\n config->state_dir = g_strdup(optarg);\n\n break;\n\n case 'v':\n\n /* enable all log levels */\n\n config->log_level = G_LOG_LEVEL_MASK;\n\n break;\n\n case 'V':\n\n printf(\"QEMU Guest Agent %s\\n\", QEMU_VERSION);\n\n exit(EXIT_SUCCESS);\n\n case 'd':\n\n config->daemonize = 1;\n\n break;\n\n case 'D':\n\n config->dumpconf = 1;\n\n break;\n\n case 'b': {\n\n if (is_help_option(optarg)) {\n\n qmp_for_each_command(ga_print_cmd, NULL);\n\n exit(EXIT_SUCCESS);\n\n }\n\n config->blacklist = g_list_concat(config->blacklist,\n\n split_list(optarg, \",\"));\n\n break;\n\n }\n\n#ifdef _WIN32\n\n case 's':\n\n config->service = optarg;\n\n if (strcmp(config->service, \"install\") == 0) {\n\n if (ga_install_vss_provider()) {\n\n exit(EXIT_FAILURE);\n\n }\n\n if (ga_install_service(config->channel_path,\n\n config->log_filepath, config->state_dir)) {\n\n exit(EXIT_FAILURE);\n\n }\n\n exit(EXIT_SUCCESS);\n\n } else if (strcmp(config->service, \"uninstall\") == 0) {\n\n ga_uninstall_vss_provider();\n\n exit(ga_uninstall_service());\n\n } else if (strcmp(config->service, \"vss-install\") == 0) {\n\n if (ga_install_vss_provider()) {\n\n exit(EXIT_FAILURE);\n\n }\n\n exit(EXIT_SUCCESS);\n\n } else if (strcmp(config->service, \"vss-uninstall\") == 0) {\n\n ga_uninstall_vss_provider();\n\n exit(EXIT_SUCCESS);\n\n } else {\n\n printf(\"Unknown service command.\\n\");\n\n exit(EXIT_FAILURE);\n\n }\n\n break;\n\n#endif\n\n case 'h':\n\n usage(argv[0]);\n\n exit(EXIT_SUCCESS);\n\n case '?':\n\n g_print(\"Unknown option, try '%s --help' for more information.\\n\",\n\n argv[0]);\n\n exit(EXIT_FAILURE);\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 17949 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void test_qga_file_write_read(gconstpointer fix)\n\n{\n\n const TestFixture *fixture = fix;\n\n const unsigned char helloworld[] = \"Hello World!\\n\";\n\n const char *b64;\n\n gchar *cmd, *enc;\n\n QDict *ret, *val;\n\n int64_t id, eof;\n\n gsize count;\n\n\n\n /* open */\n\n ret = qmp_fd(fixture->fd, \"{'execute': 'guest-file-open',\"\n\n \" 'arguments': { 'path': 'foo', 'mode': 'w+' } }\");\n\n g_assert_nonnull(ret);\n\n qmp_assert_no_error(ret);\n\n id = qdict_get_int(ret, \"return\");\n\n QDECREF(ret);\n\n\n\n enc = g_base64_encode(helloworld, sizeof(helloworld));\n\n /* write */\n\n cmd = g_strdup_printf(\"{'execute': 'guest-file-write',\"\n\n \" 'arguments': { 'handle': %\" PRId64 \",\"\n\n \" 'buf-b64': '%s' } }\", id, enc);\n\n ret = qmp_fd(fixture->fd, cmd);\n\n g_assert_nonnull(ret);\n\n qmp_assert_no_error(ret);\n\n\n\n val = qdict_get_qdict(ret, \"return\");\n\n count = qdict_get_int(val, \"count\");\n\n eof = qdict_get_bool(val, \"eof\");\n\n g_assert_cmpint(count, ==, sizeof(helloworld));\n\n g_assert_cmpint(eof, ==, 0);\n\n QDECREF(ret);\n\n g_free(cmd);\n\n\n\n /* read (check implicit flush) */\n\n cmd = g_strdup_printf(\"{'execute': 'guest-file-read',\"\n\n \" 'arguments': { 'handle': %\" PRId64 \"} }\",\n\n id);\n\n ret = qmp_fd(fixture->fd, cmd);\n\n val = qdict_get_qdict(ret, \"return\");\n\n count = qdict_get_int(val, \"count\");\n\n eof = qdict_get_bool(val, \"eof\");\n\n b64 = qdict_get_str(val, \"buf-b64\");\n\n g_assert_cmpint(count, ==, 0);\n\n g_assert(eof);\n\n g_assert_cmpstr(b64, ==, \"\");\n\n QDECREF(ret);\n\n g_free(cmd);\n\n\n\n /* seek to 0 */\n\n cmd = g_strdup_printf(\"{'execute': 'guest-file-seek',\"\n\n \" 'arguments': { 'handle': %\" PRId64 \", \"\n\n \" 'offset': %d, 'whence': %d } }\",\n\n id, 0, SEEK_SET);\n\n ret = qmp_fd(fixture->fd, cmd);\n\n qmp_assert_no_error(ret);\n\n val = qdict_get_qdict(ret, \"return\");\n\n count = qdict_get_int(val, \"position\");\n\n eof = qdict_get_bool(val, \"eof\");\n\n g_assert_cmpint(count, ==, 0);\n\n g_assert(!eof);\n\n QDECREF(ret);\n\n g_free(cmd);\n\n\n\n /* read */\n\n cmd = g_strdup_printf(\"{'execute': 'guest-file-read',\"\n\n \" 'arguments': { 'handle': %\" PRId64 \"} }\",\n\n id);\n\n ret = qmp_fd(fixture->fd, cmd);\n\n val = qdict_get_qdict(ret, \"return\");\n\n count = qdict_get_int(val, \"count\");\n\n eof = qdict_get_bool(val, \"eof\");\n\n b64 = qdict_get_str(val, \"buf-b64\");\n\n g_assert_cmpint(count, ==, sizeof(helloworld));\n\n g_assert(eof);\n\n g_assert_cmpstr(b64, ==, enc);\n\n QDECREF(ret);\n\n g_free(cmd);\n\n g_free(enc);\n\n\n\n /* close */\n\n cmd = g_strdup_printf(\"{'execute': 'guest-file-close',\"\n\n \" 'arguments': {'handle': %\" PRId64 \"} }\",\n\n id);\n\n ret = qmp_fd(fixture->fd, cmd);\n\n QDECREF(ret);\n\n g_free(cmd);\n\n}\n", + "output": "0", + "index": 19469 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void vscsi_command_complete(SCSIBus *bus, int reason, uint32_t tag,\n\n uint32_t arg)\n\n{\n\n VSCSIState *s = DO_UPCAST(VSCSIState, vdev.qdev, bus->qbus.parent);\n\n vscsi_req *req = vscsi_find_req(s, tag);\n\n SCSIDevice *sdev;\n\n uint8_t *buf;\n\n int32_t res_in = 0, res_out = 0;\n\n int len, rc = 0;\n\n\n\n dprintf(\"VSCSI: SCSI cmd complete, r=0x%x tag=0x%x arg=0x%x, req=%p\\n\",\n\n reason, tag, arg, req);\n\n if (req == NULL) {\n\n fprintf(stderr, \"VSCSI: Can't find request for tag 0x%x\\n\", tag);\n\n return;\n\n }\n\n sdev = req->sdev;\n\n\n\n if (req->sensing) {\n\n if (reason == SCSI_REASON_DONE) {\n\n dprintf(\"VSCSI: Sense done !\\n\");\n\n vscsi_send_rsp(s, req, CHECK_CONDITION, 0, 0);\n\n vscsi_put_req(s, req);\n\n } else {\n\n uint8_t *buf = sdev->info->get_buf(sdev, tag);\n\n\n\n len = MIN(arg, SCSI_SENSE_BUF_SIZE);\n\n dprintf(\"VSCSI: Sense data, %d bytes:\\n\", len);\n\n dprintf(\" %02x %02x %02x %02x %02x %02x %02x %02x\\n\",\n\n buf[0], buf[1], buf[2], buf[3],\n\n buf[4], buf[5], buf[6], buf[7]);\n\n dprintf(\" %02x %02x %02x %02x %02x %02x %02x %02x\\n\",\n\n buf[8], buf[9], buf[10], buf[11],\n\n buf[12], buf[13], buf[14], buf[15]);\n\n memcpy(req->sense, buf, len);\n\n req->senselen = len;\n\n sdev->info->read_data(sdev, req->qtag);\n\n }\n\n return;\n\n }\n\n\n\n if (reason == SCSI_REASON_DONE) {\n\n dprintf(\"VSCSI: Command complete err=%d\\n\", arg);\n\n if (arg == 0) {\n\n /* We handle overflows, not underflows for normal commands,\n\n * but hopefully nobody cares\n\n */\n\n if (req->writing) {\n\n res_out = req->data_len;\n\n } else {\n\n res_in = req->data_len;\n\n }\n\n vscsi_send_rsp(s, req, 0, res_in, res_out);\n\n } else if (arg == CHECK_CONDITION) {\n\n dprintf(\"VSCSI: Got CHECK_CONDITION, requesting sense...\\n\");\n\n vscsi_send_request_sense(s, req);\n\n return;\n\n } else {\n\n vscsi_send_rsp(s, req, arg, 0, 0);\n\n }\n\n vscsi_put_req(s, req);\n\n return;\n\n }\n\n\n\n /* \"arg\" is how much we have read for reads and how much we want\n\n * to write for writes (ie, how much is to be DMA'd)\n\n */\n\n if (arg) {\n\n buf = sdev->info->get_buf(sdev, tag);\n\n rc = vscsi_srp_transfer_data(s, req, req->writing, buf, arg);\n\n }\n\n if (rc < 0) {\n\n fprintf(stderr, \"VSCSI: RDMA error rc=%d!\\n\", rc);\n\n sdev->info->cancel_io(sdev, req->qtag);\n\n vscsi_makeup_sense(s, req, HARDWARE_ERROR, 0, 0);\n\n vscsi_send_rsp(s, req, CHECK_CONDITION, 0, 0);\n\n vscsi_put_req(s, req);\n\n return;\n\n }\n\n\n\n /* Start next chunk */\n\n req->data_len -= rc;\n\n if (req->writing) {\n\n sdev->info->write_data(sdev, req->qtag);\n\n } else {\n\n sdev->info->read_data(sdev, req->qtag);\n\n }\n\n}\n", + "output": "1", + "index": 13748 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void put_pixels_x2_mmx(UINT8 *block, const UINT8 *pixels, int line_size, int h)\n\n{\n\n#if 0\n\n UINT8 *p;\n\n const UINT8 *pix;\n\n p = block;\n\n pix = pixels;\n\n MOVQ_ZERO(mm7);\n\n MOVQ_WONE(mm4);\n\n JUMPALIGN();\n\n do {\n\n __asm __volatile(\n\n\t\"movq\t%1, %%mm0\\n\\t\"\n\n\t\"movq\t1%1, %%mm1\\n\\t\"\n\n\t\"movq\t%%mm0, %%mm2\\n\\t\"\n\n\t\"movq\t%%mm1, %%mm3\\n\\t\"\n\n\t\"punpcklbw %%mm7, %%mm0\\n\\t\"\n\n\t\"punpcklbw %%mm7, %%mm1\\n\\t\"\n\n\t\"punpckhbw %%mm7, %%mm2\\n\\t\"\n\n\t\"punpckhbw %%mm7, %%mm3\\n\\t\"\n\n\t\"paddusw %%mm1, %%mm0\\n\\t\"\n\n\t\"paddusw %%mm3, %%mm2\\n\\t\"\n\n\t\"paddusw %%mm4, %%mm0\\n\\t\"\n\n\t\"paddusw %%mm4, %%mm2\\n\\t\"\n\n\t\"psrlw\t$1, %%mm0\\n\\t\"\n\n\t\"psrlw\t$1, %%mm2\\n\\t\"\n\n\t\"packuswb %%mm2, %%mm0\\n\\t\"\n\n\t\"movq\t%%mm0, %0\\n\\t\"\n\n\t:\"=m\"(*p)\n\n\t:\"m\"(*pix)\n\n\t\t :\"memory\");\n\n pix += line_size; p += line_size;\n\n } while (--h);\n\n#else\n\n __asm __volatile(\n\n \tMOVQ_BFE(%%mm7)\n\n\t\"lea (%3, %3), %%eax\t\\n\\t\"\n\n\t\".balign 8 \t\t\\n\\t\"\n\n\t\"1:\t\t\t\\n\\t\"\n\n\t\"movq (%1), %%mm0\t\\n\\t\"\n\n\t\"movq (%1, %3), %%mm2\t\\n\\t\"\n\n\t\"movq 1(%1), %%mm1\t\\n\\t\"\n\n\t\"movq 1(%1, %3), %%mm3\t\\n\\t\"\n\n\tPAVG_MMX(%%mm0, %%mm1)\n\n\t\"movq %%mm6, (%2)\t\\n\\t\"\n\n\tPAVG_MMX(%%mm2, %%mm3)\n\n\t\"movq %%mm6, (%2, %3)\t\\n\\t\"\n\n\t\"addl %%eax, %1\t\t\\n\\t\"\n\n\t\"addl %%eax, %2\t\t\\n\\t\"\n\n#if LONG_UNROLL\n\n\t\"movq (%1), %%mm0\t\\n\\t\"\n\n\t\"movq (%1, %3), %%mm2\t\\n\\t\"\n\n\t\"movq 1(%1), %%mm1\t\\n\\t\"\n\n\t\"movq 1(%1, %3), %%mm3\t\\n\\t\"\n\n\tPAVG_MMX(%%mm0, %%mm1)\n\n\t\"movq %%mm6, (%2)\t\\n\\t\"\n\n\tPAVG_MMX(%%mm2, %%mm3)\n\n\t\"movq %%mm6, (%2, %3)\t\\n\\t\"\n\n\t\"addl %%eax, %1\t\t\\n\\t\"\n\n\t\"addl %%eax, %2\t\t\\n\\t\"\n\n\t\"subl $4, %0\t\t\\n\\t\"\n\n#else\n\n\t\"subl $2, %0\t\t\\n\\t\"\n\n#endif\n\n\t\"jnz 1b\t\t\t\\n\\t\"\n\n\t:\"+g\"(h), \"+S\"(pixels), \"+D\"(block)\n\n\t:\"r\"(line_size)\n\n\t:\"eax\", \"memory\");\n\n#endif\n\n}\n", + "output": "0", + "index": 2271 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static uint64_t qemu_rdma_poll(RDMAContext *rdma, uint64_t *wr_id_out,\n\n uint32_t *byte_len)\n\n{\n\n int ret;\n\n struct ibv_wc wc;\n\n uint64_t wr_id;\n\n\n\n ret = ibv_poll_cq(rdma->cq, 1, &wc);\n\n\n\n if (!ret) {\n\n *wr_id_out = RDMA_WRID_NONE;\n\n return 0;\n\n }\n\n\n\n if (ret < 0) {\n\n fprintf(stderr, \"ibv_poll_cq return %d!\\n\", ret);\n\n return ret;\n\n }\n\n\n\n wr_id = wc.wr_id & RDMA_WRID_TYPE_MASK;\n\n\n\n if (wc.status != IBV_WC_SUCCESS) {\n\n fprintf(stderr, \"ibv_poll_cq wc.status=%d %s!\\n\",\n\n wc.status, ibv_wc_status_str(wc.status));\n\n fprintf(stderr, \"ibv_poll_cq wrid=%s!\\n\", wrid_desc[wr_id]);\n\n\n\n return -1;\n\n }\n\n\n\n if (rdma->control_ready_expected &&\n\n (wr_id >= RDMA_WRID_RECV_CONTROL)) {\n\n DDDPRINTF(\"completion %s #%\" PRId64 \" received (%\" PRId64 \")\"\n\n \" left %d\\n\", wrid_desc[RDMA_WRID_RECV_CONTROL],\n\n wr_id - RDMA_WRID_RECV_CONTROL, wr_id, rdma->nb_sent);\n\n rdma->control_ready_expected = 0;\n\n }\n\n\n\n if (wr_id == RDMA_WRID_RDMA_WRITE) {\n\n uint64_t chunk =\n\n (wc.wr_id & RDMA_WRID_CHUNK_MASK) >> RDMA_WRID_CHUNK_SHIFT;\n\n uint64_t index =\n\n (wc.wr_id & RDMA_WRID_BLOCK_MASK) >> RDMA_WRID_BLOCK_SHIFT;\n\n RDMALocalBlock *block = &(rdma->local_ram_blocks.block[index]);\n\n\n\n DDDPRINTF(\"completions %s (%\" PRId64 \") left %d, \"\n\n \"block %\" PRIu64 \", chunk: %\" PRIu64 \" %p %p\\n\",\n\n print_wrid(wr_id), wr_id, rdma->nb_sent, index, chunk,\n\n block->local_host_addr, (void *)block->remote_host_addr);\n\n\n\n clear_bit(chunk, block->transit_bitmap);\n\n\n\n if (rdma->nb_sent > 0) {\n\n rdma->nb_sent--;\n\n }\n\n\n\n if (!rdma->pin_all) {\n\n /*\n\n * FYI: If one wanted to signal a specific chunk to be unregistered\n\n * using LRU or workload-specific information, this is the function\n\n * you would call to do so. That chunk would then get asynchronously\n\n * unregistered later.\n\n */\n\n#ifdef RDMA_UNREGISTRATION_EXAMPLE\n\n qemu_rdma_signal_unregister(rdma, index, chunk, wc.wr_id);\n\n#endif\n\n }\n\n } else {\n\n DDDPRINTF(\"other completion %s (%\" PRId64 \") received left %d\\n\",\n\n print_wrid(wr_id), wr_id, rdma->nb_sent);\n\n }\n\n\n\n *wr_id_out = wc.wr_id;\n\n if (byte_len) {\n\n *byte_len = wc.byte_len;\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 11978 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static uint64_t get_cluster_offset(BlockDriverState *bs,\n\n uint64_t offset, int allocate)\n\n{\n\n BDRVVmdkState *s = bs->opaque;\n\n unsigned int l1_index, l2_offset, l2_index;\n\n int min_index, i, j;\n\n uint32_t min_count, *l2_table, tmp;\n\n uint64_t cluster_offset;\n\n \n\n l1_index = (offset >> 9) / s->l1_entry_sectors;\n\n if (l1_index >= s->l1_size)\n\n return 0;\n\n l2_offset = s->l1_table[l1_index];\n\n if (!l2_offset)\n\n return 0;\n\n for(i = 0; i < L2_CACHE_SIZE; i++) {\n\n if (l2_offset == s->l2_cache_offsets[i]) {\n\n /* increment the hit count */\n\n if (++s->l2_cache_counts[i] == 0xffffffff) {\n\n for(j = 0; j < L2_CACHE_SIZE; j++) {\n\n s->l2_cache_counts[j] >>= 1;\n\n }\n\n }\n\n l2_table = s->l2_cache + (i * s->l2_size);\n\n goto found;\n\n }\n\n }\n\n /* not found: load a new entry in the least used one */\n\n min_index = 0;\n\n min_count = 0xffffffff;\n\n for(i = 0; i < L2_CACHE_SIZE; i++) {\n\n if (s->l2_cache_counts[i] < min_count) {\n\n min_count = s->l2_cache_counts[i];\n\n min_index = i;\n\n }\n\n }\n\n l2_table = s->l2_cache + (min_index * s->l2_size);\n\n if (bdrv_pread(s->hd, (int64_t)l2_offset * 512, l2_table, s->l2_size * sizeof(uint32_t)) != \n\n s->l2_size * sizeof(uint32_t))\n\n return 0;\n\n\n\n s->l2_cache_offsets[min_index] = l2_offset;\n\n s->l2_cache_counts[min_index] = 1;\n\n found:\n\n l2_index = ((offset >> 9) / s->cluster_sectors) % s->l2_size;\n\n cluster_offset = le32_to_cpu(l2_table[l2_index]);\n\n if (!cluster_offset) {\n\n struct stat file_buf;\n\n\n\n if (!allocate)\n\n return 0;\n\n stat(s->hd->filename, &file_buf);\n\n cluster_offset = file_buf.st_size;\n\n bdrv_truncate(s->hd, cluster_offset + (s->cluster_sectors << 9));\n\n\n\n cluster_offset >>= 9;\n\n /* update L2 table */\n\n tmp = cpu_to_le32(cluster_offset);\n\n l2_table[l2_index] = tmp;\n\n if (bdrv_pwrite(s->hd, ((int64_t)l2_offset * 512) + (l2_index * sizeof(tmp)), \n\n &tmp, sizeof(tmp)) != sizeof(tmp))\n\n return 0;\n\n /* update backup L2 table */\n\n if (s->l1_backup_table_offset != 0) {\n\n l2_offset = s->l1_backup_table[l1_index];\n\n if (bdrv_pwrite(s->hd, ((int64_t)l2_offset * 512) + (l2_index * sizeof(tmp)), \n\n &tmp, sizeof(tmp)) != sizeof(tmp))\n\n return 0;\n\n }\n\n\n\n if (get_whole_cluster(bs, cluster_offset, offset, allocate) == -1)\n\n return 0;\n\n }\n\n cluster_offset <<= 9;\n\n return cluster_offset;\n\n}\n", + "output": "1", + "index": 20304 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,\n\n enum dshowDeviceType devtype, enum dshowSourceFilterType sourcetype, IBaseFilter **pfilter)\n\n{\n\n struct dshow_ctx *ctx = avctx->priv_data;\n\n IBaseFilter *device_filter = NULL;\n\n IEnumMoniker *classenum = NULL;\n\n IMoniker *m = NULL;\n\n const char *device_name = ctx->device_name[devtype];\n\n int skip = (devtype == VideoDevice) ? ctx->video_device_number\n\n : ctx->audio_device_number;\n\n int r;\n\n\n\n const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,\n\n &CLSID_AudioInputDeviceCategory };\n\n const char *devtypename = (devtype == VideoDevice) ? \"video\" : \"audio only\";\n\n const char *sourcetypename = (sourcetype == VideoSourceDevice) ? \"video\" : \"audio\";\n\n\n\n r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[sourcetype],\n\n (IEnumMoniker **) &classenum, 0);\n\n if (r != S_OK) {\n\n av_log(avctx, AV_LOG_ERROR, \"Could not enumerate %s devices (or none found).\\n\",\n\n devtypename);\n\n return AVERROR(EIO);\n\n }\n\n\n\n while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) {\n\n IPropertyBag *bag = NULL;\n\n char *friendly_name = NULL;\n\n char *unique_name = NULL;\n\n VARIANT var;\n\n IBindCtx *bind_ctx = NULL;\n\n LPOLESTR olestr = NULL;\n\n LPMALLOC co_malloc = NULL;\n\n int i;\n\n\n\n r = CoGetMalloc(1, &co_malloc);\n\n if (r = S_OK)\n\n goto fail1;\n\n r = CreateBindCtx(0, &bind_ctx);\n\n if (r != S_OK)\n\n goto fail1;\n\n /* GetDisplayname works for both video and audio, DevicePath doesn't */\n\n r = IMoniker_GetDisplayName(m, bind_ctx, NULL, &olestr);\n\n if (r != S_OK)\n\n goto fail1;\n\n unique_name = dup_wchar_to_utf8(olestr);\n\n /* replace ':' with '_' since we use : to delineate between sources */\n\n for (i = 0; i < strlen(unique_name); i++) {\n\n if (unique_name[i] == ':')\n\n unique_name[i] = '_';\n\n }\n\n\n\n r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag);\n\n if (r != S_OK)\n\n goto fail1;\n\n\n\n var.vt = VT_BSTR;\n\n r = IPropertyBag_Read(bag, L\"FriendlyName\", &var, NULL);\n\n if (r != S_OK)\n\n goto fail1;\n\n friendly_name = dup_wchar_to_utf8(var.bstrVal);\n\n\n\n if (pfilter) {\n\n if (strcmp(device_name, friendly_name) && strcmp(device_name, unique_name))\n\n goto fail1;\n\n\n\n if (!skip--) {\n\n r = IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter);\n\n if (r != S_OK) {\n\n av_log(avctx, AV_LOG_ERROR, \"Unable to BindToObject for %s\\n\", device_name);\n\n goto fail1;\n\n }\n\n }\n\n } else {\n\n av_log(avctx, AV_LOG_INFO, \" \\\"%s\\\"\\n\", friendly_name);\n\n av_log(avctx, AV_LOG_INFO, \" Alternative name \\\"%s\\\"\\n\", unique_name);\n\n }\n\n\n\nfail1:\n\n if (olestr && co_malloc)\n\n IMalloc_Free(co_malloc, olestr);\n\n if (bind_ctx)\n\n IBindCtx_Release(bind_ctx);\n\n av_free(friendly_name);\n\n av_free(unique_name);\n\n if (bag)\n\n IPropertyBag_Release(bag);\n\n IMoniker_Release(m);\n\n }\n\n\n\n IEnumMoniker_Release(classenum);\n\n\n\n if (pfilter) {\n\n if (!device_filter) {\n\n av_log(avctx, AV_LOG_ERROR, \"Could not find %s device with name [%s] among source devices of type %s.\\n\",\n\n devtypename, device_name, sourcetypename);\n\n return AVERROR(EIO);\n\n }\n\n *pfilter = device_filter;\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 20384 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void clear_context(MpegEncContext *s)\n\n{\n\n int i, j, k;\n\n\n\n memset(&s->next_picture, 0, sizeof(s->next_picture));\n\n memset(&s->last_picture, 0, sizeof(s->last_picture));\n\n memset(&s->current_picture, 0, sizeof(s->current_picture));\n\n memset(&s->new_picture, 0, sizeof(s->new_picture));\n\n\n\n memset(s->thread_context, 0, sizeof(s->thread_context));\n\n\n\n s->me.map = NULL;\n\n s->me.score_map = NULL;\n\n s->dct_error_sum = NULL;\n\n s->block = NULL;\n\n s->blocks = NULL;\n\n memset(s->pblocks, 0, sizeof(s->pblocks));\n\n s->ac_val_base = NULL;\n\n s->ac_val[0] =\n\n s->ac_val[1] =\n\n s->ac_val[2] =NULL;\n\n s->sc.edge_emu_buffer = NULL;\n\n s->me.scratchpad = NULL;\n\n s->me.temp =\n\n s->sc.rd_scratchpad =\n\n s->sc.b_scratchpad =\n\n s->sc.obmc_scratchpad = NULL;\n\n\n\n s->parse_context.buffer = NULL;\n\n s->parse_context.buffer_size = 0;\n\n\n s->bitstream_buffer = NULL;\n\n s->allocated_bitstream_buffer_size = 0;\n\n s->picture = NULL;\n\n s->mb_type = NULL;\n\n s->p_mv_table_base = NULL;\n\n s->b_forw_mv_table_base = NULL;\n\n s->b_back_mv_table_base = NULL;\n\n s->b_bidir_forw_mv_table_base = NULL;\n\n s->b_bidir_back_mv_table_base = NULL;\n\n s->b_direct_mv_table_base = NULL;\n\n s->p_mv_table = NULL;\n\n s->b_forw_mv_table = NULL;\n\n s->b_back_mv_table = NULL;\n\n s->b_bidir_forw_mv_table = NULL;\n\n s->b_bidir_back_mv_table = NULL;\n\n s->b_direct_mv_table = NULL;\n\n for (i = 0; i < 2; i++) {\n\n for (j = 0; j < 2; j++) {\n\n for (k = 0; k < 2; k++) {\n\n s->b_field_mv_table_base[i][j][k] = NULL;\n\n s->b_field_mv_table[i][j][k] = NULL;\n\n }\n\n s->b_field_select_table[i][j] = NULL;\n\n s->p_field_mv_table_base[i][j] = NULL;\n\n s->p_field_mv_table[i][j] = NULL;\n\n }\n\n s->p_field_select_table[i] = NULL;\n\n }\n\n\n\n s->dc_val_base = NULL;\n\n s->coded_block_base = NULL;\n\n s->mbintra_table = NULL;\n\n s->cbp_table = NULL;\n\n s->pred_dir_table = NULL;\n\n\n\n s->mbskip_table = NULL;\n\n\n\n s->er.error_status_table = NULL;\n\n s->er.er_temp_buffer = NULL;\n\n s->mb_index2xy = NULL;\n\n s->lambda_table = NULL;\n\n\n\n s->cplx_tab = NULL;\n\n s->bits_tab = NULL;\n\n}", + "output": "1", + "index": 24651 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q)\n\n{\n\n const char *rc_desc;\n\n mfxU16 rc_mode;\n\n\n\n int want_la = q->la_depth >= 0;\n\n int want_qscale = !!(avctx->flags & AV_CODEC_FLAG_QSCALE);\n\n int want_vcm = q->vcm;\n\n\n\n if (want_la && !QSV_HAVE_LA) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Lookahead ratecontrol mode requested, but is not supported by this SDK version\\n\");\n\n return AVERROR(ENOSYS);\n\n }\n\n if (want_vcm && !QSV_HAVE_VCM) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"VCM ratecontrol mode requested, but is not supported by this SDK version\\n\");\n\n return AVERROR(ENOSYS);\n\n }\n\n\n\n if (want_la + want_qscale + want_vcm > 1) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"More than one of: { constant qscale, lookahead, VCM } requested, \"\n\n \"only one of them can be used at a time.\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n if (want_qscale) {\n\n rc_mode = MFX_RATECONTROL_CQP;\n\n rc_desc = \"constant quantization parameter (CQP)\";\n\n }\n\n#if QSV_HAVE_VCM\n\n else if (want_vcm) {\n\n rc_mode = MFX_RATECONTROL_VCM;\n\n rc_desc = \"video conferencing mode (VCM)\";\n\n }\n\n#endif\n\n#if QSV_HAVE_LA\n\n else if (want_la) {\n\n rc_mode = MFX_RATECONTROL_LA;\n\n rc_desc = \"VBR with lookahead (LA)\";\n\n\n\n#if QSV_HAVE_ICQ\n\n if (avctx->global_quality > 0) {\n\n rc_mode = MFX_RATECONTROL_LA_ICQ;\n\n rc_desc = \"intelligent constant quality with lookahead (LA_ICQ)\";\n\n }\n\n#endif\n\n }\n\n#endif\n\n#if QSV_HAVE_ICQ\n\n else if (avctx->global_quality > 0) {\n\n rc_mode = MFX_RATECONTROL_ICQ;\n\n rc_desc = \"intelligent constant quality (ICQ)\";\n\n }\n\n#endif\n\n else if (avctx->rc_max_rate == avctx->bit_rate) {\n\n rc_mode = MFX_RATECONTROL_CBR;\n\n rc_desc = \"constant bitrate (CBR)\";\n\n } else if (!avctx->rc_max_rate) {\n\n rc_mode = MFX_RATECONTROL_AVBR;\n\n rc_desc = \"average variable bitrate (AVBR)\";\n\n } else {\n\n rc_mode = MFX_RATECONTROL_VBR;\n\n rc_desc = \"variable bitrate (VBR)\";\n\n }\n\n\n\n q->param.mfx.RateControlMethod = rc_mode;\n\n av_log(avctx, AV_LOG_VERBOSE, \"Using the %s ratecontrol method\\n\", rc_desc);\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 23100 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1,\n\n int width, int height, int bpno, int bandno,\n\n int seg_symbols, int vert_causal_ctx_csty_symbol)\n\n{\n\n int mask = 3 << (bpno - 1), y0, x, y, runlen, dec;\n\n\n\n for (y0 = 0; y0 < height; y0 += 4) {\n\n for (x = 0; x < width; x++) {\n\n int flags_mask = -1;\n\n if (vert_causal_ctx_csty_symbol)\n\n flags_mask &= ~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE | JPEG2000_T1_SGN_S);\n\n if (y0 + 3 < height &&\n\n !((t1->flags[y0 + 1][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||\n\n (t1->flags[y0 + 2][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||\n\n (t1->flags[y0 + 3][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||\n\n (t1->flags[y0 + 4][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG) & flags_mask))) {\n\n if (!ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL))\n\n continue;\n\n runlen = ff_mqc_decode(&t1->mqc,\n\n t1->mqc.cx_states + MQC_CX_UNI);\n\n runlen = (runlen << 1) | ff_mqc_decode(&t1->mqc,\n\n t1->mqc.cx_states +\n\n MQC_CX_UNI);\n\n dec = 1;\n\n } else {\n\n runlen = 0;\n\n dec = 0;\n\n }\n\n\n\n for (y = y0 + runlen; y < y0 + 4 && y < height; y++) {\n\n int flags_mask = -1;\n\n if (vert_causal_ctx_csty_symbol && y == y0 + 3)\n\n flags_mask &= ~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE | JPEG2000_T1_SGN_S);\n\n if (!dec) {\n\n if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))) {\n\n dec = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_jpeg2000_getsigctxno(t1->flags[y+1][x+1] & flags_mask,\n\n bandno));\n\n }\n\n }\n\n if (dec) {\n\n int xorbit;\n\n int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y + 1][x + 1] & flags_mask,\n\n &xorbit);\n\n t1->data[y][x] = (ff_mqc_decode(&t1->mqc,\n\n t1->mqc.cx_states + ctxno) ^\n\n xorbit)\n\n ? -mask : mask;\n\n ff_jpeg2000_set_significance(t1, x, y, t1->data[y][x] < 0);\n\n }\n\n dec = 0;\n\n t1->flags[y + 1][x + 1] &= ~JPEG2000_T1_VIS;\n\n }\n\n }\n\n }\n\n if (seg_symbols) {\n\n int val;\n\n val = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);\n\n val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);\n\n val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);\n\n val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);\n\n if (val != 0xa)\n\n av_log(s->avctx, AV_LOG_ERROR,\n\n \"Segmentation symbol value incorrect\\n\");\n\n }\n\n}\n", + "output": "0", + "index": 5722 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int alloc_tables(H264Context *h){\n\n MpegEncContext * const s = &h->s;\n\n const int big_mb_num= s->mb_stride * (s->mb_height+1);\n\n int x,y;\n\n\n\n CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t))\n\n\n\n CHECKED_ALLOCZ(h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t))\n\n CHECKED_ALLOCZ(h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(uint8_t))\n\n CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t))\n\n\n\n if( h->pps.cabac ) {\n\n CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t))\n\n CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t));\n\n CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t));\n\n CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t));\n\n }\n\n\n\n memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(uint8_t));\n\n h->slice_table= h->slice_table_base + s->mb_stride*2 + 1;\n\n\n\n CHECKED_ALLOCZ(h->mb2b_xy , big_mb_num * sizeof(uint32_t));\n\n CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint32_t));\n\n for(y=0; ymb_height; y++){\n\n for(x=0; xmb_width; x++){\n\n const int mb_xy= x + y*s->mb_stride;\n\n const int b_xy = 4*x + 4*y*h->b_stride;\n\n const int b8_xy= 2*x + 2*y*h->b8_stride;\n\n\n\n h->mb2b_xy [mb_xy]= b_xy;\n\n h->mb2b8_xy[mb_xy]= b8_xy;\n\n }\n\n }\n\n\n\n s->obmc_scratchpad = NULL;\n\n\n\n if(!h->dequant4_coeff[0])\n\n init_dequant_tables(h);\n\n\n\n return 0;\n\nfail:\n\n free_tables(h);\n\n return -1;\n\n}\n", + "output": "1", + "index": 19845 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int get_cluster_offset(BlockDriverState *bs,\n\n VmdkExtent *extent,\n\n VmdkMetaData *m_data,\n\n uint64_t offset,\n\n int allocate,\n\n uint64_t *cluster_offset)\n\n{\n\n unsigned int l1_index, l2_offset, l2_index;\n\n int min_index, i, j;\n\n uint32_t min_count, *l2_table, tmp = 0;\n\n\n\n if (m_data)\n\n m_data->valid = 0;\n\n if (extent->flat) {\n\n *cluster_offset = extent->flat_start_offset;\n\n return 0;\n\n }\n\n\n\n l1_index = (offset >> 9) / extent->l1_entry_sectors;\n\n if (l1_index >= extent->l1_size) {\n\n return -1;\n\n }\n\n l2_offset = extent->l1_table[l1_index];\n\n if (!l2_offset) {\n\n return -1;\n\n }\n\n for (i = 0; i < L2_CACHE_SIZE; i++) {\n\n if (l2_offset == extent->l2_cache_offsets[i]) {\n\n /* increment the hit count */\n\n if (++extent->l2_cache_counts[i] == 0xffffffff) {\n\n for (j = 0; j < L2_CACHE_SIZE; j++) {\n\n extent->l2_cache_counts[j] >>= 1;\n\n }\n\n }\n\n l2_table = extent->l2_cache + (i * extent->l2_size);\n\n goto found;\n\n }\n\n }\n\n /* not found: load a new entry in the least used one */\n\n min_index = 0;\n\n min_count = 0xffffffff;\n\n for (i = 0; i < L2_CACHE_SIZE; i++) {\n\n if (extent->l2_cache_counts[i] < min_count) {\n\n min_count = extent->l2_cache_counts[i];\n\n min_index = i;\n\n }\n\n }\n\n l2_table = extent->l2_cache + (min_index * extent->l2_size);\n\n if (bdrv_pread(\n\n extent->file,\n\n (int64_t)l2_offset * 512,\n\n l2_table,\n\n extent->l2_size * sizeof(uint32_t)\n\n ) != extent->l2_size * sizeof(uint32_t)) {\n\n return -1;\n\n }\n\n\n\n extent->l2_cache_offsets[min_index] = l2_offset;\n\n extent->l2_cache_counts[min_index] = 1;\n\n found:\n\n l2_index = ((offset >> 9) / extent->cluster_sectors) % extent->l2_size;\n\n *cluster_offset = le32_to_cpu(l2_table[l2_index]);\n\n\n\n if (!*cluster_offset) {\n\n if (!allocate) {\n\n return -1;\n\n }\n\n\n\n // Avoid the L2 tables update for the images that have snapshots.\n\n *cluster_offset = bdrv_getlength(extent->file);\n\n bdrv_truncate(\n\n extent->file,\n\n *cluster_offset + (extent->cluster_sectors << 9)\n\n );\n\n\n\n *cluster_offset >>= 9;\n\n tmp = cpu_to_le32(*cluster_offset);\n\n l2_table[l2_index] = tmp;\n\n\n\n /* First of all we write grain itself, to avoid race condition\n\n * that may to corrupt the image.\n\n * This problem may occur because of insufficient space on host disk\n\n * or inappropriate VM shutdown.\n\n */\n\n if (get_whole_cluster(\n\n bs, extent, *cluster_offset, offset, allocate) == -1)\n\n return -1;\n\n\n\n if (m_data) {\n\n m_data->offset = tmp;\n\n m_data->l1_index = l1_index;\n\n m_data->l2_index = l2_index;\n\n m_data->l2_offset = l2_offset;\n\n m_data->valid = 1;\n\n }\n\n }\n\n *cluster_offset <<= 9;\n\n return 0;\n\n}\n", + "output": "0", + "index": 3031 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],\n const int16_t *ubuf[2], const int16_t *vbuf[2],\n const int16_t *abuf[2], uint8_t *dest, int dstW,\n int yalpha, int uvalpha, int y,\n enum PixelFormat target, int hasAlpha)\n{\n const int16_t *buf0 = buf[0], *buf1 = buf[1],\n *ubuf0 = ubuf[0], *ubuf1 = ubuf[1],\n *vbuf0 = vbuf[0], *vbuf1 = vbuf[1],\n *abuf0 = hasAlpha ? abuf[0] : NULL,\n *abuf1 = hasAlpha ? abuf[1] : NULL;\n int yalpha1 = 4095 - yalpha;\n int uvalpha1 = 4095 - uvalpha;\n int i;\n for (i = 0; i < (dstW >> 1); i++) {\n int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;\n int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;\n int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;\n int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19;\n int A1, A2;\n const void *r = c->table_rV[V],\n *g = (c->table_gU[U] + c->table_gV[V]),\n *b = c->table_bU[U];\n if (hasAlpha) {\n A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19;\n A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19;\n }\n yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,\n r, g, b, y, target, hasAlpha);\n }\n}", + "output": "1", + "index": 11074 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int qemu_rdma_exchange_send(RDMAContext *rdma, RDMAControlHeader *head,\n\n uint8_t *data, RDMAControlHeader *resp,\n\n int *resp_idx,\n\n int (*callback)(RDMAContext *rdma))\n\n{\n\n int ret = 0;\n\n\n\n /*\n\n * Wait until the dest is ready before attempting to deliver the message\n\n * by waiting for a READY message.\n\n */\n\n if (rdma->control_ready_expected) {\n\n RDMAControlHeader resp;\n\n ret = qemu_rdma_exchange_get_response(rdma,\n\n &resp, RDMA_CONTROL_READY, RDMA_WRID_READY);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n }\n\n\n\n /*\n\n * If the user is expecting a response, post a WR in anticipation of it.\n\n */\n\n if (resp) {\n\n ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_DATA);\n\n if (ret) {\n\n fprintf(stderr, \"rdma migration: error posting\"\n\n \" extra control recv for anticipated result!\");\n\n return ret;\n\n }\n\n }\n\n\n\n /*\n\n * Post a WR to replace the one we just consumed for the READY message.\n\n */\n\n ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY);\n\n if (ret) {\n\n fprintf(stderr, \"rdma migration: error posting first control recv!\");\n\n return ret;\n\n }\n\n\n\n /*\n\n * Deliver the control message that was requested.\n\n */\n\n ret = qemu_rdma_post_send_control(rdma, data, head);\n\n\n\n if (ret < 0) {\n\n fprintf(stderr, \"Failed to send control buffer!\\n\");\n\n return ret;\n\n }\n\n\n\n /*\n\n * If we're expecting a response, block and wait for it.\n\n */\n\n if (resp) {\n\n if (callback) {\n\n DDPRINTF(\"Issuing callback before receiving response...\\n\");\n\n ret = callback(rdma);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n }\n\n\n\n DDPRINTF(\"Waiting for response %s\\n\", control_desc[resp->type]);\n\n ret = qemu_rdma_exchange_get_response(rdma, resp,\n\n resp->type, RDMA_WRID_DATA);\n\n\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n qemu_rdma_move_header(rdma, RDMA_WRID_DATA, resp);\n\n if (resp_idx) {\n\n *resp_idx = RDMA_WRID_DATA;\n\n }\n\n DDPRINTF(\"Response %s received.\\n\", control_desc[resp->type]);\n\n }\n\n\n\n rdma->control_ready_expected = 1;\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 23387 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int coroutine_fn backup_do_cow(BackupBlockJob *job,\n\n int64_t sector_num, int nb_sectors,\n\n bool *error_is_read,\n\n bool is_write_notifier)\n\n{\n\n BlockBackend *blk = job->common.blk;\n\n CowRequest cow_request;\n\n struct iovec iov;\n\n QEMUIOVector bounce_qiov;\n\n void *bounce_buffer = NULL;\n\n int ret = 0;\n\n int64_t sectors_per_cluster = cluster_size_sectors(job);\n\n int64_t start, end;\n\n int n;\n\n\n\n qemu_co_rwlock_rdlock(&job->flush_rwlock);\n\n\n\n start = sector_num / sectors_per_cluster;\n\n end = DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster);\n\n\n\n trace_backup_do_cow_enter(job, start, sector_num, nb_sectors);\n\n\n\n wait_for_overlapping_requests(job, start, end);\n\n cow_request_begin(&cow_request, job, start, end);\n\n\n\n for (; start < end; start++) {\n\n if (test_bit(start, job->done_bitmap)) {\n\n trace_backup_do_cow_skip(job, start);\n\n continue; /* already copied */\n\n }\n\n\n\n trace_backup_do_cow_process(job, start);\n\n\n\n n = MIN(sectors_per_cluster,\n\n job->common.len / BDRV_SECTOR_SIZE -\n\n start * sectors_per_cluster);\n\n\n\n if (!bounce_buffer) {\n\n bounce_buffer = blk_blockalign(blk, job->cluster_size);\n\n }\n\n iov.iov_base = bounce_buffer;\n\n iov.iov_len = n * BDRV_SECTOR_SIZE;\n\n qemu_iovec_init_external(&bounce_qiov, &iov, 1);\n\n\n\n ret = blk_co_preadv(blk, start * job->cluster_size,\n\n bounce_qiov.size, &bounce_qiov,\n\n is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0);\n\n if (ret < 0) {\n\n trace_backup_do_cow_read_fail(job, start, ret);\n\n if (error_is_read) {\n\n *error_is_read = true;\n\n }\n\n goto out;\n\n }\n\n\n\n if (buffer_is_zero(iov.iov_base, iov.iov_len)) {\n\n ret = blk_co_pwrite_zeroes(job->target, start * job->cluster_size,\n\n bounce_qiov.size, BDRV_REQ_MAY_UNMAP);\n\n } else {\n\n ret = blk_co_pwritev(job->target, start * job->cluster_size,\n\n bounce_qiov.size, &bounce_qiov, 0);\n\n }\n\n if (ret < 0) {\n\n trace_backup_do_cow_write_fail(job, start, ret);\n\n if (error_is_read) {\n\n *error_is_read = false;\n\n }\n\n goto out;\n\n }\n\n\n\n set_bit(start, job->done_bitmap);\n\n\n\n /* Publish progress, guest I/O counts as progress too. Note that the\n\n * offset field is an opaque progress value, it is not a disk offset.\n\n */\n\n job->sectors_read += n;\n\n job->common.offset += n * BDRV_SECTOR_SIZE;\n\n }\n\n\n\nout:\n\n if (bounce_buffer) {\n\n qemu_vfree(bounce_buffer);\n\n }\n\n\n\n cow_request_end(&cow_request);\n\n\n\n trace_backup_do_cow_return(job, sector_num, nb_sectors, ret);\n\n\n\n qemu_co_rwlock_unlock(&job->flush_rwlock);\n\n\n\n return ret;\n\n}\n", + "output": "0", + "index": 3750 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void do_ext_interrupt(CPUS390XState *env)\n\n{\n\n S390CPU *cpu = s390_env_get_cpu(env);\n\n uint64_t mask, addr;\n\n LowCore *lowcore;\n\n ExtQueue *q;\n\n\n\n if (!(env->psw.mask & PSW_MASK_EXT)) {\n\n cpu_abort(CPU(cpu), \"Ext int w/o ext mask\\n\");\n\n }\n\n\n\n lowcore = cpu_map_lowcore(env);\n\n\n\n if (env->pending_int & INTERRUPT_EXT_CLOCK_COMPARATOR) {\n\n lowcore->ext_int_code = cpu_to_be16(EXT_CLOCK_COMP);\n\n lowcore->cpu_addr = 0;\n\n env->pending_int &= ~INTERRUPT_EXT_CLOCK_COMPARATOR;\n\n } else if (env->pending_int & INTERRUPT_EXT_CPU_TIMER) {\n\n lowcore->ext_int_code = cpu_to_be16(EXT_CPU_TIMER);\n\n lowcore->cpu_addr = 0;\n\n env->pending_int &= ~INTERRUPT_EXT_CPU_TIMER;\n\n } else if (env->pending_int & INTERRUPT_EXT_SERVICE) {\n\n g_assert(env->ext_index >= 0);\n\n /*\n\n * FIXME: floating IRQs should be considered by all CPUs and\n\n * shuld not get cleared by CPU reset.\n\n */\n\n q = &env->ext_queue[env->ext_index];\n\n lowcore->ext_int_code = cpu_to_be16(q->code);\n\n lowcore->ext_params = cpu_to_be32(q->param);\n\n lowcore->ext_params2 = cpu_to_be64(q->param64);\n\n lowcore->cpu_addr = cpu_to_be16(env->core_id | VIRTIO_SUBCODE_64);\n\n env->ext_index--;\n\n if (env->ext_index == -1) {\n\n env->pending_int &= ~INTERRUPT_EXT_SERVICE;\n\n }\n\n } else {\n\n g_assert_not_reached();\n\n }\n\n\n\n mask = be64_to_cpu(lowcore->external_new_psw.mask);\n\n addr = be64_to_cpu(lowcore->external_new_psw.addr);\n\n lowcore->external_old_psw.mask = cpu_to_be64(get_psw_mask(env));\n\n lowcore->external_old_psw.addr = cpu_to_be64(env->psw.addr);\n\n\n\n cpu_unmap_lowcore(lowcore);\n\n\n\n DPRINTF(\"%s: %\" PRIx64 \" %\" PRIx64 \"\\n\", __func__,\n\n env->psw.mask, env->psw.addr);\n\n\n\n load_psw(env, mask, addr);\n\n}\n", + "output": "0", + "index": 7332 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static uint32_t stellaris_enet_read(void *opaque, target_phys_addr_t offset)\n\n{\n\n stellaris_enet_state *s = (stellaris_enet_state *)opaque;\n\n uint32_t val;\n\n\n\n switch (offset) {\n\n case 0x00: /* RIS */\n\n DPRINTF(\"IRQ status %02x\\n\", s->ris);\n\n return s->ris;\n\n case 0x04: /* IM */\n\n return s->im;\n\n case 0x08: /* RCTL */\n\n return s->rctl;\n\n case 0x0c: /* TCTL */\n\n return s->tctl;\n\n case 0x10: /* DATA */\n\n if (s->rx_fifo_len == 0) {\n\n if (s->np == 0) {\n\n BADF(\"RX underflow\\n\");\n\n return 0;\n\n }\n\n s->rx_fifo_len = s->rx[s->next_packet].len;\n\n s->rx_fifo = s->rx[s->next_packet].data;\n\n DPRINTF(\"RX FIFO start packet len=%d\\n\", s->rx_fifo_len);\n\n }\n\n val = s->rx_fifo[0] | (s->rx_fifo[1] << 8) | (s->rx_fifo[2] << 16)\n\n | (s->rx_fifo[3] << 24);\n\n s->rx_fifo += 4;\n\n s->rx_fifo_len -= 4;\n\n if (s->rx_fifo_len <= 0) {\n\n s->rx_fifo_len = 0;\n\n s->next_packet++;\n\n if (s->next_packet >= 31)\n\n s->next_packet = 0;\n\n s->np--;\n\n DPRINTF(\"RX done np=%d\\n\", s->np);\n\n }\n\n return val;\n\n case 0x14: /* IA0 */\n\n return s->macaddr[0] | (s->macaddr[1] << 8)\n\n | (s->macaddr[2] << 16) | (s->macaddr[3] << 24);\n\n case 0x18: /* IA1 */\n\n return s->macaddr[4] | (s->macaddr[5] << 8);\n\n case 0x1c: /* THR */\n\n return s->thr;\n\n case 0x20: /* MCTL */\n\n return s->mctl;\n\n case 0x24: /* MDV */\n\n return s->mdv;\n\n case 0x28: /* MADD */\n\n return 0;\n\n case 0x2c: /* MTXD */\n\n return s->mtxd;\n\n case 0x30: /* MRXD */\n\n return s->mrxd;\n\n case 0x34: /* NP */\n\n return s->np;\n\n case 0x38: /* TR */\n\n return 0;\n\n case 0x3c: /* Undocuented: Timestamp? */\n\n return 0;\n\n default:\n\n hw_error(\"stellaris_enet_read: Bad offset %x\\n\", (int)offset);\n\n return 0;\n\n }\n\n}\n", + "output": "0", + "index": 10923 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_subframe_lpc(ShortenContext *s, int command, int channel,\n\n int residual_size, int32_t coffset)\n\n{\n\n int pred_order, sum, qshift, init_sum, i, j;\n\n const int *coeffs;\n\n\n\n if (command == FN_QLPC) {\n\n /* read/validate prediction order */\n\n pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);\n\n if (pred_order > s->nwrap) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"invalid pred_order %d\\n\",\n\n pred_order);\n\n return AVERROR(EINVAL);\n\n }\n\n /* read LPC coefficients */\n\n for (i = 0; i < pred_order; i++)\n\n s->coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);\n\n coeffs = s->coeffs;\n\n\n\n qshift = LPCQUANT;\n\n } else {\n\n /* fixed LPC coeffs */\n\n pred_order = command;\n\n if (pred_order >= FF_ARRAY_ELEMS(fixed_coeffs)) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"invalid pred_order %d\\n\",\n\n pred_order);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n coeffs = fixed_coeffs[pred_order];\n\n qshift = 0;\n\n }\n\n\n\n /* subtract offset from previous samples to use in prediction */\n\n if (command == FN_QLPC && coffset)\n\n for (i = -pred_order; i < 0; i++)\n\n s->decoded[channel][i] -= coffset;\n\n\n\n /* decode residual and do LPC prediction */\n\n init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset;\n\n for (i = 0; i < s->blocksize; i++) {\n\n sum = init_sum;\n\n for (j = 0; j < pred_order; j++)\n\n sum += coeffs[j] * s->decoded[channel][i - j - 1];\n\n s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) +\n\n (sum >> qshift);\n\n }\n\n\n\n /* add offset to current samples */\n\n if (command == FN_QLPC && coffset)\n\n for (i = 0; i < s->blocksize; i++)\n\n s->decoded[channel][i] += coffset;\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 7373 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int64_t calculate_mode_score(CinepakEncContext *s, CinepakMode mode, int h, int v1_size, int v4_size, int v4, strip_info *info)\n\n{\n\n //score = FF_LAMBDA_SCALE * error + lambda * bits\n\n int x;\n\n int entry_size = s->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4;\n\n int mb_count = s->w * h / MB_AREA;\n\n mb_info *mb;\n\n int64_t score1, score2, score3;\n\n int64_t ret = s->lambda * ((v1_size ? CHUNK_HEADER_SIZE + v1_size * entry_size : 0) +\n\n (v4_size ? CHUNK_HEADER_SIZE + v4_size * entry_size : 0) +\n\n CHUNK_HEADER_SIZE) << 3;\n\n\n\n //av_log(s->avctx, AV_LOG_INFO, \"sizes %3i %3i -> %9li score mb_count %i\", v1_size, v4_size, ret, mb_count);\n\n\n\n switch(mode) {\n\n case MODE_V1_ONLY:\n\n //one byte per MB\n\n ret += s->lambda * 8 * mb_count;\n\n\n\n for(x = 0; x < mb_count; x++) {\n\n mb = &s->mb[x];\n\n ret += FF_LAMBDA_SCALE * mb->v1_error;\n\n mb->best_encoding = ENC_V1;\n\n }\n\n\n\n break;\n\n case MODE_V1_V4:\n\n //9 or 33 bits per MB\n\n for(x = 0; x < mb_count; x++) {\n\n mb = &s->mb[x];\n\n score1 = s->lambda * 9 + FF_LAMBDA_SCALE * mb->v1_error;\n\n score2 = s->lambda * 33 + FF_LAMBDA_SCALE * mb->v4_error[v4];\n\n\n\n if(score1 <= score2) {\n\n ret += score1;\n\n mb->best_encoding = ENC_V1;\n\n } else {\n\n ret += score2;\n\n mb->best_encoding = ENC_V4;\n\n }\n\n }\n\n\n\n break;\n\n case MODE_MC:\n\n //1, 10 or 34 bits per MB\n\n for(x = 0; x < mb_count; x++) {\n\n mb = &s->mb[x];\n\n score1 = s->lambda * 1 + FF_LAMBDA_SCALE * mb->skip_error;\n\n score2 = s->lambda * 10 + FF_LAMBDA_SCALE * mb->v1_error;\n\n score3 = s->lambda * 34 + FF_LAMBDA_SCALE * mb->v4_error[v4];\n\n\n\n\n\n if(score1 <= score2 && score1 <= score3) {\n\n ret += score1;\n\n mb->best_encoding = ENC_SKIP;\n\n } else if(score2 <= score1 && score2 <= score3) {\n\n ret += score2;\n\n mb->best_encoding = ENC_V1;\n\n } else {\n\n ret += score3;\n\n mb->best_encoding = ENC_V4;\n\n }\n\n }\n\n\n\n break;\n\n }\n\n\n\n return ret;\n\n}\n", + "output": "1", + "index": 10458 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int sd_open(BlockDriverState *bs, const char *filename, int flags)\n\n{\n\n int ret, fd;\n\n uint32_t vid = 0;\n\n BDRVSheepdogState *s = bs->opaque;\n\n char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN];\n\n uint32_t snapid;\n\n char *buf = NULL;\n\n\n\n strstart(filename, \"sheepdog:\", (const char **)&filename);\n\n\n\n QLIST_INIT(&s->inflight_aio_head);\n\n QLIST_INIT(&s->pending_aio_head);\n\n s->fd = -1;\n\n\n\n memset(vdi, 0, sizeof(vdi));\n\n memset(tag, 0, sizeof(tag));\n\n if (parse_vdiname(s, filename, vdi, &snapid, tag) < 0) {\n\n ret = -EINVAL;\n\n goto out;\n\n }\n\n s->fd = get_sheep_fd(s);\n\n if (s->fd < 0) {\n\n ret = s->fd;\n\n goto out;\n\n }\n\n\n\n ret = find_vdi_name(s, vdi, snapid, tag, &vid, 0);\n\n if (ret) {\n\n goto out;\n\n }\n\n\n\n /*\n\n * QEMU block layer emulates writethrough cache as 'writeback + flush', so\n\n * we always set SD_FLAG_CMD_CACHE (writeback cache) as default.\n\n */\n\n s->cache_flags = SD_FLAG_CMD_CACHE;\n\n if (flags & BDRV_O_NOCACHE) {\n\n s->cache_flags = SD_FLAG_CMD_DIRECT;\n\n }\n\n\n\n if (s->cache_flags == SD_FLAG_CMD_CACHE) {\n\n s->flush_fd = connect_to_sdog(s->addr, s->port);\n\n if (s->flush_fd < 0) {\n\n error_report(\"failed to connect\");\n\n ret = s->flush_fd;\n\n goto out;\n\n }\n\n }\n\n\n\n if (snapid || tag[0] != '\\0') {\n\n dprintf(\"%\" PRIx32 \" snapshot inode was open.\\n\", vid);\n\n s->is_snapshot = true;\n\n }\n\n\n\n fd = connect_to_sdog(s->addr, s->port);\n\n if (fd < 0) {\n\n error_report(\"failed to connect\");\n\n ret = fd;\n\n goto out;\n\n }\n\n\n\n buf = g_malloc(SD_INODE_SIZE);\n\n ret = read_object(fd, buf, vid_to_vdi_oid(vid), 0, SD_INODE_SIZE, 0,\n\n s->cache_flags);\n\n\n\n closesocket(fd);\n\n\n\n if (ret) {\n\n goto out;\n\n }\n\n\n\n memcpy(&s->inode, buf, sizeof(s->inode));\n\n s->min_dirty_data_idx = UINT32_MAX;\n\n s->max_dirty_data_idx = 0;\n\n\n\n bs->total_sectors = s->inode.vdi_size / SECTOR_SIZE;\n\n pstrcpy(s->name, sizeof(s->name), vdi);\n\n qemu_co_mutex_init(&s->lock);\n\n g_free(buf);\n\n return 0;\n\nout:\n\n qemu_aio_set_fd_handler(s->fd, NULL, NULL, NULL, NULL);\n\n if (s->fd >= 0) {\n\n closesocket(s->fd);\n\n }\n\n g_free(buf);\n\n return ret;\n\n}\n", + "output": "0", + "index": 15909 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void setup_rt_frame(int sig, struct target_sigaction *ka,\n\n target_siginfo_t *info,\n\n target_sigset_t *set, CPUOpenRISCState *env)\n\n{\n\n int err = 0;\n\n abi_ulong frame_addr;\n\n unsigned long return_ip;\n\n struct target_rt_sigframe *frame;\n\n abi_ulong info_addr, uc_addr;\n\n\n\n frame_addr = get_sigframe(ka, env, sizeof(*frame));\n\n if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {\n\n goto give_sigsegv;\n\n }\n\n\n\n info_addr = frame_addr + offsetof(struct target_rt_sigframe, info);\n\n __put_user(info_addr, &frame->pinfo);\n\n uc_addr = frame_addr + offsetof(struct target_rt_sigframe, uc);\n\n __put_user(uc_addr, &frame->puc);\n\n\n\n if (ka->sa_flags & SA_SIGINFO) {\n\n copy_siginfo_to_user(&frame->info, info);\n\n }\n\n\n\n /*err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));*/\n\n __put_user(0, &frame->uc.tuc_flags);\n\n __put_user(0, &frame->uc.tuc_link);\n\n __put_user(target_sigaltstack_used.ss_sp,\n\n &frame->uc.tuc_stack.ss_sp);\n\n __put_user(sas_ss_flags(env->gpr[1]), &frame->uc.tuc_stack.ss_flags);\n\n __put_user(target_sigaltstack_used.ss_size,\n\n &frame->uc.tuc_stack.ss_size);\n\n err |= setup_sigcontext(&frame->sc, env, set->sig[0]);\n\n\n\n /*err |= copy_to_user(frame->uc.tuc_sigmask, set, sizeof(*set));*/\n\n\n\n if (err) {\n\n goto give_sigsegv;\n\n }\n\n\n\n /* trampoline - the desired return ip is the retcode itself */\n\n return_ip = (unsigned long)&frame->retcode;\n\n /* This is l.ori r11,r0,__NR_sigreturn, l.sys 1 */\n\n __put_user(0xa960, (short *)(frame->retcode + 0));\n\n __put_user(TARGET_NR_rt_sigreturn, (short *)(frame->retcode + 2));\n\n __put_user(0x20000001, (unsigned long *)(frame->retcode + 4));\n\n __put_user(0x15000000, (unsigned long *)(frame->retcode + 8));\n\n\n\n if (err) {\n\n goto give_sigsegv;\n\n }\n\n\n\n /* TODO what is the current->exec_domain stuff and invmap ? */\n\n\n\n /* Set up registers for signal handler */\n\n env->pc = (unsigned long)ka->_sa_handler; /* what we enter NOW */\n\n env->gpr[9] = (unsigned long)return_ip; /* what we enter LATER */\n\n env->gpr[3] = (unsigned long)sig; /* arg 1: signo */\n\n env->gpr[4] = (unsigned long)&frame->info; /* arg 2: (siginfo_t*) */\n\n env->gpr[5] = (unsigned long)&frame->uc; /* arg 3: ucontext */\n\n\n\n /* actually move the usp to reflect the stacked frame */\n\n env->gpr[1] = (unsigned long)frame;\n\n\n\n return;\n\n\n\ngive_sigsegv:\n\n unlock_user_struct(frame, frame_addr, 1);\n\n if (sig == TARGET_SIGSEGV) {\n\n ka->_sa_handler = TARGET_SIG_DFL;\n\n }\n\n force_sig(TARGET_SIGSEGV);\n\n}\n", + "output": "0", + "index": 15540 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "_syscall3(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode)\n\n#endif\n\n#if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)\n\n_syscall3(int,sys_fchmodat,int,dirfd,const char *,pathname, mode_t,mode)\n\n#endif\n\n#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) && defined(USE_UID16)\n\n_syscall5(int,sys_fchownat,int,dirfd,const char *,pathname,\n\n uid_t,owner,gid_t,group,int,flags)\n\n#endif\n\n#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \\\n\n defined(__NR_fstatat64)\n\n_syscall4(int,sys_fstatat64,int,dirfd,const char *,pathname,\n\n struct stat *,buf,int,flags)\n\n#endif\n\n#if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)\n\n_syscall3(int,sys_futimesat,int,dirfd,const char *,pathname,\n\n const struct timeval *,times)\n\n#endif\n\n#if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \\\n\n defined(__NR_newfstatat)\n\n_syscall4(int,sys_newfstatat,int,dirfd,const char *,pathname,\n\n struct stat *,buf,int,flags)\n\n#endif\n\n#if defined(TARGET_NR_linkat) && defined(__NR_linkat)\n\n_syscall5(int,sys_linkat,int,olddirfd,const char *,oldpath,\n\n int,newdirfd,const char *,newpath,int,flags)\n\n#endif\n\n#if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)\n\n_syscall3(int,sys_mkdirat,int,dirfd,const char *,pathname,mode_t,mode)\n\n#endif\n\n#if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)\n\n_syscall4(int,sys_mknodat,int,dirfd,const char *,pathname,\n\n mode_t,mode,dev_t,dev)\n\n#endif\n\n#if defined(TARGET_NR_openat) && defined(__NR_openat)\n\n_syscall4(int,sys_openat,int,dirfd,const char *,pathname,int,flags,mode_t,mode)\n\n#endif\n\n#if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)\n\n_syscall4(int,sys_readlinkat,int,dirfd,const char *,pathname,\n\n char *,buf,size_t,bufsize)\n\n#endif\n\n#if defined(TARGET_NR_renameat) && defined(__NR_renameat)\n\n_syscall4(int,sys_renameat,int,olddirfd,const char *,oldpath,\n\n int,newdirfd,const char *,newpath)\n\n#endif\n\n#if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)\n\n_syscall3(int,sys_symlinkat,const char *,oldpath,\n\n int,newdirfd,const char *,newpath)\n\n#endif\n\n#if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)\n\n_syscall3(int,sys_unlinkat,int,dirfd,const char *,pathname,int,flags)\n\n#endif\n\n\n\n#endif /* CONFIG_ATFILE */\n\n\n\n#ifdef CONFIG_UTIMENSAT\n\nstatic int sys_utimensat(int dirfd, const char *pathname,\n\n const struct timespec times[2], int flags)\n\n{\n\n if (pathname == NULL)\n\n return futimens(dirfd, times);\n\n else\n\n return utimensat(dirfd, pathname, times, flags);\n\n}\n", + "output": "0", + "index": 16307 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,\n\n const char *version, const char *serial, const char *model,\n\n uint64_t wwn)\n\n{\n\n int cylinders, heads, secs;\n\n uint64_t nb_sectors;\n\n\n\n s->bs = bs;\n\n s->drive_kind = kind;\n\n\n\n bdrv_get_geometry(bs, &nb_sectors);\n\n bdrv_guess_geometry(bs, &cylinders, &heads, &secs);\n\n if (cylinders < 1 || cylinders > 16383) {\n\n error_report(\"cyls must be between 1 and 16383\");\n\n return -1;\n\n }\n\n if (heads < 1 || heads > 16) {\n\n error_report(\"heads must be between 1 and 16\");\n\n return -1;\n\n }\n\n if (secs < 1 || secs > 63) {\n\n error_report(\"secs must be between 1 and 63\");\n\n return -1;\n\n }\n\n s->cylinders = cylinders;\n\n s->heads = heads;\n\n s->sectors = secs;\n\n s->nb_sectors = nb_sectors;\n\n s->wwn = wwn;\n\n /* The SMART values should be preserved across power cycles\n\n but they aren't. */\n\n s->smart_enabled = 1;\n\n s->smart_autosave = 1;\n\n s->smart_errors = 0;\n\n s->smart_selftest_count = 0;\n\n if (kind == IDE_CD) {\n\n bdrv_set_dev_ops(bs, &ide_cd_block_ops, s);\n\n bdrv_set_buffer_alignment(bs, 2048);\n\n } else {\n\n if (!bdrv_is_inserted(s->bs)) {\n\n error_report(\"Device needs media, but drive is empty\");\n\n return -1;\n\n }\n\n if (bdrv_is_read_only(bs)) {\n\n error_report(\"Can't use a read-only drive\");\n\n return -1;\n\n }\n\n }\n\n if (serial) {\n\n pstrcpy(s->drive_serial_str, sizeof(s->drive_serial_str), serial);\n\n } else {\n\n snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),\n\n \"QM%05d\", s->drive_serial);\n\n }\n\n if (model) {\n\n pstrcpy(s->drive_model_str, sizeof(s->drive_model_str), model);\n\n } else {\n\n switch (kind) {\n\n case IDE_CD:\n\n strcpy(s->drive_model_str, \"QEMU DVD-ROM\");\n\n break;\n\n case IDE_CFATA:\n\n strcpy(s->drive_model_str, \"QEMU MICRODRIVE\");\n\n break;\n\n default:\n\n strcpy(s->drive_model_str, \"QEMU HARDDISK\");\n\n break;\n\n }\n\n }\n\n\n\n if (version) {\n\n pstrcpy(s->version, sizeof(s->version), version);\n\n } else {\n\n pstrcpy(s->version, sizeof(s->version), qemu_get_version());\n\n }\n\n\n\n ide_reset(s);\n\n bdrv_iostatus_enable(bs);\n\n return 0;\n\n}\n", + "output": "0", + "index": 2981 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void async_complete(void *opaque)\n\n{\n\n USBHostDevice *s = opaque;\n\n AsyncURB *aurb;\n\n int urbs = 0;\n\n\n\n while (1) {\n\n USBPacket *p;\n\n\n\n int r = ioctl(s->fd, USBDEVFS_REAPURBNDELAY, &aurb);\n\n if (r < 0) {\n\n if (errno == EAGAIN) {\n\n if (urbs > 2) {\n\n fprintf(stderr, \"husb: %d iso urbs finished at once\\n\", urbs);\n\n }\n\n return;\n\n }\n\n if (errno == ENODEV && !s->closing) {\n\n do_disconnect(s);\n\n return;\n\n }\n\n\n\n DPRINTF(\"husb: async. reap urb failed errno %d\\n\", errno);\n\n return;\n\n }\n\n\n\n DPRINTF(\"husb: async completed. aurb %p status %d alen %d\\n\",\n\n aurb, aurb->urb.status, aurb->urb.actual_length);\n\n\n\n /* If this is a buffered iso urb mark it as complete and don't do\n\n anything else (it is handled further in usb_host_handle_iso_data) */\n\n if (aurb->iso_frame_idx == -1) {\n\n int inflight;\n\n if (aurb->urb.status == -EPIPE) {\n\n set_halt(s, aurb->urb.endpoint & 0xf);\n\n }\n\n aurb->iso_frame_idx = 0;\n\n urbs++;\n\n inflight = change_iso_inflight(s, aurb->urb.endpoint & 0xf, -1);\n\n if (inflight == 0 && is_iso_started(s, aurb->urb.endpoint & 0xf)) {\n\n fprintf(stderr, \"husb: out of buffers for iso stream\\n\");\n\n }\n\n continue;\n\n }\n\n\n\n p = aurb->packet;\n\n\n\n if (p) {\n\n switch (aurb->urb.status) {\n\n case 0:\n\n p->len += aurb->urb.actual_length;\n\n break;\n\n\n\n case -EPIPE:\n\n set_halt(s, p->devep);\n\n p->len = USB_RET_STALL;\n\n break;\n\n\n\n default:\n\n p->len = USB_RET_NAK;\n\n break;\n\n }\n\n\n\n if (aurb->urb.type == USBDEVFS_URB_TYPE_CONTROL) {\n\n usb_generic_async_ctrl_complete(&s->dev, p);\n\n } else if (!aurb->more) {\n\n usb_packet_complete(&s->dev, p);\n\n }\n\n }\n\n\n\n async_free(aurb);\n\n }\n\n}\n", + "output": "1", + "index": 21009 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)\n\n{\n\n VideoData *s = s1->priv_data;\n\n int ret, first_index, last_index;\n\n char buf[1024];\n\n ByteIOContext pb1, *f = &pb1;\n\n AVStream *st;\n\n\n\n st = av_new_stream(s1, 0);\n\n if (!st) {\n\n av_free(s);\n\n return -ENOMEM;\n\n }\n\n\n\n if (ap->image_format)\n\n s->img_fmt = ap->image_format;\n\n\n\n pstrcpy(s->path, sizeof(s->path), s1->filename);\n\n s->img_number = 0;\n\n s->img_count = 0;\n\n\n\n /* find format */\n\n if (s1->iformat->flags & AVFMT_NOFILE)\n\n s->is_pipe = 0;\n\n else\n\n s->is_pipe = 1;\n\n\n\n if (!ap->time_base.num) {\n\n st->codec->time_base= (AVRational){1,25};\n\n } else {\n\n st->codec->time_base= ap->time_base;\n\n }\n\n\n\n if (!s->is_pipe) {\n\n if (find_image_range(&first_index, &last_index, s->path) < 0)\n\n goto fail;\n\n s->img_first = first_index;\n\n s->img_last = last_index;\n\n s->img_number = first_index;\n\n /* compute duration */\n\n st->start_time = 0;\n\n st->duration = last_index - first_index + 1;\n\n if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)\n\n goto fail;\n\n if (url_fopen(f, buf, URL_RDONLY) < 0)\n\n goto fail;\n\n } else {\n\n f = &s1->pb;\n\n }\n\n\n\n ret = av_read_image(f, s1->filename, s->img_fmt, read_header_alloc_cb, s);\n\n if (ret < 0)\n\n goto fail1;\n\n\n\n if (!s->is_pipe) {\n\n url_fclose(f);\n\n } else {\n\n url_fseek(f, 0, SEEK_SET);\n\n }\n\n\n\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n\n st->codec->codec_id = CODEC_ID_RAWVIDEO;\n\n st->codec->width = s->width;\n\n st->codec->height = s->height;\n\n st->codec->pix_fmt = s->pix_fmt;\n\n s->img_size = avpicture_get_size(s->pix_fmt, (s->width+15)&(~15), (s->height+15)&(~15));\n\n\n\n return 0;\n\n fail1:\n\n if (!s->is_pipe)\n\n url_fclose(f);\n\n fail:\n\n av_free(s);\n\n return AVERROR_IO;\n\n}\n", + "output": "1", + "index": 17372 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void ppc_hw_interrupt (CPUPPCState *env)\n\n{\n\n int raised = 0;\n\n\n\n#if 1\n\n if (loglevel & CPU_LOG_INT) {\n\n fprintf(logfile, \"%s: %p pending %08x req %08x me %d ee %d\\n\",\n\n __func__, env, env->pending_interrupts,\n\n env->interrupt_request, msr_me, msr_ee);\n\n }\n\n#endif\n\n /* Raise it */\n\n if (env->pending_interrupts & (1 << PPC_INTERRUPT_RESET)) {\n\n /* External reset / critical input */\n\n /* XXX: critical input should be handled another way.\n\n * This code is not correct !\n\n */\n\n env->exception_index = EXCP_RESET;\n\n env->pending_interrupts &= ~(1 << PPC_INTERRUPT_RESET);\n\n raised = 1;\n\n }\n\n if (raised == 0 && msr_me != 0) {\n\n /* Machine check exception */\n\n if (env->pending_interrupts & (1 << PPC_INTERRUPT_MCK)) {\n\n env->exception_index = EXCP_MACHINE_CHECK;\n\n env->pending_interrupts &= ~(1 << PPC_INTERRUPT_MCK);\n\n raised = 1;\n\n }\n\n }\n\n if (raised == 0 && msr_ee != 0) {\n\n#if defined(TARGET_PPC64H) /* PowerPC 64 with hypervisor mode support */\n\n /* Hypervisor decrementer exception */\n\n if (env->pending_interrupts & (1 << PPC_INTERRUPT_HDECR)) {\n\n env->exception_index = EXCP_HDECR;\n\n env->pending_interrupts &= ~(1 << PPC_INTERRUPT_HDECR);\n\n raised = 1;\n\n } else\n\n#endif\n\n /* Decrementer exception */\n\n if (env->pending_interrupts & (1 << PPC_INTERRUPT_DECR)) {\n\n env->exception_index = EXCP_DECR;\n\n env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DECR);\n\n raised = 1;\n\n /* Programmable interval timer on embedded PowerPC */\n\n } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_PIT)) {\n\n env->exception_index = EXCP_40x_PIT;\n\n env->pending_interrupts &= ~(1 << PPC_INTERRUPT_PIT);\n\n raised = 1;\n\n /* Fixed interval timer on embedded PowerPC */\n\n } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_FIT)) {\n\n env->exception_index = EXCP_40x_FIT;\n\n env->pending_interrupts &= ~(1 << PPC_INTERRUPT_FIT);\n\n raised = 1;\n\n /* Watchdog timer on embedded PowerPC */\n\n } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_WDT)) {\n\n env->exception_index = EXCP_40x_WATCHDOG;\n\n env->pending_interrupts &= ~(1 << PPC_INTERRUPT_WDT);\n\n raised = 1;\n\n /* External interrupt */\n\n } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_EXT)) {\n\n env->exception_index = EXCP_EXTERNAL;\n\n /* Taking an external interrupt does not clear the external\n\n * interrupt status\n\n */\n\n#if 0\n\n env->pending_interrupts &= ~(1 << PPC_INTERRUPT_EXT);\n\n#endif\n\n raised = 1;\n\n#if 0 // TODO\n\n /* Thermal interrupt */\n\n } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_THERM)) {\n\n env->exception_index = EXCP_970_THRM;\n\n env->pending_interrupts &= ~(1 << PPC_INTERRUPT_THERM);\n\n raised = 1;\n\n#endif\n\n }\n\n#if 0 // TODO\n\n /* External debug exception */\n\n } else if (env->pending_interrupts & (1 << PPC_INTERRUPT_DEBUG)) {\n\n env->exception_index = EXCP_xxx;\n\n env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DEBUG);\n\n raised = 1;\n\n#endif\n\n }\n\n if (raised != 0) {\n\n env->error_code = 0;\n\n do_interrupt(env);\n\n }\n\n}\n", + "output": "0", + "index": 18619 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void update_stream_timings(AVFormatContext *ic)\n\n{\n\n int64_t start_time, start_time1, start_time_text, end_time, end_time1;\n\n int64_t duration, duration1, filesize;\n\n int i;\n\n AVStream *st;\n\n AVProgram *p;\n\n\n\n start_time = INT64_MAX;\n\n start_time_text = INT64_MAX;\n\n end_time = INT64_MIN;\n\n duration = INT64_MIN;\n\n for(i = 0;i < ic->nb_streams; i++) {\n\n st = ic->streams[i];\n\n if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) {\n\n start_time1= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q);\n\n if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codec->codec_type == AVMEDIA_TYPE_DATA) {\n\n if (start_time1 < start_time_text)\n\n start_time_text = start_time1;\n\n } else\n\n start_time = FFMIN(start_time, start_time1);\n\n end_time1 = AV_NOPTS_VALUE;\n\n if (st->duration != AV_NOPTS_VALUE) {\n\n end_time1 = start_time1\n\n + av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q);\n\n end_time = FFMAX(end_time, end_time1);\n\n }\n\n for(p = NULL; (p = av_find_program_from_stream(ic, p, i)); ){\n\n if(p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1)\n\n p->start_time = start_time1;\n\n if(p->end_time < end_time1)\n\n p->end_time = end_time1;\n\n }\n\n }\n\n if (st->duration != AV_NOPTS_VALUE) {\n\n duration1 = av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q);\n\n duration = FFMAX(duration, duration1);\n\n }\n\n }\n\n if (start_time == INT64_MAX || (start_time > start_time_text && start_time - start_time_text < AV_TIME_BASE))\n\n start_time = start_time_text;\n\n else if(start_time > start_time_text)\n\n av_log(ic, AV_LOG_VERBOSE, \"Ignoring outlier non primary stream starttime %f\\n\", start_time_text / (float)AV_TIME_BASE);\n\n\n\n if (start_time != INT64_MAX) {\n\n ic->start_time = start_time;\n\n if (end_time != INT64_MIN) {\n\n if (ic->nb_programs) {\n\n for (i=0; inb_programs; i++) {\n\n p = ic->programs[i];\n\n if(p->start_time != AV_NOPTS_VALUE && p->end_time > p->start_time)\n\n duration = FFMAX(duration, p->end_time - p->start_time);\n\n }\n\n } else\n\n duration = FFMAX(duration, end_time - start_time);\n\n }\n\n }\n\n if (duration != INT64_MIN && duration > 0 && ic->duration == AV_NOPTS_VALUE) {\n\n ic->duration = duration;\n\n }\n\n if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration != AV_NOPTS_VALUE) {\n\n /* compute the bitrate */\n\n ic->bit_rate = (double)filesize * 8.0 * AV_TIME_BASE /\n\n (double)ic->duration;\n\n }\n\n}\n", + "output": "1", + "index": 27144 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int parallels_open(BlockDriverState *bs, QDict *options, int flags,\n\n Error **errp)\n\n{\n\n BDRVParallelsState *s = bs->opaque;\n\n int i;\n\n ParallelsHeader ph;\n\n int ret;\n\n\n\n ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph));\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n bs->total_sectors = le64_to_cpu(ph.nb_sectors);\n\n\n\n if (le32_to_cpu(ph.version) != HEADER_VERSION) {\n\n goto fail_format;\n\n }\n\n if (!memcmp(ph.magic, HEADER_MAGIC, 16)) {\n\n s->off_multiplier = 1;\n\n bs->total_sectors = 0xffffffff & bs->total_sectors;\n\n } else if (!memcmp(ph.magic, HEADER_MAGIC2, 16)) {\n\n s->off_multiplier = le32_to_cpu(ph.tracks);\n\n } else {\n\n goto fail_format;\n\n }\n\n\n\n s->tracks = le32_to_cpu(ph.tracks);\n\n if (s->tracks == 0) {\n\n error_setg(errp, \"Invalid image: Zero sectors per track\");\n\n ret = -EINVAL;\n\n goto fail;\n\n }\n\n if (s->tracks > INT32_MAX/513) {\n\n error_setg(errp, \"Invalid image: Too big cluster\");\n\n ret = -EFBIG;\n\n goto fail;\n\n }\n\n\n\n s->catalog_size = le32_to_cpu(ph.catalog_entries);\n\n if (s->catalog_size > INT_MAX / sizeof(uint32_t)) {\n\n error_setg(errp, \"Catalog too large\");\n\n ret = -EFBIG;\n\n goto fail;\n\n }\n\n s->catalog_bitmap = g_try_new(uint32_t, s->catalog_size);\n\n if (s->catalog_size && s->catalog_bitmap == NULL) {\n\n ret = -ENOMEM;\n\n goto fail;\n\n }\n\n\n\n ret = bdrv_pread(bs->file, sizeof(ParallelsHeader),\n\n s->catalog_bitmap, s->catalog_size * sizeof(uint32_t));\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n for (i = 0; i < s->catalog_size; i++)\n\n le32_to_cpus(&s->catalog_bitmap[i]);\n\n\n\n s->has_truncate = bdrv_has_zero_init(bs->file) &&\n\n bdrv_truncate(bs->file, bdrv_getlength(bs->file)) == 0;\n\n\n\n qemu_co_mutex_init(&s->lock);\n\n return 0;\n\n\n\nfail_format:\n\n error_setg(errp, \"Image not in Parallels format\");\n\n ret = -EINVAL;\n\nfail:\n\n g_free(s->catalog_bitmap);\n\n return ret;\n\n}\n", + "output": "0", + "index": 2736 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int32_t scsi_send_command(SCSIRequest *req, uint8_t *cmd)\n\n{\n\n SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, req->dev);\n\n SCSIGenericReq *r = DO_UPCAST(SCSIGenericReq, req, req);\n\n int ret;\n\n\n\n if (cmd[0] != REQUEST_SENSE && req->lun != s->qdev.lun) {\n\n DPRINTF(\"Unimplemented LUN %d\\n\", req->lun);\n\n scsi_req_build_sense(&r->req, SENSE_CODE(LUN_NOT_SUPPORTED));\n\n scsi_req_complete(&r->req, CHECK_CONDITION);\n\n return 0;\n\n }\n\n\n\n if (-1 == scsi_req_parse(&r->req, cmd)) {\n\n BADF(\"Unsupported command length, command %x\\n\", cmd[0]);\n\n scsi_command_complete(r, -EINVAL);\n\n return 0;\n\n }\n\n scsi_req_fixup(&r->req);\n\n\n\n DPRINTF(\"Command: lun=%d tag=0x%x len %zd data=0x%02x\", lun, tag,\n\n r->req.cmd.xfer, cmd[0]);\n\n\n\n#ifdef DEBUG_SCSI\n\n {\n\n int i;\n\n for (i = 1; i < r->req.cmd.len; i++) {\n\n printf(\" 0x%02x\", cmd[i]);\n\n }\n\n printf(\"\\n\");\n\n }\n\n#endif\n\n\n\n if (r->req.cmd.xfer == 0) {\n\n if (r->buf != NULL)\n\n qemu_free(r->buf);\n\n r->buflen = 0;\n\n r->buf = NULL;\n\n ret = execute_command(s->bs, r, SG_DXFER_NONE, scsi_command_complete);\n\n if (ret < 0) {\n\n scsi_command_complete(r, ret);\n\n return 0;\n\n }\n\n return 0;\n\n }\n\n\n\n if (r->buflen != r->req.cmd.xfer) {\n\n if (r->buf != NULL)\n\n qemu_free(r->buf);\n\n r->buf = qemu_malloc(r->req.cmd.xfer);\n\n r->buflen = r->req.cmd.xfer;\n\n }\n\n\n\n memset(r->buf, 0, r->buflen);\n\n r->len = r->req.cmd.xfer;\n\n if (r->req.cmd.mode == SCSI_XFER_TO_DEV) {\n\n r->len = 0;\n\n return -r->req.cmd.xfer;\n\n } else {\n\n return r->req.cmd.xfer;\n\n }\n\n}\n", + "output": "0", + "index": 7315 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int write_abst(AVFormatContext *s, OutputStream *os, int final)\n\n{\n\n HDSContext *c = s->priv_data;\n\n AVIOContext *out;\n\n char filename[1024], temp_filename[1024];\n\n int i, ret;\n\n int64_t asrt_pos, afrt_pos;\n\n int start = 0, fragments;\n\n int index = s->streams[os->first_stream]->id;\n\n int64_t cur_media_time = 0;\n\n if (c->window_size)\n\n start = FFMAX(os->nb_fragments - c->window_size, 0);\n\n fragments = os->nb_fragments - start;\n\n if (final)\n\n cur_media_time = os->last_ts;\n\n else if (os->nb_fragments)\n\n cur_media_time = os->fragments[os->nb_fragments - 1]->start_time;\n\n\n\n snprintf(filename, sizeof(filename),\n\n \"%s/stream%d.abst\", s->filename, index);\n\n snprintf(temp_filename, sizeof(temp_filename),\n\n \"%s/stream%d.abst.tmp\", s->filename, index);\n\n ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE,\n\n &s->interrupt_callback, NULL);\n\n if (ret < 0) {\n\n av_log(s, AV_LOG_ERROR, \"Unable to open %s for writing\\n\", temp_filename);\n\n return ret;\n\n }\n\n avio_wb32(out, 0); // abst size\n\n avio_wl32(out, MKTAG('a','b','s','t'));\n\n avio_wb32(out, 0); // version + flags\n\n avio_wb32(out, os->fragment_index - 1); // BootstrapinfoVersion\n\n avio_w8(out, final ? 0 : 0x20); // profile, live, update\n\n avio_wb32(out, 1000); // timescale\n\n avio_wb64(out, cur_media_time);\n\n avio_wb64(out, 0); // SmpteTimeCodeOffset\n\n avio_w8(out, 0); // MovieIdentifer (null string)\n\n avio_w8(out, 0); // ServerEntryCount\n\n avio_w8(out, 0); // QualityEntryCount\n\n avio_w8(out, 0); // DrmData (null string)\n\n avio_w8(out, 0); // MetaData (null string)\n\n avio_w8(out, 1); // SegmentRunTableCount\n\n asrt_pos = avio_tell(out);\n\n avio_wb32(out, 0); // asrt size\n\n avio_wl32(out, MKTAG('a','s','r','t'));\n\n avio_wb32(out, 0); // version + flags\n\n avio_w8(out, 0); // QualityEntryCount\n\n avio_wb32(out, 1); // SegmentRunEntryCount\n\n avio_wb32(out, 1); // FirstSegment\n\n avio_wb32(out, final ? (os->fragment_index - 1) : 0xffffffff); // FragmentsPerSegment\n\n update_size(out, asrt_pos);\n\n avio_w8(out, 1); // FragmentRunTableCount\n\n afrt_pos = avio_tell(out);\n\n avio_wb32(out, 0); // afrt size\n\n avio_wl32(out, MKTAG('a','f','r','t'));\n\n avio_wb32(out, 0); // version + flags\n\n avio_wb32(out, 1000); // timescale\n\n avio_w8(out, 0); // QualityEntryCount\n\n avio_wb32(out, fragments); // FragmentRunEntryCount\n\n for (i = start; i < os->nb_fragments; i++) {\n\n avio_wb32(out, os->fragments[i]->n);\n\n avio_wb64(out, os->fragments[i]->start_time);\n\n avio_wb32(out, os->fragments[i]->duration);\n\n }\n\n update_size(out, afrt_pos);\n\n update_size(out, 0);\n\n avio_close(out);\n\n return ff_rename(temp_filename, filename);\n\n}\n", + "output": "0", + "index": 10191 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void tgen_andi(TCGContext *s, TCGType type, TCGReg dest, uint64_t val)\n\n{\n\n static const S390Opcode ni_insns[4] = {\n\n RI_NILL, RI_NILH, RI_NIHL, RI_NIHH\n\n };\n\n static const S390Opcode nif_insns[2] = {\n\n RIL_NILF, RIL_NIHF\n\n };\n\n uint64_t valid = (type == TCG_TYPE_I32 ? 0xffffffffull : -1ull);\n\n int i;\n\n\n\n /* Look for the zero-extensions. */\n\n if ((val & valid) == 0xffffffff) {\n\n tgen_ext32u(s, dest, dest);\n\n return;\n\n }\n\n if (facilities & FACILITY_EXT_IMM) {\n\n if ((val & valid) == 0xff) {\n\n tgen_ext8u(s, TCG_TYPE_I64, dest, dest);\n\n return;\n\n }\n\n if ((val & valid) == 0xffff) {\n\n tgen_ext16u(s, TCG_TYPE_I64, dest, dest);\n\n return;\n\n }\n\n }\n\n\n\n /* Try all 32-bit insns that can perform it in one go. */\n\n for (i = 0; i < 4; i++) {\n\n tcg_target_ulong mask = ~(0xffffull << i*16);\n\n if (((val | ~valid) & mask) == mask) {\n\n tcg_out_insn_RI(s, ni_insns[i], dest, val >> i*16);\n\n return;\n\n }\n\n }\n\n\n\n /* Try all 48-bit insns that can perform it in one go. */\n\n if (facilities & FACILITY_EXT_IMM) {\n\n for (i = 0; i < 2; i++) {\n\n tcg_target_ulong mask = ~(0xffffffffull << i*32);\n\n if (((val | ~valid) & mask) == mask) {\n\n tcg_out_insn_RIL(s, nif_insns[i], dest, val >> i*32);\n\n return;\n\n }\n\n }\n\n }\n\n if ((facilities & FACILITY_GEN_INST_EXT) && risbg_mask(val)) {\n\n int msb, lsb;\n\n if ((val & 0x8000000000000001ull) == 0x8000000000000001ull) {\n\n /* Achieve wraparound by swapping msb and lsb. */\n\n msb = 63 - ctz64(~val);\n\n lsb = clz64(~val) + 1;\n\n } else {\n\n msb = clz64(val);\n\n lsb = 63 - ctz64(val);\n\n }\n\n tcg_out_risbg(s, dest, dest, msb, lsb, 0, 1);\n\n return;\n\n }\n\n\n\n /* Fall back to loading the constant. */\n\n tcg_out_movi(s, type, TCG_TMP0, val);\n\n if (type == TCG_TYPE_I32) {\n\n tcg_out_insn(s, RR, NR, dest, TCG_TMP0);\n\n } else {\n\n tcg_out_insn(s, RRE, NGR, dest, TCG_TMP0);\n\n }\n\n}\n", + "output": "1", + "index": 5862 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static GtkWidget *gd_create_menu_view(GtkDisplayState *s, GtkAccelGroup *accel_group)\n\n{\n\n GSList *group = NULL;\n\n GtkWidget *view_menu;\n\n GtkWidget *separator;\n\n int i;\n\n\n\n view_menu = gtk_menu_new();\n\n gtk_menu_set_accel_group(GTK_MENU(view_menu), accel_group);\n\n\n\n s->full_screen_item =\n\n gtk_image_menu_item_new_from_stock(GTK_STOCK_FULLSCREEN, NULL);\n\n gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->full_screen_item),\n\n \"/View/Full Screen\");\n\n gtk_accel_map_add_entry(\"/View/Full Screen\", GDK_KEY_f, GDK_CONTROL_MASK | GDK_MOD1_MASK);\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->full_screen_item);\n\n\n\n separator = gtk_separator_menu_item_new();\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);\n\n\n\n s->zoom_in_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_IN, NULL);\n\n gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_in_item),\n\n \"/View/Zoom In\");\n\n gtk_accel_map_add_entry(\"/View/Zoom In\", GDK_KEY_plus, GDK_CONTROL_MASK | GDK_MOD1_MASK);\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_in_item);\n\n\n\n s->zoom_out_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_OUT, NULL);\n\n gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_out_item),\n\n \"/View/Zoom Out\");\n\n gtk_accel_map_add_entry(\"/View/Zoom Out\", GDK_KEY_minus, GDK_CONTROL_MASK | GDK_MOD1_MASK);\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_out_item);\n\n\n\n s->zoom_fixed_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_100, NULL);\n\n gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->zoom_fixed_item),\n\n \"/View/Zoom Fixed\");\n\n gtk_accel_map_add_entry(\"/View/Zoom Fixed\", GDK_KEY_0, GDK_CONTROL_MASK | GDK_MOD1_MASK);\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_fixed_item);\n\n\n\n s->zoom_fit_item = gtk_check_menu_item_new_with_mnemonic(_(\"Zoom To _Fit\"));\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->zoom_fit_item);\n\n\n\n separator = gtk_separator_menu_item_new();\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);\n\n\n\n s->grab_on_hover_item = gtk_check_menu_item_new_with_mnemonic(_(\"Grab On _Hover\"));\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_on_hover_item);\n\n\n\n s->grab_item = gtk_check_menu_item_new_with_mnemonic(_(\"_Grab Input\"));\n\n gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->grab_item),\n\n \"/View/Grab Input\");\n\n gtk_accel_map_add_entry(\"/View/Grab Input\", GDK_KEY_g, GDK_CONTROL_MASK | GDK_MOD1_MASK);\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->grab_item);\n\n\n\n separator = gtk_separator_menu_item_new();\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);\n\n\n\n s->vga_item = gtk_radio_menu_item_new_with_mnemonic(group, \"_VGA\");\n\n group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(s->vga_item));\n\n gtk_menu_item_set_accel_path(GTK_MENU_ITEM(s->vga_item),\n\n \"/View/VGA\");\n\n gtk_accel_map_add_entry(\"/View/VGA\", GDK_KEY_1, GDK_CONTROL_MASK | GDK_MOD1_MASK);\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->vga_item);\n\n\n\n for (i = 0; i < nb_vcs; i++) {\n\n VirtualConsole *vc = &s->vc[i];\n\n\n\n group = gd_vc_init(s, vc, i, group, view_menu);\n\n s->nb_vcs++;\n\n }\n\n\n\n separator = gtk_separator_menu_item_new();\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), separator);\n\n\n\n s->show_tabs_item = gtk_check_menu_item_new_with_mnemonic(_(\"Show _Tabs\"));\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), s->show_tabs_item);\n\n\n\n return view_menu;\n\n}\n", + "output": "0", + "index": 8979 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold int opus_encode_init(AVCodecContext *avctx)\n\n{\n\n int i, ch, ret;\n\n OpusEncContext *s = avctx->priv_data;\n\n\n\n s->avctx = avctx;\n\n s->channels = avctx->channels;\n\n\n\n /* Opus allows us to change the framesize on each packet (and each packet may\n\n * have multiple frames in it) but we can't change the codec's frame size on\n\n * runtime, so fix it to the lowest possible number of samples and use a queue\n\n * to accumulate AVFrames until we have enough to encode whatever the encoder\n\n * decides is the best */\n\n avctx->frame_size = 120;\n\n /* Initial padding will change if SILK is ever supported */\n\n avctx->initial_padding = 120;\n\n\n\n avctx->cutoff = !avctx->cutoff ? 20000 : avctx->cutoff;\n\n\n\n if (!avctx->bit_rate) {\n\n int coupled = ff_opus_default_coupled_streams[s->channels - 1];\n\n avctx->bit_rate = coupled*(96000) + (s->channels - coupled*2)*(48000);\n\n } else if (avctx->bit_rate < 6000 || avctx->bit_rate > 255000 * s->channels) {\n\n int64_t clipped_rate = av_clip(avctx->bit_rate, 6000, 255000 * s->channels);\n\n av_log(avctx, AV_LOG_ERROR, \"Unsupported bitrate %\"PRId64\" kbps, clipping to %\"PRId64\" kbps\\n\",\n\n avctx->bit_rate/1000, clipped_rate/1000);\n\n avctx->bit_rate = clipped_rate;\n\n }\n\n\n\n /* Frame structs and range coder buffers */\n\n s->frame = av_malloc(OPUS_MAX_FRAMES_PER_PACKET*sizeof(CeltFrame));\n\n if (!s->frame)\n\n return AVERROR(ENOMEM);\n\n s->rc = av_malloc(OPUS_MAX_FRAMES_PER_PACKET*sizeof(OpusRangeCoder));\n\n if (!s->rc)\n\n return AVERROR(ENOMEM);\n\n\n\n /* Extradata */\n\n avctx->extradata_size = 19;\n\n avctx->extradata = av_malloc(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);\n\n if (!avctx->extradata)\n\n return AVERROR(ENOMEM);\n\n opus_write_extradata(avctx);\n\n\n\n ff_af_queue_init(avctx, &s->afq);\n\n\n\n if (!(s->dsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT)))\n\n return AVERROR(ENOMEM);\n\n\n\n /* I have no idea why a base scaling factor of 68 works, could be the twiddles */\n\n for (i = 0; i < CELT_BLOCK_NB; i++)\n\n if ((ret = ff_mdct15_init(&s->mdct[i], 0, i + 3, 68 << (CELT_BLOCK_NB - 1 - i))))\n\n return AVERROR(ENOMEM);\n\n\n\n for (i = 0; i < OPUS_MAX_FRAMES_PER_PACKET; i++)\n\n s->frame[i].block[0].emph_coeff = s->frame[i].block[1].emph_coeff = 0.0f;\n\n\n\n /* Zero out previous energy (matters for inter first frame) */\n\n for (ch = 0; ch < s->channels; ch++)\n\n for (i = 0; i < CELT_MAX_BANDS; i++)\n\n s->last_quantized_energy[ch][i] = 0.0f;\n\n\n\n /* Allocate an empty frame to use as overlap for the first frame of audio */\n\n ff_bufqueue_add(avctx, &s->bufqueue, spawn_empty_frame(s));\n\n if (!ff_bufqueue_peek(&s->bufqueue, 0))\n\n return AVERROR(ENOMEM);\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 5469 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, unsigned int src_size)\n\n{\n\n\tunsigned i;\n\n#ifdef HAVE_MMX\n\n\tlong mmx_size= 23 - src_size;\n\n\tasm volatile (\n\n\t\t\"movq \"MANGLE(mask24r)\", %%mm5\t\\n\\t\"\n\n\t\t\"movq \"MANGLE(mask24g)\", %%mm6\t\\n\\t\"\n\n\t\t\"movq \"MANGLE(mask24b)\", %%mm7\t\\n\\t\"\n\n\t\t\".balign 16\t\t\t\\n\\t\"\n\n\t\t\"1:\t\t\t\t\\n\\t\"\n\n\t\tPREFETCH\" 32(%1, %%\"REG_a\")\t\\n\\t\"\n\n\t\t\"movq (%1, %%\"REG_a\"), %%mm0\t\\n\\t\" // BGR BGR BG\n\n\t\t\"movq (%1, %%\"REG_a\"), %%mm1\t\\n\\t\" // BGR BGR BG\n\n\t\t\"movq 2(%1, %%\"REG_a\"), %%mm2\t\\n\\t\" // R BGR BGR B\n\n\t\t\"psllq $16, %%mm0\t\t\\n\\t\" // 00 BGR BGR\n\n\t\t\"pand %%mm5, %%mm0\t\t\\n\\t\"\n\n\t\t\"pand %%mm6, %%mm1\t\t\\n\\t\"\n\n\t\t\"pand %%mm7, %%mm2\t\t\\n\\t\"\n\n\t\t\"por %%mm0, %%mm1\t\t\\n\\t\"\n\n\t\t\"por %%mm2, %%mm1\t\t\\n\\t\" \n\n\t\t\"movq 6(%1, %%\"REG_a\"), %%mm0\t\\n\\t\" // BGR BGR BG\n\n\t\tMOVNTQ\" %%mm1, (%2, %%\"REG_a\")\\n\\t\" // RGB RGB RG\n\n\t\t\"movq 8(%1, %%\"REG_a\"), %%mm1\t\\n\\t\" // R BGR BGR B\n\n\t\t\"movq 10(%1, %%\"REG_a\"), %%mm2\t\\n\\t\" // GR BGR BGR\n\n\t\t\"pand %%mm7, %%mm0\t\t\\n\\t\"\n\n\t\t\"pand %%mm5, %%mm1\t\t\\n\\t\"\n\n\t\t\"pand %%mm6, %%mm2\t\t\\n\\t\"\n\n\t\t\"por %%mm0, %%mm1\t\t\\n\\t\"\n\n\t\t\"por %%mm2, %%mm1\t\t\\n\\t\" \n\n\t\t\"movq 14(%1, %%\"REG_a\"), %%mm0\t\\n\\t\" // R BGR BGR B\n\n\t\tMOVNTQ\" %%mm1, 8(%2, %%\"REG_a\")\\n\\t\" // B RGB RGB R\n\n\t\t\"movq 16(%1, %%\"REG_a\"), %%mm1\t\\n\\t\" // GR BGR BGR\n\n\t\t\"movq 18(%1, %%\"REG_a\"), %%mm2\t\\n\\t\" // BGR BGR BG\n\n\t\t\"pand %%mm6, %%mm0\t\t\\n\\t\"\n\n\t\t\"pand %%mm7, %%mm1\t\t\\n\\t\"\n\n\t\t\"pand %%mm5, %%mm2\t\t\\n\\t\"\n\n\t\t\"por %%mm0, %%mm1\t\t\\n\\t\"\n\n\t\t\"por %%mm2, %%mm1\t\t\\n\\t\" \n\n\t\tMOVNTQ\" %%mm1, 16(%2, %%\"REG_a\")\\n\\t\"\n\n\t\t\"add $24, %%\"REG_a\"\t\t\\n\\t\"\n\n\t\t\" js 1b\t\t\t\t\\n\\t\"\n\n\t\t: \"+a\" (mmx_size)\n\n\t\t: \"r\" (src-mmx_size), \"r\"(dst-mmx_size)\n\n\t);\n\n\n\n\t__asm __volatile(SFENCE:::\"memory\");\n\n\t__asm __volatile(EMMS:::\"memory\");\n\n\n\n\tif(mmx_size==23) return; //finihsed, was multiple of 8\n\n\n\n\tsrc+= src_size;\n\n\tdst+= src_size;\n\n\tsrc_size= 23-mmx_size;\n\n\tsrc-= src_size;\n\n\tdst-= src_size;\n\n#endif\n\n\tfor(i=0; itb_flags & MSR_EE_FLAG)\n\n && !(dc->env->pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)\n\n && !(dc->env->pvr.regs[0] & PVR0_USE_HW_MUL_MASK)) {\n\n tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);\n\n t_gen_raise_exception(dc, EXCP_HW_EXCP);\n\n return;\n\n }\n\n\n\n subcode = dc->imm & 3;\n\n d[0] = tcg_temp_new();\n\n d[1] = tcg_temp_new();\n\n\n\n if (dc->type_b) {\n\n LOG_DIS(\"muli r%d r%d %x\\n\", dc->rd, dc->ra, dc->imm);\n\n t_gen_mulu(cpu_R[dc->rd], d[1], cpu_R[dc->ra], *(dec_alu_op_b(dc)));\n\n goto done;\n\n }\n\n\n\n /* mulh, mulhsu and mulhu are not available if C_USE_HW_MUL is < 2. */\n\n if (subcode >= 1 && subcode <= 3\n\n && !((dc->env->pvr.regs[2] & PVR2_USE_MUL64_MASK))) {\n\n /* nop??? */\n\n }\n\n\n\n switch (subcode) {\n\n case 0:\n\n LOG_DIS(\"mul r%d r%d r%d\\n\", dc->rd, dc->ra, dc->rb);\n\n t_gen_mulu(cpu_R[dc->rd], d[1], cpu_R[dc->ra], cpu_R[dc->rb]);\n\n break;\n\n case 1:\n\n LOG_DIS(\"mulh r%d r%d r%d\\n\", dc->rd, dc->ra, dc->rb);\n\n t_gen_muls(d[0], cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);\n\n break;\n\n case 2:\n\n LOG_DIS(\"mulhsu r%d r%d r%d\\n\", dc->rd, dc->ra, dc->rb);\n\n t_gen_muls(d[0], cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);\n\n break;\n\n case 3:\n\n LOG_DIS(\"mulhu r%d r%d r%d\\n\", dc->rd, dc->ra, dc->rb);\n\n t_gen_mulu(d[0], cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);\n\n break;\n\n default:\n\n cpu_abort(dc->env, \"unknown MUL insn %x\\n\", subcode);\n\n break;\n\n }\n\ndone:\n\n tcg_temp_free(d[0]);\n\n tcg_temp_free(d[1]);\n\n}\n", + "output": "0", + "index": 9561 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,\n AVPacket *avpkt) {\n const uint8_t *buf = avpkt->data;\n const uint8_t *buf_end = avpkt->data + avpkt->size;\n PTXContext * const s = avctx->priv_data;\n AVFrame *picture = data;\n AVFrame * const p = &s->picture;\n unsigned int offset, w, h, y, stride, bytes_per_pixel;\n uint8_t *ptr;\n if (buf_end - buf < 14)\n offset = AV_RL16(buf);\n w = AV_RL16(buf+8);\n h = AV_RL16(buf+10);\n bytes_per_pixel = AV_RL16(buf+12) >> 3;\n if (bytes_per_pixel != 2) {\n av_log_ask_for_sample(avctx, \"Image format is not RGB15.\\n\");\n return -1;\n }\n avctx->pix_fmt = PIX_FMT_RGB555;\n if (offset != 0x2c)\n av_log_ask_for_sample(avctx, \"offset != 0x2c\\n\");\n buf += offset;\n if (p->data[0])\n avctx->release_buffer(avctx, p);\n if (av_image_check_size(w, h, 0, avctx))\n return -1;\n if (w != avctx->width || h != avctx->height)\n avcodec_set_dimensions(avctx, w, h);\n if (avctx->get_buffer(avctx, p) < 0) {\n av_log(avctx, AV_LOG_ERROR, \"get_buffer() failed\\n\");\n return -1;\n }\n p->pict_type = AV_PICTURE_TYPE_I;\n ptr = p->data[0];\n stride = p->linesize[0];\n for (y=0; ypicture;\n *data_size = sizeof(AVPicture);\n return offset + w*h*bytes_per_pixel;\n}", + "output": "1", + "index": 16181 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int rv10_decode_picture_header(MpegEncContext *s)\n\n{\n\n int mb_count, pb_frame, marker, h, full_frame;\n\n \n\n /* skip packet header */\n\n h = get_bits(&s->gb, 8);\n\n if ((h & 0xc0) == 0xc0) {\n\n int len, pos;\n\n full_frame = 1;\n\n len = get_num(&s->gb);\n\n pos = get_num(&s->gb);\n\n } else {\n\n int seq, frame_size, pos;\n\n full_frame = 0;\n\n seq = get_bits(&s->gb, 8);\n\n frame_size = get_num(&s->gb);\n\n pos = get_num(&s->gb);\n\n }\n\n /* picture number */\n\n get_bits(&s->gb, 8);\n\n\n\n marker = get_bits(&s->gb, 1);\n\n\n\n if (get_bits(&s->gb, 1))\n\n s->pict_type = P_TYPE;\n\n else\n\n s->pict_type = I_TYPE;\n\n\n\n pb_frame = get_bits(&s->gb, 1);\n\n\n\n#ifdef DEBUG\n\n printf(\"pict_type=%d pb_frame=%d\\n\", s->pict_type, pb_frame);\n\n#endif\n\n \n\n if (pb_frame)\n\n return -1;\n\n\n\n s->qscale = get_bits(&s->gb, 5);\n\n\n\n if (s->pict_type == I_TYPE) {\n\n if (s->rv10_version == 3) {\n\n /* specific MPEG like DC coding not used */\n\n s->last_dc[0] = get_bits(&s->gb, 8);\n\n s->last_dc[1] = get_bits(&s->gb, 8);\n\n s->last_dc[2] = get_bits(&s->gb, 8);\n\n#ifdef DEBUG\n\n printf(\"DC:%d %d %d\\n\",\n\n s->last_dc[0],\n\n s->last_dc[1],\n\n s->last_dc[2]);\n\n#endif\n\n }\n\n }\n\n /* if multiple packets per frame are sent, the position at which\n\n to display the macro blocks is coded here */\n\n if (!full_frame) {\n\n s->mb_x = get_bits(&s->gb, 6);\t/* mb_x */\n\n s->mb_y = get_bits(&s->gb, 6);\t/* mb_y */\n\n mb_count = get_bits(&s->gb, 12);\n\n } else {\n\n s->mb_x = 0;\n\n s->mb_y = 0;\n\n mb_count = s->mb_width * s->mb_height;\n\n }\n\n\n\n get_bits(&s->gb, 3);\t/* ignored */\n\n s->f_code = 1;\n\n s->unrestricted_mv = 1;\n\n#if 0\n\n s->h263_long_vectors = 1;\n\n#endif\n\n return mb_count;\n\n}\n", + "output": "1", + "index": 17879 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)\n\n{\n\n int log2_min_cb_size = sps->log2_min_cb_size;\n\n int width = sps->width;\n\n int height = sps->height;\n\n int pic_size_in_ctb = ((width >> log2_min_cb_size) + 1) *\n\n ((height >> log2_min_cb_size) + 1);\n\n int ctb_count = sps->ctb_width * sps->ctb_height;\n\n int min_pu_size = sps->min_pu_width * sps->min_pu_height;\n\n\n\n s->bs_width = (width >> 2) + 1;\n\n s->bs_height = (height >> 2) + 1;\n\n\n\n s->sao = av_mallocz_array(ctb_count, sizeof(*s->sao));\n\n s->deblock = av_mallocz_array(ctb_count, sizeof(*s->deblock));\n\n if (!s->sao || !s->deblock)\n\n goto fail;\n\n\n\n s->skip_flag = av_malloc(sps->min_cb_height * sps->min_cb_width);\n\n s->tab_ct_depth = av_malloc_array(sps->min_cb_height, sps->min_cb_width);\n\n if (!s->skip_flag || !s->tab_ct_depth)\n\n goto fail;\n\n\n\n s->cbf_luma = av_malloc_array(sps->min_tb_width, sps->min_tb_height);\n\n s->tab_ipm = av_mallocz(min_pu_size);\n\n s->is_pcm = av_malloc((sps->min_pu_width + 1) * (sps->min_pu_height + 1));\n\n if (!s->tab_ipm || !s->cbf_luma || !s->is_pcm)\n\n goto fail;\n\n\n\n s->filter_slice_edges = av_malloc(ctb_count);\n\n s->tab_slice_address = av_malloc_array(pic_size_in_ctb,\n\n sizeof(*s->tab_slice_address));\n\n s->qp_y_tab = av_malloc_array(pic_size_in_ctb,\n\n sizeof(*s->qp_y_tab));\n\n if (!s->qp_y_tab || !s->filter_slice_edges || !s->tab_slice_address)\n\n goto fail;\n\n\n\n s->horizontal_bs = av_mallocz_array(s->bs_width, s->bs_height);\n\n s->vertical_bs = av_mallocz_array(s->bs_width, s->bs_height);\n\n if (!s->horizontal_bs || !s->vertical_bs)\n\n goto fail;\n\n\n\n s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField),\n\n av_buffer_allocz);\n\n s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab),\n\n av_buffer_allocz);\n\n if (!s->tab_mvf_pool || !s->rpl_tab_pool)\n\n goto fail;\n\n\n\n return 0;\n\n\n\nfail:\n\n pic_arrays_free(s);\n\n return AVERROR(ENOMEM);\n\n}\n", + "output": "1", + "index": 8193 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int qtrle_decode_frame(AVCodecContext *avctx,\n\n void *data, int *got_frame,\n\n AVPacket *avpkt)\n\n{\n\n QtrleContext *s = avctx->priv_data;\n\n int header, start_line;\n\n int height, row_ptr;\n\n int has_palette = 0;\n\n int ret;\n\n\n\n bytestream2_init(&s->g, avpkt->data, avpkt->size);\n\n if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)\n\n return ret;\n\n\n\n /* check if this frame is even supposed to change */\n\n if (avpkt->size < 8)\n\n goto done;\n\n\n\n /* start after the chunk size */\n\n bytestream2_seek(&s->g, 4, SEEK_SET);\n\n\n\n /* fetch the header */\n\n header = bytestream2_get_be16(&s->g);\n\n\n\n /* if a header is present, fetch additional decoding parameters */\n\n if (header & 0x0008) {\n\n if (avpkt->size < 14)\n\n goto done;\n\n start_line = bytestream2_get_be16(&s->g);\n\n bytestream2_skip(&s->g, 2);\n\n height = bytestream2_get_be16(&s->g);\n\n bytestream2_skip(&s->g, 2);\n\n if (height > s->avctx->height - start_line)\n\n goto done;\n\n } else {\n\n start_line = 0;\n\n height = s->avctx->height;\n\n }\n\n row_ptr = s->frame->linesize[0] * start_line;\n\n\n\n switch (avctx->bits_per_coded_sample) {\n\n case 1:\n\n case 33:\n\n qtrle_decode_1bpp(s, row_ptr, height);\n\n has_palette = 1;\n\n break;\n\n\n\n case 2:\n\n case 34:\n\n qtrle_decode_2n4bpp(s, row_ptr, height, 2);\n\n has_palette = 1;\n\n break;\n\n\n\n case 4:\n\n case 36:\n\n qtrle_decode_2n4bpp(s, row_ptr, height, 4);\n\n has_palette = 1;\n\n break;\n\n\n\n case 8:\n\n case 40:\n\n qtrle_decode_8bpp(s, row_ptr, height);\n\n has_palette = 1;\n\n break;\n\n\n\n case 16:\n\n qtrle_decode_16bpp(s, row_ptr, height);\n\n break;\n\n\n\n case 24:\n\n qtrle_decode_24bpp(s, row_ptr, height);\n\n break;\n\n\n\n case 32:\n\n qtrle_decode_32bpp(s, row_ptr, height);\n\n break;\n\n\n\n default:\n\n av_log (s->avctx, AV_LOG_ERROR, \"Unsupported colorspace: %d bits/sample?\\n\",\n\n avctx->bits_per_coded_sample);\n\n break;\n\n }\n\n\n\n if(has_palette) {\n\n const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);\n\n\n\n if (pal) {\n\n s->frame->palette_has_changed = 1;\n\n memcpy(s->pal, pal, AVPALETTE_SIZE);\n\n }\n\n\n\n /* make the palette available on the way out */\n\n memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE);\n\n }\n\n\n\ndone:\n\n if ((ret = av_frame_ref(data, s->frame)) < 0)\n\n return ret;\n\n *got_frame = 1;\n\n\n\n /* always report that the buffer was completely consumed */\n\n return avpkt->size;\n\n}\n", + "output": "0", + "index": 18321 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void ahci_port_write(AHCIState *s, int port, int offset, uint32_t val)\n\n{\n\n AHCIPortRegs *pr = &s->dev[port].port_regs;\n\n\n\n DPRINTF(port, \"offset: 0x%x val: 0x%x\\n\", offset, val);\n\n switch (offset) {\n\n case PORT_LST_ADDR:\n\n pr->lst_addr = val;\n\n map_page(s->as, &s->dev[port].lst,\n\n ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr, 1024);\n\n s->dev[port].cur_cmd = NULL;\n\n break;\n\n case PORT_LST_ADDR_HI:\n\n pr->lst_addr_hi = val;\n\n map_page(s->as, &s->dev[port].lst,\n\n ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr, 1024);\n\n s->dev[port].cur_cmd = NULL;\n\n break;\n\n case PORT_FIS_ADDR:\n\n pr->fis_addr = val;\n\n map_page(s->as, &s->dev[port].res_fis,\n\n ((uint64_t)pr->fis_addr_hi << 32) | pr->fis_addr, 256);\n\n break;\n\n case PORT_FIS_ADDR_HI:\n\n pr->fis_addr_hi = val;\n\n map_page(s->as, &s->dev[port].res_fis,\n\n ((uint64_t)pr->fis_addr_hi << 32) | pr->fis_addr, 256);\n\n break;\n\n case PORT_IRQ_STAT:\n\n pr->irq_stat &= ~val;\n\n ahci_check_irq(s);\n\n break;\n\n case PORT_IRQ_MASK:\n\n pr->irq_mask = val & 0xfdc000ff;\n\n ahci_check_irq(s);\n\n break;\n\n case PORT_CMD:\n\n pr->cmd = val & ~(PORT_CMD_LIST_ON | PORT_CMD_FIS_ON);\n\n\n\n if (pr->cmd & PORT_CMD_START) {\n\n pr->cmd |= PORT_CMD_LIST_ON;\n\n }\n\n\n\n if (pr->cmd & PORT_CMD_FIS_RX) {\n\n pr->cmd |= PORT_CMD_FIS_ON;\n\n }\n\n\n\n /* XXX usually the FIS would be pending on the bus here and\n\n issuing deferred until the OS enables FIS receival.\n\n Instead, we only submit it once - which works in most\n\n cases, but is a hack. */\n\n if ((pr->cmd & PORT_CMD_FIS_ON) &&\n\n !s->dev[port].init_d2h_sent) {\n\n ahci_init_d2h(&s->dev[port]);\n\n s->dev[port].init_d2h_sent = true;\n\n }\n\n\n\n check_cmd(s, port);\n\n break;\n\n case PORT_TFDATA:\n\n s->dev[port].port.ifs[0].error = (val >> 8) & 0xff;\n\n s->dev[port].port.ifs[0].status = val & 0xff;\n\n break;\n\n case PORT_SIG:\n\n pr->sig = val;\n\n break;\n\n case PORT_SCR_STAT:\n\n pr->scr_stat = val;\n\n break;\n\n case PORT_SCR_CTL:\n\n if (((pr->scr_ctl & AHCI_SCR_SCTL_DET) == 1) &&\n\n ((val & AHCI_SCR_SCTL_DET) == 0)) {\n\n ahci_reset_port(s, port);\n\n }\n\n pr->scr_ctl = val;\n\n break;\n\n case PORT_SCR_ERR:\n\n pr->scr_err &= ~val;\n\n break;\n\n case PORT_SCR_ACT:\n\n /* RW1 */\n\n pr->scr_act |= val;\n\n break;\n\n case PORT_CMD_ISSUE:\n\n pr->cmd_issue |= val;\n\n check_cmd(s, port);\n\n break;\n\n default:\n\n break;\n\n }\n\n}\n", + "output": "1", + "index": 24898 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void apply_loop_filter(Vp3DecodeContext *s)\n\n{\n\n int x, y, plane;\n\n int width, height;\n\n int fragment;\n\n int stride;\n\n unsigned char *plane_data;\n\n\n\n int bounding_values_array[256];\n\n int *bounding_values= bounding_values_array+127;\n\n int filter_limit;\n\n\n\n /* find the right loop limit value */\n\n for (x = 63; x >= 0; x--) {\n\n if (vp31_ac_scale_factor[x] >= s->quality_index)\n\n break;\n\n }\n\n filter_limit = vp31_filter_limit_values[s->quality_index];\n\n\n\n /* set up the bounding values */\n\n memset(bounding_values_array, 0, 256 * sizeof(int));\n\n for (x = 0; x < filter_limit; x++) {\n\n bounding_values[-x - filter_limit] = -filter_limit + x;\n\n bounding_values[-x] = -x;\n\n bounding_values[x] = x;\n\n bounding_values[x + filter_limit] = filter_limit - x;\n\n }\n\n\n\n for (plane = 0; plane < 3; plane++) {\n\n\n\n if (plane == 0) {\n\n /* Y plane parameters */\n\n fragment = 0;\n\n width = s->fragment_width;\n\n height = s->fragment_height;\n\n stride = s->current_frame.linesize[0];\n\n plane_data = s->current_frame.data[0];\n\n } else if (plane == 1) {\n\n /* U plane parameters */\n\n fragment = s->u_fragment_start;\n\n width = s->fragment_width / 2;\n\n height = s->fragment_height / 2;\n\n stride = s->current_frame.linesize[1];\n\n plane_data = s->current_frame.data[1];\n\n } else {\n\n /* V plane parameters */\n\n fragment = s->v_fragment_start;\n\n width = s->fragment_width / 2;\n\n height = s->fragment_height / 2;\n\n stride = s->current_frame.linesize[2];\n\n plane_data = s->current_frame.data[2];\n\n }\n\n\n\n for (y = 0; y < height; y++) {\n\n\n\n for (x = 0; x < width; x++) {\n\nSTART_TIMER\n\n /* do not perform left edge filter for left columns frags */\n\n if ((x > 0) &&\n\n (s->all_fragments[fragment].coding_method != MODE_COPY)) {\n\n horizontal_filter(\n\n plane_data + s->all_fragments[fragment].first_pixel - 7*stride, \n\n stride, bounding_values);\n\n }\n\n\n\n /* do not perform top edge filter for top row fragments */\n\n if ((y > 0) &&\n\n (s->all_fragments[fragment].coding_method != MODE_COPY)) {\n\n vertical_filter(\n\n plane_data + s->all_fragments[fragment].first_pixel + stride, \n\n stride, bounding_values);\n\n }\n\n\n\n /* do not perform right edge filter for right column\n\n * fragments or if right fragment neighbor is also coded\n\n * in this frame (it will be filtered in next iteration) */\n\n if ((x < width - 1) &&\n\n (s->all_fragments[fragment].coding_method != MODE_COPY) &&\n\n (s->all_fragments[fragment + 1].coding_method == MODE_COPY)) {\n\n horizontal_filter(\n\n plane_data + s->all_fragments[fragment + 1].first_pixel - 7*stride, \n\n stride, bounding_values);\n\n }\n\n\n\n /* do not perform bottom edge filter for bottom row\n\n * fragments or if bottom fragment neighbor is also coded\n\n * in this frame (it will be filtered in the next row) */\n\n if ((y < height - 1) &&\n\n (s->all_fragments[fragment].coding_method != MODE_COPY) &&\n\n (s->all_fragments[fragment + width].coding_method == MODE_COPY)) {\n\n vertical_filter(\n\n plane_data + s->all_fragments[fragment + width].first_pixel + stride, \n\n stride, bounding_values);\n\n }\n\n\n\n fragment++;\n\nSTOP_TIMER(\"loop filter\")\n\n }\n\n }\n\n }\n\n}\n", + "output": "0", + "index": 9545 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "av_cold void ff_rl_init(RLTable *rl,\n\n uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3])\n\n{\n\n int8_t max_level[MAX_RUN + 1], max_run[MAX_LEVEL + 1];\n\n uint8_t index_run[MAX_RUN + 1];\n\n int last, run, level, start, end, i;\n\n\n\n /* If table is static, we can quit if rl->max_level[0] is not NULL */\n\n if (static_store && rl->max_level[0])\n\n return;\n\n\n\n /* compute max_level[], max_run[] and index_run[] */\n\n for (last = 0; last < 2; last++) {\n\n if (last == 0) {\n\n start = 0;\n\n end = rl->last;\n\n } else {\n\n start = rl->last;\n\n end = rl->n;\n\n }\n\n\n\n memset(max_level, 0, MAX_RUN + 1);\n\n memset(max_run, 0, MAX_LEVEL + 1);\n\n memset(index_run, rl->n, MAX_RUN + 1);\n\n for (i = start; i < end; i++) {\n\n run = rl->table_run[i];\n\n level = rl->table_level[i];\n\n if (index_run[run] == rl->n)\n\n index_run[run] = i;\n\n if (level > max_level[run])\n\n max_level[run] = level;\n\n if (run > max_run[level])\n\n max_run[level] = run;\n\n }\n\n if (static_store)\n\n rl->max_level[last] = static_store[last];\n\n else\n\n rl->max_level[last] = av_malloc(MAX_RUN + 1);\n\n memcpy(rl->max_level[last], max_level, MAX_RUN + 1);\n\n if (static_store)\n\n rl->max_run[last] = static_store[last] + MAX_RUN + 1;\n\n else\n\n rl->max_run[last] = av_malloc(MAX_LEVEL + 1);\n\n memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1);\n\n if (static_store)\n\n rl->index_run[last] = static_store[last] + MAX_RUN + MAX_LEVEL + 2;\n\n else\n\n rl->index_run[last] = av_malloc(MAX_RUN + 1);\n\n memcpy(rl->index_run[last], index_run, MAX_RUN + 1);\n\n }\n\n}\n", + "output": "0", + "index": 22514 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size)\n\n{\n\n const uint8_t *s = src;\n\n const uint8_t *end;\n\n#if COMPILE_TEMPLATE_MMX\n\n const uint8_t *mm_end;\n\n#endif\n\n uint16_t *d = (uint16_t *)dst;\n\n end = s + src_size;\n\n#if COMPILE_TEMPLATE_MMX\n\n __asm__ volatile(PREFETCH\" %0\"::\"m\"(*src):\"memory\");\n\n __asm__ volatile(\n\n \"movq %0, %%mm7 \\n\\t\"\n\n \"movq %1, %%mm6 \\n\\t\"\n\n ::\"m\"(red_15mask),\"m\"(green_15mask));\n\n mm_end = end - 11;\n\n while (s < mm_end) {\n\n __asm__ volatile(\n\n PREFETCH\" 32%1 \\n\\t\"\n\n \"movd %1, %%mm0 \\n\\t\"\n\n \"movd 3%1, %%mm3 \\n\\t\"\n\n \"punpckldq 6%1, %%mm0 \\n\\t\"\n\n \"punpckldq 9%1, %%mm3 \\n\\t\"\n\n \"movq %%mm0, %%mm1 \\n\\t\"\n\n \"movq %%mm0, %%mm2 \\n\\t\"\n\n \"movq %%mm3, %%mm4 \\n\\t\"\n\n \"movq %%mm3, %%mm5 \\n\\t\"\n\n \"psrlq $3, %%mm0 \\n\\t\"\n\n \"psrlq $3, %%mm3 \\n\\t\"\n\n \"pand %2, %%mm0 \\n\\t\"\n\n \"pand %2, %%mm3 \\n\\t\"\n\n \"psrlq $6, %%mm1 \\n\\t\"\n\n \"psrlq $6, %%mm4 \\n\\t\"\n\n \"pand %%mm6, %%mm1 \\n\\t\"\n\n \"pand %%mm6, %%mm4 \\n\\t\"\n\n \"psrlq $9, %%mm2 \\n\\t\"\n\n \"psrlq $9, %%mm5 \\n\\t\"\n\n \"pand %%mm7, %%mm2 \\n\\t\"\n\n \"pand %%mm7, %%mm5 \\n\\t\"\n\n \"por %%mm1, %%mm0 \\n\\t\"\n\n \"por %%mm4, %%mm3 \\n\\t\"\n\n \"por %%mm2, %%mm0 \\n\\t\"\n\n \"por %%mm5, %%mm3 \\n\\t\"\n\n \"psllq $16, %%mm3 \\n\\t\"\n\n \"por %%mm3, %%mm0 \\n\\t\"\n\n MOVNTQ\" %%mm0, %0 \\n\\t\"\n\n :\"=m\"(*d):\"m\"(*s),\"m\"(blue_15mask):\"memory\");\n\n d += 4;\n\n s += 12;\n\n }\n\n __asm__ volatile(SFENCE:::\"memory\");\n\n __asm__ volatile(EMMS:::\"memory\");\n\n#endif\n\n while (s < end) {\n\n const int b = *s++;\n\n const int g = *s++;\n\n const int r = *s++;\n\n *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7);\n\n }\n\n}\n", + "output": "0", + "index": 12014 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void fic_draw_cursor(AVCodecContext *avctx, int cur_x, int cur_y)\n\n{\n\n FICContext *ctx = avctx->priv_data;\n\n uint8_t *ptr = ctx->cursor_buf;\n\n uint8_t *dstptr[3];\n\n uint8_t planes[4][1024];\n\n uint8_t chroma[3][256];\n\n int i, j, p;\n\n\n\n /* Convert to YUVA444. */\n\n for (i = 0; i < 1024; i++) {\n\n planes[0][i] = av_clip_uint8((( 25 * ptr[0] + 129 * ptr[1] + 66 * ptr[2]) / 255) + 16);\n\n planes[1][i] = av_clip_uint8(((-38 * ptr[0] + 112 * ptr[1] + -74 * ptr[2]) / 255) + 128);\n\n planes[2][i] = av_clip_uint8(((-18 * ptr[0] + 112 * ptr[1] + -94 * ptr[2]) / 255) + 128);\n\n planes[3][i] = ptr[3];\n\n\n\n ptr += 4;\n\n }\n\n\n\n /* Subsample chroma. */\n\n for (i = 0; i < 32; i += 2)\n\n for (j = 0; j < 32; j += 2)\n\n for (p = 0; p < 3; p++)\n\n chroma[p][16 * (i / 2) + j / 2] = (planes[p + 1][32 * i + j ] +\n\n planes[p + 1][32 * i + j + 1] +\n\n planes[p + 1][32 * (i + 1) + j ] +\n\n planes[p + 1][32 * (i + 1) + j + 1]) / 4;\n\n\n\n /* Seek to x/y pos of cursor. */\n\n for (i = 0; i < 3; i++)\n\n dstptr[i] = ctx->final_frame->data[i] +\n\n (ctx->final_frame->linesize[i] * (cur_y >> !!i)) +\n\n (cur_x >> !!i) + !!i;\n\n\n\n /* Copy. */\n\n for (i = 0; i < FFMIN(32, avctx->height - cur_y) - 1; i += 2) {\n\n int lsize = FFMIN(32, avctx->width - cur_x);\n\n int csize = lsize / 2;\n\n\n\n fic_alpha_blend(dstptr[0],\n\n planes[0] + i * 32, lsize, planes[3] + i * 32);\n\n fic_alpha_blend(dstptr[0] + ctx->final_frame->linesize[0],\n\n planes[0] + (i + 1) * 32, lsize, planes[3] + (i + 1) * 32);\n\n fic_alpha_blend(dstptr[1],\n\n chroma[0] + (i / 2) * 16, csize, chroma[2] + (i / 2) * 16);\n\n fic_alpha_blend(dstptr[2],\n\n chroma[1] + (i / 2) * 16, csize, chroma[2] + (i / 2) * 16);\n\n\n\n dstptr[0] += ctx->final_frame->linesize[0] * 2;\n\n dstptr[1] += ctx->final_frame->linesize[1];\n\n dstptr[2] += ctx->final_frame->linesize[2];\n\n }\n\n}\n", + "output": "1", + "index": 15139 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "CPUCRISState *cpu_cris_init (const char *cpu_model)\n\n{\n\n\tCPUCRISState *env;\n\n\tstatic int tcg_initialized = 0;\n\n\tint i;\n\n\n\n\tenv = qemu_mallocz(sizeof(CPUCRISState));\n\n\tif (!env)\n\n\t\treturn NULL;\n\n\n\n\tcpu_exec_init(env);\n\n\tcpu_reset(env);\n\n\n\n\tif (tcg_initialized)\n\n\t\treturn env;\n\n\n\n\ttcg_initialized = 1;\n\n\n\n\tcpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, \"env\");\n\n\tcc_x = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t offsetof(CPUState, cc_x), \"cc_x\");\n\n\tcc_src = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t offsetof(CPUState, cc_src), \"cc_src\");\n\n\tcc_dest = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t offsetof(CPUState, cc_dest),\n\n\t\t\t\t \"cc_dest\");\n\n\tcc_result = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t offsetof(CPUState, cc_result),\n\n\t\t\t\t \"cc_result\");\n\n\tcc_op = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t offsetof(CPUState, cc_op), \"cc_op\");\n\n\tcc_size = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t offsetof(CPUState, cc_size),\n\n\t\t\t\t \"cc_size\");\n\n\tcc_mask = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t offsetof(CPUState, cc_mask),\n\n\t\t\t\t \"cc_mask\");\n\n\n\n\tenv_pc = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0, \n\n\t\t\t\t offsetof(CPUState, pc),\n\n\t\t\t\t \"pc\");\n\n\tenv_btarget = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t\t offsetof(CPUState, btarget),\n\n\t\t\t\t\t \"btarget\");\n\n\tenv_btaken = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t\t offsetof(CPUState, btaken),\n\n\t\t\t\t\t \"btaken\");\n\n\tfor (i = 0; i < 16; i++) {\n\n\t\tcpu_R[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t\t offsetof(CPUState, regs[i]),\n\n\t\t\t\t\t regnames[i]);\n\n\t}\n\n\tfor (i = 0; i < 16; i++) {\n\n\t\tcpu_PR[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,\n\n\t\t\t\t\t offsetof(CPUState, pregs[i]),\n\n\t\t\t\t\t pregnames[i]);\n\n\t}\n\n\n\n\tTCG_HELPER(helper_raise_exception);\n\n\tTCG_HELPER(helper_dump);\n\n\n\n\tTCG_HELPER(helper_tlb_flush_pid);\n\n\tTCG_HELPER(helper_movl_sreg_reg);\n\n\tTCG_HELPER(helper_movl_reg_sreg);\n\n\tTCG_HELPER(helper_rfe);\n\n\tTCG_HELPER(helper_rfn);\n\n\n\n\tTCG_HELPER(helper_evaluate_flags_muls);\n\n\tTCG_HELPER(helper_evaluate_flags_mulu);\n\n\tTCG_HELPER(helper_evaluate_flags_mcp);\n\n\tTCG_HELPER(helper_evaluate_flags_alu_4);\n\n\tTCG_HELPER(helper_evaluate_flags_move_4);\n\n\tTCG_HELPER(helper_evaluate_flags_move_2);\n\n\tTCG_HELPER(helper_evaluate_flags);\n\n\tTCG_HELPER(helper_top_evaluate_flags);\n\n\treturn env;\n\n}\n", + "output": "0", + "index": 20499 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int discard_single_l2(BlockDriverState *bs, uint64_t offset,\n\n unsigned int nb_clusters, enum qcow2_discard_type type, bool full_discard)\n\n{\n\n BDRVQcow2State *s = bs->opaque;\n\n uint64_t *l2_table;\n\n int l2_index;\n\n int ret;\n\n int i;\n\n\n\n ret = get_cluster_table(bs, offset, &l2_table, &l2_index);\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n\n\n /* Limit nb_clusters to one L2 table */\n\n nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);\n\n\n\n for (i = 0; i < nb_clusters; i++) {\n\n uint64_t old_l2_entry;\n\n\n\n old_l2_entry = be64_to_cpu(l2_table[l2_index + i]);\n\n\n\n /*\n\n * If full_discard is false, make sure that a discarded area reads back\n\n * as zeroes for v3 images (we cannot do it for v2 without actually\n\n * writing a zero-filled buffer). We can skip the operation if the\n\n * cluster is already marked as zero, or if it's unallocated and we\n\n * don't have a backing file.\n\n *\n\n * TODO We might want to use bdrv_get_block_status(bs) here, but we're\n\n * holding s->lock, so that doesn't work today.\n\n *\n\n * If full_discard is true, the sector should not read back as zeroes,\n\n * but rather fall through to the backing file.\n\n */\n\n switch (qcow2_get_cluster_type(old_l2_entry)) {\n\n case QCOW2_CLUSTER_UNALLOCATED:\n\n if (full_discard || !bs->backing_hd) {\n\n continue;\n\n }\n\n break;\n\n\n\n case QCOW2_CLUSTER_ZERO:\n\n if (!full_discard) {\n\n continue;\n\n }\n\n break;\n\n\n\n case QCOW2_CLUSTER_NORMAL:\n\n case QCOW2_CLUSTER_COMPRESSED:\n\n break;\n\n\n\n default:\n\n abort();\n\n }\n\n\n\n /* First remove L2 entries */\n\n qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache, l2_table);\n\n if (!full_discard && s->qcow_version >= 3) {\n\n l2_table[l2_index + i] = cpu_to_be64(QCOW_OFLAG_ZERO);\n\n } else {\n\n l2_table[l2_index + i] = cpu_to_be64(0);\n\n }\n\n\n\n /* Then decrease the refcount */\n\n qcow2_free_any_clusters(bs, old_l2_entry, 1, type);\n\n }\n\n\n\n qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table);\n\n\n\n return nb_clusters;\n\n}\n", + "output": "0", + "index": 15530 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)\n\n{\n\n int sx, sy;\n\n int dx, dy;\n\n int width, height;\n\n int depth;\n\n int notify = 0;\n\n\n\n depth = s->get_bpp((VGAState *)s) / 8;\n\n s->get_resolution((VGAState *)s, &width, &height);\n\n\n\n /* extra x, y */\n\n sx = (src % (width * depth)) / depth;\n\n sy = (src / (width * depth));\n\n dx = (dst % (width *depth)) / depth;\n\n dy = (dst / (width * depth));\n\n\n\n /* normalize width */\n\n w /= depth;\n\n\n\n /* if we're doing a backward copy, we have to adjust\n\n our x/y to be the upper left corner (instead of the lower\n\n right corner) */\n\n if (s->cirrus_blt_dstpitch < 0) {\n\n\tsx -= (s->cirrus_blt_width / depth) - 1;\n\n\tdx -= (s->cirrus_blt_width / depth) - 1;\n\n\tsy -= s->cirrus_blt_height - 1;\n\n\tdy -= s->cirrus_blt_height - 1;\n\n }\n\n\n\n /* are we in the visible portion of memory? */\n\n if (sx >= 0 && sy >= 0 && dx >= 0 && dy >= 0 &&\n\n\t(sx + w) <= width && (sy + h) <= height &&\n\n\t(dx + w) <= width && (dy + h) <= height) {\n\n\tnotify = 1;\n\n }\n\n\n\n /* make to sure only copy if it's a plain copy ROP */\n\n if (*s->cirrus_rop != cirrus_bitblt_rop_fwd_src &&\n\n\t*s->cirrus_rop != cirrus_bitblt_rop_bkwd_src)\n\n\tnotify = 0;\n\n\n\n /* we have to flush all pending changes so that the copy\n\n is generated at the appropriate moment in time */\n\n if (notify)\n\n\tvga_hw_update();\n\n\n\n (*s->cirrus_rop) (s, s->vram_ptr +\n\n\t\t (s->cirrus_blt_dstaddr & s->cirrus_addr_mask),\n\n\t\t s->vram_ptr +\n\n\t\t (s->cirrus_blt_srcaddr & s->cirrus_addr_mask),\n\n\t\t s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch,\n\n\t\t s->cirrus_blt_width, s->cirrus_blt_height);\n\n\n\n if (notify)\n\n\tqemu_console_copy(s->ds,\n\n\t\t\t sx, sy, dx, dy,\n\n\t\t\t s->cirrus_blt_width / depth,\n\n\t\t\t s->cirrus_blt_height);\n\n\n\n /* we don't have to notify the display that this portion has\n\n changed since qemu_console_copy implies this */\n\n\n\n if (!notify)\n\n\tcirrus_invalidate_region(s, s->cirrus_blt_dstaddr,\n\n\t\t\t\t s->cirrus_blt_dstpitch, s->cirrus_blt_width,\n\n\t\t\t\t s->cirrus_blt_height);\n\n}\n", + "output": "1", + "index": 13709 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void horizX1Filter(uint8_t *src, int stride, int QP)\n\n{\n\n int y;\n\n static uint64_t *lut= NULL;\n\n if(lut==NULL)\n\n {\n\n int i;\n\n lut = av_malloc(256*8);\n\n for(i=0; i<256; i++)\n\n {\n\n int v= i < 128 ? 2*i : 2*(i-256);\n\n/*\n\n//Simulate 112242211 9-Tap filter\n\n uint64_t a= (v/16) & 0xFF;\n\n uint64_t b= (v/8) & 0xFF;\n\n uint64_t c= (v/4) & 0xFF;\n\n uint64_t d= (3*v/8) & 0xFF;\n\n*/\n\n//Simulate piecewise linear interpolation\n\n uint64_t a= (v/16) & 0xFF;\n\n uint64_t b= (v*3/16) & 0xFF;\n\n uint64_t c= (v*5/16) & 0xFF;\n\n uint64_t d= (7*v/16) & 0xFF;\n\n uint64_t A= (0x100 - a)&0xFF;\n\n uint64_t B= (0x100 - b)&0xFF;\n\n uint64_t C= (0x100 - c)&0xFF;\n\n uint64_t D= (0x100 - c)&0xFF;\n\n\n\n lut[i] = (a<<56) | (b<<48) | (c<<40) | (d<<32) |\n\n (D<<24) | (C<<16) | (B<<8) | (A);\n\n //lut[i] = (v<<32) | (v<<24);\n\n }\n\n }\n\n\n\n for(y=0; yopts != NULL) {\n\n qemu_opts_loc_restore(pflash_drv->opts);\n\n }\n\n error_report(\"%s\", fatal_errmsg);\n\n loc_pop(&loc);\n\n g_free(fatal_errmsg);\n\n exit(1);\n\n }\n\n\n\n phys_addr -= size;\n\n\n\n /* pflash_cfi01_register() creates a deep copy of the name */\n\n snprintf(name, sizeof name, \"system.flash%d\", unit);\n\n system_flash = pflash_cfi01_register(phys_addr, NULL /* qdev */, name,\n\n size, bdrv, sector_size,\n\n size >> sector_bits,\n\n 1 /* width */,\n\n 0x0000 /* id0 */,\n\n 0x0000 /* id1 */,\n\n 0x0000 /* id2 */,\n\n 0x0000 /* id3 */,\n\n 0 /* be */);\n\n if (unit == 0) {\n\n flash_mem = pflash_cfi01_get_memory(system_flash);\n\n pc_isa_bios_init(rom_memory, flash_mem, size);\n\n }\n\n }\n\n}\n", + "output": "0", + "index": 17982 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "event_thread(void *arg)\n\n{\n\n unsigned char atr[MAX_ATR_LEN];\n\n int atr_len = MAX_ATR_LEN;\n\n VEvent *event = NULL;\n\n unsigned int reader_id;\n\n\n\n\n\n while (1) {\n\n const char *reader_name;\n\n\n\n event = vevent_wait_next_vevent();\n\n if (event == NULL) {\n\n break;\n\n }\n\n reader_id = vreader_get_id(event->reader);\n\n if (reader_id == VSCARD_UNDEFINED_READER_ID &&\n\n event->type != VEVENT_READER_INSERT) {\n\n /* ignore events from readers qemu has rejected */\n\n /* if qemu is still deciding on this reader, wait to see if need to\n\n * forward this event */\n\n qemu_mutex_lock(&pending_reader_lock);\n\n if (!pending_reader || (pending_reader != event->reader)) {\n\n /* wasn't for a pending reader, this reader has already been\n\n * rejected by qemu */\n\n qemu_mutex_unlock(&pending_reader_lock);\n\n vevent_delete(event);\n\n continue;\n\n }\n\n /* this reader hasn't been told its status from qemu yet, wait for\n\n * that status */\n\n while (pending_reader != NULL) {\n\n qemu_cond_wait(&pending_reader_condition, &pending_reader_lock);\n\n }\n\n qemu_mutex_unlock(&pending_reader_lock);\n\n /* now recheck the id */\n\n reader_id = vreader_get_id(event->reader);\n\n if (reader_id == VSCARD_UNDEFINED_READER_ID) {\n\n /* this reader was rejected */\n\n vevent_delete(event);\n\n continue;\n\n }\n\n /* reader was accepted, now forward the event */\n\n }\n\n switch (event->type) {\n\n case VEVENT_READER_INSERT:\n\n /* tell qemu to insert a new CCID reader */\n\n /* wait until qemu has responded to our first reader insert\n\n * before we send a second. That way we won't confuse the responses\n\n * */\n\n qemu_mutex_lock(&pending_reader_lock);\n\n while (pending_reader != NULL) {\n\n qemu_cond_wait(&pending_reader_condition, &pending_reader_lock);\n\n }\n\n pending_reader = vreader_reference(event->reader);\n\n qemu_mutex_unlock(&pending_reader_lock);\n\n reader_name = vreader_get_name(event->reader);\n\n if (verbose > 10) {\n\n printf(\" READER INSERT: %s\\n\", reader_name);\n\n }\n\n send_msg(VSC_ReaderAdd,\n\n reader_id, /* currerntly VSCARD_UNDEFINED_READER_ID */\n\n NULL, 0 /* TODO reader_name, strlen(reader_name) */);\n\n break;\n\n case VEVENT_READER_REMOVE:\n\n /* future, tell qemu that an old CCID reader has been removed */\n\n if (verbose > 10) {\n\n printf(\" READER REMOVE: %u\\n\", reader_id);\n\n }\n\n send_msg(VSC_ReaderRemove, reader_id, NULL, 0);\n\n break;\n\n case VEVENT_CARD_INSERT:\n\n /* get the ATR (intended as a response to a power on from the\n\n * reader */\n\n atr_len = MAX_ATR_LEN;\n\n vreader_power_on(event->reader, atr, &atr_len);\n\n /* ATR call functions as a Card Insert event */\n\n if (verbose > 10) {\n\n printf(\" CARD INSERT %u: \", reader_id);\n\n print_byte_array(atr, atr_len);\n\n }\n\n send_msg(VSC_ATR, reader_id, atr, atr_len);\n\n break;\n\n case VEVENT_CARD_REMOVE:\n\n /* Card removed */\n\n if (verbose > 10) {\n\n printf(\" CARD REMOVE %u:\\n\", reader_id);\n\n }\n\n send_msg(VSC_CardRemove, reader_id, NULL, 0);\n\n break;\n\n default:\n\n break;\n\n }\n\n vevent_delete(event);\n\n }\n\n return NULL;\n\n}\n", + "output": "0", + "index": 2287 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void arm_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,\n\n int flags)\n\n{\n\n ARMCPU *cpu = ARM_CPU(cs);\n\n CPUARMState *env = &cpu->env;\n\n int i;\n\n\n\n if (is_a64(env)) {\n\n aarch64_cpu_dump_state(cs, f, cpu_fprintf, flags);\n\n return;\n\n }\n\n\n\n for(i=0;i<16;i++) {\n\n cpu_fprintf(f, \"R%02d=%08x\", i, env->regs[i]);\n\n if ((i % 4) == 3)\n\n cpu_fprintf(f, \"\\n\");\n\n else\n\n cpu_fprintf(f, \" \");\n\n }\n\n\n\n if (arm_feature(env, ARM_FEATURE_M)) {\n\n uint32_t xpsr = xpsr_read(env);\n\n const char *mode;\n\n\n\n if (xpsr & XPSR_EXCP) {\n\n mode = \"handler\";\n\n } else {\n\n if (env->v7m.control & R_V7M_CONTROL_NPRIV_MASK) {\n\n mode = \"unpriv-thread\";\n\n } else {\n\n mode = \"priv-thread\";\n\n }\n\n }\n\n\n\n cpu_fprintf(f, \"XPSR=%08x %c%c%c%c %c %s\\n\",\n\n xpsr,\n\n xpsr & XPSR_N ? 'N' : '-',\n\n xpsr & XPSR_Z ? 'Z' : '-',\n\n xpsr & XPSR_C ? 'C' : '-',\n\n xpsr & XPSR_V ? 'V' : '-',\n\n xpsr & XPSR_T ? 'T' : 'A',\n\n mode);\n\n } else {\n\n uint32_t psr = cpsr_read(env);\n\n const char *ns_status = \"\";\n\n\n\n if (arm_feature(env, ARM_FEATURE_EL3) &&\n\n (psr & CPSR_M) != ARM_CPU_MODE_MON) {\n\n ns_status = env->cp15.scr_el3 & SCR_NS ? \"NS \" : \"S \";\n\n }\n\n\n\n cpu_fprintf(f, \"PSR=%08x %c%c%c%c %c %s%s%d\\n\",\n\n psr,\n\n psr & CPSR_N ? 'N' : '-',\n\n psr & CPSR_Z ? 'Z' : '-',\n\n psr & CPSR_C ? 'C' : '-',\n\n psr & CPSR_V ? 'V' : '-',\n\n psr & CPSR_T ? 'T' : 'A',\n\n ns_status,\n\n cpu_mode_names[psr & 0xf], (psr & 0x10) ? 32 : 26);\n\n }\n\n\n\n if (flags & CPU_DUMP_FPU) {\n\n int numvfpregs = 0;\n\n if (arm_feature(env, ARM_FEATURE_VFP)) {\n\n numvfpregs += 16;\n\n }\n\n if (arm_feature(env, ARM_FEATURE_VFP3)) {\n\n numvfpregs += 16;\n\n }\n\n for (i = 0; i < numvfpregs; i++) {\n\n uint64_t v = float64_val(env->vfp.regs[i]);\n\n cpu_fprintf(f, \"s%02d=%08x s%02d=%08x d%02d=%016\" PRIx64 \"\\n\",\n\n i * 2, (uint32_t)v,\n\n i * 2 + 1, (uint32_t)(v >> 32),\n\n i, v);\n\n }\n\n cpu_fprintf(f, \"FPSCR: %08x\\n\", (int)env->vfp.xregs[ARM_VFP_FPSCR]);\n\n }\n\n}\n", + "output": "0", + "index": 21324 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int event_thread(void *arg)\n\n{\n\n AVFormatContext *s = arg;\n\n SDLContext *sdl = s->priv_data;\n\n int flags = SDL_BASE_FLAGS | (sdl->window_fullscreen ? SDL_FULLSCREEN : 0);\n\n AVStream *st = s->streams[0];\n\n AVCodecContext *encctx = st->codec;\n\n\n\n /* initialization */\n\n if (SDL_Init(SDL_INIT_VIDEO) != 0) {\n\n av_log(s, AV_LOG_ERROR, \"Unable to initialize SDL: %s\\n\", SDL_GetError());\n\n sdl->init_ret = AVERROR(EINVAL);\n\n goto init_end;\n\n }\n\n\n\n SDL_WM_SetCaption(sdl->window_title, sdl->icon_title);\n\n sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height,\n\n 24, flags);\n\n if (!sdl->surface) {\n\n av_log(sdl, AV_LOG_ERROR, \"Unable to set video mode: %s\\n\", SDL_GetError());\n\n sdl->init_ret = AVERROR(EINVAL);\n\n goto init_end;\n\n }\n\n\n\n sdl->overlay = SDL_CreateYUVOverlay(encctx->width, encctx->height,\n\n sdl->overlay_fmt, sdl->surface);\n\n if (!sdl->overlay || sdl->overlay->pitches[0] < encctx->width) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"SDL does not support an overlay with size of %dx%d pixels\\n\",\n\n encctx->width, encctx->height);\n\n sdl->init_ret = AVERROR(EINVAL);\n\n goto init_end;\n\n }\n\n\n\n sdl->init_ret = 0;\n\n av_log(s, AV_LOG_VERBOSE, \"w:%d h:%d fmt:%s -> w:%d h:%d\\n\",\n\n encctx->width, encctx->height, av_get_pix_fmt_name(encctx->pix_fmt),\n\n sdl->overlay_rect.w, sdl->overlay_rect.h);\n\n\n\ninit_end:\n\n SDL_LockMutex(sdl->mutex);\n\n sdl->inited = 1;\n\n SDL_UnlockMutex(sdl->mutex);\n\n SDL_CondSignal(sdl->init_cond);\n\n\n\n if (sdl->init_ret < 0)\n\n return sdl->init_ret;\n\n\n\n /* event loop */\n\n while (!sdl->quit) {\n\n int ret;\n\n SDL_Event event;\n\n SDL_PumpEvents();\n\n ret = SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS);\n\n if (ret < 0)\n\n av_log(s, AV_LOG_ERROR, \"Error when getting SDL event: %s\\n\", SDL_GetError());\n\n if (ret <= 0)\n\n continue;\n\n\n\n switch (event.type) {\n\n case SDL_KEYDOWN:\n\n switch (event.key.keysym.sym) {\n\n case SDLK_ESCAPE:\n\n case SDLK_q:\n\n sdl->quit = 1;\n\n break;\n\n }\n\n break;\n\n case SDL_QUIT:\n\n sdl->quit = 1;\n\n break;\n\n\n\n case SDL_VIDEORESIZE:\n\n sdl->window_width = event.resize.w;\n\n sdl->window_height = event.resize.h;\n\n\n\n SDL_LockMutex(sdl->mutex);\n\n sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height, 24, SDL_BASE_FLAGS);\n\n if (!sdl->surface) {\n\n av_log(s, AV_LOG_ERROR, \"Failed to set SDL video mode: %s\\n\", SDL_GetError());\n\n sdl->quit = 1;\n\n } else {\n\n compute_overlay_rect(s);\n\n }\n\n SDL_UnlockMutex(sdl->mutex);\n\n break;\n\n\n\n default:\n\n break;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 14548 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int rtmp_server_handshake(URLContext *s, RTMPContext *rt)\n\n{\n\n uint8_t buffer[RTMP_HANDSHAKE_PACKET_SIZE];\n\n uint32_t hs_epoch;\n\n uint32_t hs_my_epoch;\n\n uint8_t hs_c1[RTMP_HANDSHAKE_PACKET_SIZE];\n\n uint8_t hs_s1[RTMP_HANDSHAKE_PACKET_SIZE];\n\n uint32_t zeroes;\n\n uint32_t temp = 0;\n\n int randomidx = 0;\n\n int inoutsize = 0;\n\n int ret;\n\n\n\n inoutsize = ffurl_read_complete(rt->stream, buffer, 1); // Receive C0\n\n if (inoutsize <= 0) {\n\n av_log(s, AV_LOG_ERROR, \"Unable to read handshake\\n\");\n\n return AVERROR(EIO);\n\n }\n\n // Check Version\n\n if (buffer[0] != 3) {\n\n av_log(s, AV_LOG_ERROR, \"RTMP protocol version mismatch\\n\");\n\n return AVERROR(EIO);\n\n }\n\n if (ffurl_write(rt->stream, buffer, 1) <= 0) { // Send S0\n\n av_log(s, AV_LOG_ERROR,\n\n \"Unable to write answer - RTMP S0\\n\");\n\n return AVERROR(EIO);\n\n }\n\n /* Receive C1 */\n\n ret = rtmp_receive_hs_packet(rt, &hs_epoch, &zeroes, hs_c1,\n\n RTMP_HANDSHAKE_PACKET_SIZE);\n\n if (ret) {\n\n av_log(s, AV_LOG_ERROR, \"RTMP Handshake C1 Error\\n\");\n\n return ret;\n\n }\n\n if (zeroes)\n\n av_log(s, AV_LOG_WARNING, \"Erroneous C1 Message zero != 0\\n\");\n\n /* Send S1 */\n\n /* By now same epoch will be sent */\n\n hs_my_epoch = hs_epoch;\n\n /* Generate random */\n\n for (randomidx = 0; randomidx < (RTMP_HANDSHAKE_PACKET_SIZE);\n\n randomidx += 4)\n\n AV_WB32(hs_s1 + 8 + randomidx, av_get_random_seed());\n\n\n\n ret = rtmp_send_hs_packet(rt, hs_my_epoch, 0, hs_s1,\n\n RTMP_HANDSHAKE_PACKET_SIZE);\n\n if (ret) {\n\n av_log(s, AV_LOG_ERROR, \"RTMP Handshake S1 Error\\n\");\n\n return ret;\n\n }\n\n /* Send S2 */\n\n ret = rtmp_send_hs_packet(rt, hs_epoch, 0, hs_c1,\n\n RTMP_HANDSHAKE_PACKET_SIZE);\n\n if (ret) {\n\n av_log(s, AV_LOG_ERROR, \"RTMP Handshake S2 Error\\n\");\n\n return ret;\n\n }\n\n /* Receive C2 */\n\n ret = rtmp_receive_hs_packet(rt, &temp, &zeroes, buffer,\n\n RTMP_HANDSHAKE_PACKET_SIZE);\n\n if (ret) {\n\n av_log(s, AV_LOG_ERROR, \"RTMP Handshake C2 Error\\n\");\n\n return ret;\n\n }\n\n if (temp != hs_my_epoch)\n\n av_log(s, AV_LOG_WARNING,\n\n \"Erroneous C2 Message epoch does not match up with C1 epoch\\n\");\n\n if (memcmp(buffer + 8, hs_s1 + 8,\n\n RTMP_HANDSHAKE_PACKET_SIZE - 8))\n\n av_log(s, AV_LOG_WARNING,\n\n \"Erroneous C2 Message random does not match up\\n\");\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 532 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold void dump_enc_cfg(AVCodecContext *avctx,\n\n const struct vpx_codec_enc_cfg *cfg)\n\n{\n\n int width = -30;\n\n int level = AV_LOG_DEBUG;\n\n\n\n av_log(avctx, level, \"vpx_codec_enc_cfg\\n\");\n\n av_log(avctx, level, \"generic settings\\n\"\n\n \" %*s%u\\n %*s%u\\n %*s%u\\n %*s%u\\n %*s%u\\n\"\n\n#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)\n\n \" %*s%u\\n %*s%u\\n\"\n\n#endif\n\n \" %*s{%u/%u}\\n %*s%u\\n %*s%d\\n %*s%u\\n\",\n\n width, \"g_usage:\", cfg->g_usage,\n\n width, \"g_threads:\", cfg->g_threads,\n\n width, \"g_profile:\", cfg->g_profile,\n\n width, \"g_w:\", cfg->g_w,\n\n width, \"g_h:\", cfg->g_h,\n\n#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)\n\n width, \"g_bit_depth:\", cfg->g_bit_depth,\n\n width, \"g_input_bit_depth:\", cfg->g_input_bit_depth,\n\n#endif\n\n width, \"g_timebase:\", cfg->g_timebase.num, cfg->g_timebase.den,\n\n width, \"g_error_resilient:\", cfg->g_error_resilient,\n\n width, \"g_pass:\", cfg->g_pass,\n\n width, \"g_lag_in_frames:\", cfg->g_lag_in_frames);\n\n av_log(avctx, level, \"rate control settings\\n\"\n\n \" %*s%u\\n %*s%u\\n %*s%u\\n %*s%u\\n\"\n\n \" %*s%d\\n %*s%p(%\"SIZE_SPECIFIER\")\\n %*s%u\\n\",\n\n width, \"rc_dropframe_thresh:\", cfg->rc_dropframe_thresh,\n\n width, \"rc_resize_allowed:\", cfg->rc_resize_allowed,\n\n width, \"rc_resize_up_thresh:\", cfg->rc_resize_up_thresh,\n\n width, \"rc_resize_down_thresh:\", cfg->rc_resize_down_thresh,\n\n width, \"rc_end_usage:\", cfg->rc_end_usage,\n\n width, \"rc_twopass_stats_in:\", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,\n\n width, \"rc_target_bitrate:\", cfg->rc_target_bitrate);\n\n av_log(avctx, level, \"quantizer settings\\n\"\n\n \" %*s%u\\n %*s%u\\n\",\n\n width, \"rc_min_quantizer:\", cfg->rc_min_quantizer,\n\n width, \"rc_max_quantizer:\", cfg->rc_max_quantizer);\n\n av_log(avctx, level, \"bitrate tolerance\\n\"\n\n \" %*s%u\\n %*s%u\\n\",\n\n width, \"rc_undershoot_pct:\", cfg->rc_undershoot_pct,\n\n width, \"rc_overshoot_pct:\", cfg->rc_overshoot_pct);\n\n av_log(avctx, level, \"decoder buffer model\\n\"\n\n \" %*s%u\\n %*s%u\\n %*s%u\\n\",\n\n width, \"rc_buf_sz:\", cfg->rc_buf_sz,\n\n width, \"rc_buf_initial_sz:\", cfg->rc_buf_initial_sz,\n\n width, \"rc_buf_optimal_sz:\", cfg->rc_buf_optimal_sz);\n\n av_log(avctx, level, \"2 pass rate control settings\\n\"\n\n \" %*s%u\\n %*s%u\\n %*s%u\\n\",\n\n width, \"rc_2pass_vbr_bias_pct:\", cfg->rc_2pass_vbr_bias_pct,\n\n width, \"rc_2pass_vbr_minsection_pct:\", cfg->rc_2pass_vbr_minsection_pct,\n\n width, \"rc_2pass_vbr_maxsection_pct:\", cfg->rc_2pass_vbr_maxsection_pct);\n\n av_log(avctx, level, \"keyframing settings\\n\"\n\n \" %*s%d\\n %*s%u\\n %*s%u\\n\",\n\n width, \"kf_mode:\", cfg->kf_mode,\n\n width, \"kf_min_dist:\", cfg->kf_min_dist,\n\n width, \"kf_max_dist:\", cfg->kf_max_dist);\n\n av_log(avctx, level, \"\\n\");\n\n}\n", + "output": "0", + "index": 18777 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)\n\n{\n\n unsigned char tag[5];\n\n unsigned int flags = 0;\n\n const int stream_index = pkt->stream_index;\n\n int size = pkt->size;\n\n AVIContext *avi = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n AVIStream *avist = s->streams[stream_index]->priv_data;\n\n AVCodecParameters *par = s->streams[stream_index]->codecpar;\n\n\n\n while (par->block_align == 0 && pkt->dts != AV_NOPTS_VALUE &&\n\n pkt->dts > avist->packet_count) {\n\n AVPacket empty_packet;\n\n\n\n av_init_packet(&empty_packet);\n\n empty_packet.size = 0;\n\n empty_packet.data = NULL;\n\n empty_packet.stream_index = stream_index;\n\n avi_write_packet(s, &empty_packet);\n\n }\n\n avist->packet_count++;\n\n\n\n // Make sure to put an OpenDML chunk when the file size exceeds the limits\n\n if (pb->seekable &&\n\n (avio_tell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) {\n\n avi_write_ix(s);\n\n ff_end_tag(pb, avi->movi_list);\n\n\n\n if (avi->riff_id == 1)\n\n avi_write_idx1(s);\n\n\n\n ff_end_tag(pb, avi->riff_start);\n\n avi->movi_list = avi_start_new_riff(s, pb, \"AVIX\", \"movi\");\n\n }\n\n\n\n avi_stream2fourcc(tag, stream_index, par->codec_type);\n\n if (pkt->flags & AV_PKT_FLAG_KEY)\n\n flags = 0x10;\n\n if (par->codec_type == AVMEDIA_TYPE_AUDIO)\n\n avist->audio_strm_length += size;\n\n\n\n if (s->pb->seekable) {\n\n int err;\n\n AVIIndex *idx = &avist->indexes;\n\n int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;\n\n int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;\n\n if (idx->ents_allocated <= idx->entry) {\n\n if ((err = av_reallocp(&idx->cluster,\n\n (cl + 1) * sizeof(*idx->cluster))) < 0) {\n\n idx->ents_allocated = 0;\n\n idx->entry = 0;\n\n return err;\n\n }\n\n idx->cluster[cl] =\n\n av_malloc(AVI_INDEX_CLUSTER_SIZE * sizeof(AVIIentry));\n\n if (!idx->cluster[cl])\n\n return -1;\n\n idx->ents_allocated += AVI_INDEX_CLUSTER_SIZE;\n\n }\n\n\n\n idx->cluster[cl][id].flags = flags;\n\n idx->cluster[cl][id].pos = avio_tell(pb) - avi->movi_list;\n\n idx->cluster[cl][id].len = size;\n\n idx->entry++;\n\n }\n\n\n\n avio_write(pb, tag, 4);\n\n avio_wl32(pb, size);\n\n avio_write(pb, pkt->data, size);\n\n if (size & 1)\n\n avio_w8(pb, 0);\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 11527 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void ac97_initfn (PCIDevice *dev)\n\n{\n\n PCIAC97LinkState *d = DO_UPCAST (PCIAC97LinkState, dev, dev);\n\n AC97LinkState *s = &d->ac97;\n\n uint8_t *c = d->dev.config;\n\n\n\n s->pci_dev = &d->dev;\n\n pci_config_set_vendor_id (c, PCI_VENDOR_ID_INTEL); /* ro */\n\n pci_config_set_device_id (c, PCI_DEVICE_ID_INTEL_82801AA_5); /* ro */\n\n\n\n c[0x04] = 0x00; /* pcicmd pci command rw, ro */\n\n c[0x05] = 0x00;\n\n\n\n c[0x06] = 0x80; /* pcists pci status rwc, ro */\n\n c[0x07] = 0x02;\n\n\n\n c[0x08] = 0x01; /* rid revision ro */\n\n c[0x09] = 0x00; /* pi programming interface ro */\n\n pci_config_set_class (c, PCI_CLASS_MULTIMEDIA_AUDIO); /* ro */\n\n c[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; /* headtyp header type ro */\n\n\n\n c[0x10] = 0x01; /* nabmar native audio mixer base\n\n address rw */\n\n c[0x11] = 0x00;\n\n c[0x12] = 0x00;\n\n c[0x13] = 0x00;\n\n\n\n c[0x14] = 0x01; /* nabmbar native audio bus mastering\n\n base address rw */\n\n c[0x15] = 0x00;\n\n c[0x16] = 0x00;\n\n c[0x17] = 0x00;\n\n\n\n c[0x2c] = 0x86; /* svid subsystem vendor id rwo */\n\n c[0x2d] = 0x80;\n\n\n\n c[0x2e] = 0x00; /* sid subsystem id rwo */\n\n c[0x2f] = 0x00;\n\n\n\n c[0x3c] = 0x00; /* intr_ln interrupt line rw */\n\n c[0x3d] = 0x01; /* intr_pn interrupt pin ro */\n\n\n\n pci_register_bar (&d->dev, 0, 256 * 4, PCI_ADDRESS_SPACE_IO, ac97_map);\n\n pci_register_bar (&d->dev, 1, 64 * 4, PCI_ADDRESS_SPACE_IO, ac97_map);\n\n register_savevm (\"ac97\", 0, 2, ac97_save, ac97_load, s);\n\n qemu_register_reset (ac97_on_reset, s);\n\n AUD_register_card (\"ac97\", &s->card);\n\n ac97_on_reset (s);\n\n}\n", + "output": "0", + "index": 15549 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value)\n\n{\n\n struct vmsvga_state_s *s = opaque;\n\n\n\n if (s->index >= SVGA_SCRATCH_BASE) {\n\n trace_vmware_scratch_write(s->index, value);\n\n } else if (s->index >= SVGA_PALETTE_BASE) {\n\n trace_vmware_palette_write(s->index, value);\n\n } else {\n\n trace_vmware_value_write(s->index, value);\n\n }\n\n switch (s->index) {\n\n case SVGA_REG_ID:\n\n if (value == SVGA_ID_2 || value == SVGA_ID_1 || value == SVGA_ID_0) {\n\n s->svgaid = value;\n\n }\n\n break;\n\n\n\n case SVGA_REG_ENABLE:\n\n s->enable = !!value;\n\n s->invalidated = 1;\n\n s->vga.hw_ops->invalidate(&s->vga);\n\n if (s->enable && s->config) {\n\n vga_dirty_log_stop(&s->vga);\n\n } else {\n\n vga_dirty_log_start(&s->vga);\n\n }\n\n break;\n\n\n\n case SVGA_REG_WIDTH:\n\n if (value <= SVGA_MAX_WIDTH) {\n\n s->new_width = value;\n\n s->invalidated = 1;\n\n } else {\n\n printf(\"%s: Bad width: %i\\n\", __func__, value);\n\n }\n\n break;\n\n\n\n case SVGA_REG_HEIGHT:\n\n if (value <= SVGA_MAX_HEIGHT) {\n\n s->new_height = value;\n\n s->invalidated = 1;\n\n } else {\n\n printf(\"%s: Bad height: %i\\n\", __func__, value);\n\n }\n\n break;\n\n\n\n case SVGA_REG_BITS_PER_PIXEL:\n\n if (value != 32) {\n\n printf(\"%s: Bad bits per pixel: %i bits\\n\", __func__, value);\n\n s->config = 0;\n\n s->invalidated = 1;\n\n }\n\n break;\n\n\n\n case SVGA_REG_CONFIG_DONE:\n\n if (value) {\n\n s->fifo = (uint32_t *) s->fifo_ptr;\n\n /* Check range and alignment. */\n\n if ((CMD(min) | CMD(max) | CMD(next_cmd) | CMD(stop)) & 3) {\n\n break;\n\n }\n\n if (CMD(min) < (uint8_t *) s->cmd->fifo - (uint8_t *) s->fifo) {\n\n break;\n\n }\n\n if (CMD(max) > SVGA_FIFO_SIZE) {\n\n break;\n\n }\n\n if (CMD(max) < CMD(min) + 10 * 1024) {\n\n break;\n\n }\n\n vga_dirty_log_stop(&s->vga);\n\n }\n\n s->config = !!value;\n\n break;\n\n\n\n case SVGA_REG_SYNC:\n\n s->syncing = 1;\n\n vmsvga_fifo_run(s); /* Or should we just wait for update_display? */\n\n break;\n\n\n\n case SVGA_REG_GUEST_ID:\n\n s->guest = value;\n\n#ifdef VERBOSE\n\n if (value >= GUEST_OS_BASE && value < GUEST_OS_BASE +\n\n ARRAY_SIZE(vmsvga_guest_id)) {\n\n printf(\"%s: guest runs %s.\\n\", __func__,\n\n vmsvga_guest_id[value - GUEST_OS_BASE]);\n\n }\n\n#endif\n\n break;\n\n\n\n case SVGA_REG_CURSOR_ID:\n\n s->cursor.id = value;\n\n break;\n\n\n\n case SVGA_REG_CURSOR_X:\n\n s->cursor.x = value;\n\n break;\n\n\n\n case SVGA_REG_CURSOR_Y:\n\n s->cursor.y = value;\n\n break;\n\n\n\n case SVGA_REG_CURSOR_ON:\n\n s->cursor.on |= (value == SVGA_CURSOR_ON_SHOW);\n\n s->cursor.on &= (value != SVGA_CURSOR_ON_HIDE);\n\n#ifdef HW_MOUSE_ACCEL\n\n if (value <= SVGA_CURSOR_ON_SHOW) {\n\n dpy_mouse_set(s->vga.con, s->cursor.x, s->cursor.y, s->cursor.on);\n\n }\n\n#endif\n\n break;\n\n\n\n case SVGA_REG_DEPTH:\n\n case SVGA_REG_MEM_REGS:\n\n case SVGA_REG_NUM_DISPLAYS:\n\n case SVGA_REG_PITCHLOCK:\n\n case SVGA_PALETTE_BASE ... SVGA_PALETTE_END:\n\n break;\n\n\n\n default:\n\n if (s->index >= SVGA_SCRATCH_BASE &&\n\n s->index < SVGA_SCRATCH_BASE + s->scratch_size) {\n\n s->scratch[s->index - SVGA_SCRATCH_BASE] = value;\n\n break;\n\n }\n\n printf(\"%s: Bad register %02x\\n\", __func__, s->index);\n\n }\n\n}\n", + "output": "1", + "index": 11385 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int nut_write_header(AVFormatContext *s)\n\n{\n\n NUTContext *nut = s->priv_data;\n\n AVIOContext *bc = s->pb;\n\n int i, j, ret;\n\n\n\n nut->avf = s;\n\n\n\n nut->version = FFMAX(NUT_STABLE_VERSION, 3 + !!nut->flags);\n\n if (nut->flags && s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"The additional syncpoint modes require version %d, \"\n\n \"that is currently not finalized, \"\n\n \"please set -f_strict experimental in order to enable it.\\n\",\n\n nut->version);\n\n return AVERROR_EXPERIMENTAL;\n\n }\n\n\n\n nut->stream = av_calloc(s->nb_streams, sizeof(*nut->stream ));\n\n nut->chapter = av_calloc(s->nb_chapters, sizeof(*nut->chapter));\n\n nut->time_base= av_calloc(s->nb_streams +\n\n s->nb_chapters, sizeof(*nut->time_base));\n\n if (!nut->stream || !nut->chapter || !nut->time_base) {\n\n av_freep(&nut->stream);\n\n av_freep(&nut->chapter);\n\n av_freep(&nut->time_base);\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n for (i = 0; i < s->nb_streams; i++) {\n\n AVStream *st = s->streams[i];\n\n int ssize;\n\n AVRational time_base;\n\n ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num);\n\n\n\n if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->sample_rate) {\n\n time_base = (AVRational) {1, st->codec->sample_rate};\n\n } else {\n\n time_base = ff_choose_timebase(s, st, 48000);\n\n }\n\n\n\n avpriv_set_pts_info(st, 64, time_base.num, time_base.den);\n\n\n\n for (j = 0; j < nut->time_base_count; j++)\n\n if (!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))) {\n\n break;\n\n }\n\n nut->time_base[j] = time_base;\n\n nut->stream[i].time_base = &nut->time_base[j];\n\n if (j == nut->time_base_count)\n\n nut->time_base_count++;\n\n\n\n if (INT64_C(1000) * time_base.num >= time_base.den)\n\n nut->stream[i].msb_pts_shift = 7;\n\n else\n\n nut->stream[i].msb_pts_shift = 14;\n\n nut->stream[i].max_pts_distance =\n\n FFMAX(time_base.den, time_base.num) / time_base.num;\n\n }\n\n\n\n for (i = 0; i < s->nb_chapters; i++) {\n\n AVChapter *ch = s->chapters[i];\n\n\n\n for (j = 0; j < nut->time_base_count; j++)\n\n if (!memcmp(&ch->time_base, &nut->time_base[j], sizeof(AVRational)))\n\n break;\n\n\n\n nut->time_base[j] = ch->time_base;\n\n nut->chapter[i].time_base = &nut->time_base[j];\n\n if (j == nut->time_base_count)\n\n nut->time_base_count++;\n\n }\n\n\n\n nut->max_distance = MAX_DISTANCE;\n\n build_elision_headers(s);\n\n build_frame_code(s);\n\n av_assert0(nut->frame_code['N'].flags == FLAG_INVALID);\n\n\n\n avio_write(bc, ID_STRING, strlen(ID_STRING));\n\n avio_w8(bc, 0);\n\n\n\n if ((ret = write_headers(s, bc)) < 0)\n\n return ret;\n\n\n\n if (s->avoid_negative_ts < 0)\n\n s->avoid_negative_ts = 1;\n\n\n\n avio_flush(bc);\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 21237 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void ide_dma_cb(void *opaque, int ret)\n\n{\n\n IDEState *s = opaque;\n\n int n;\n\n int64_t sector_num;\n\n bool stay_active = false;\n\n\n\n if (ret == -ECANCELED) {\n\n return;\n\n }\n\n if (ret < 0) {\n\n int op = IDE_RETRY_DMA;\n\n\n\n if (s->dma_cmd == IDE_DMA_READ)\n\n op |= IDE_RETRY_READ;\n\n else if (s->dma_cmd == IDE_DMA_TRIM)\n\n op |= IDE_RETRY_TRIM;\n\n\n\n if (ide_handle_rw_error(s, -ret, op)) {\n\n return;\n\n }\n\n }\n\n\n\n n = s->io_buffer_size >> 9;\n\n if (n > s->nsector) {\n\n /* The PRDs were longer than needed for this request. Shorten them so\n\n * we don't get a negative remainder. The Active bit must remain set\n\n * after the request completes. */\n\n n = s->nsector;\n\n stay_active = true;\n\n }\n\n\n\n sector_num = ide_get_sector(s);\n\n if (n > 0) {\n\n assert(s->io_buffer_size == s->sg.size);\n\n dma_buf_commit(s, s->io_buffer_size);\n\n sector_num += n;\n\n ide_set_sector(s, sector_num);\n\n s->nsector -= n;\n\n }\n\n\n\n /* end of transfer ? */\n\n if (s->nsector == 0) {\n\n s->status = READY_STAT | SEEK_STAT;\n\n ide_set_irq(s->bus);\n\n goto eot;\n\n }\n\n\n\n /* launch next transfer */\n\n n = s->nsector;\n\n s->io_buffer_index = 0;\n\n s->io_buffer_size = n * 512;\n\n if (s->bus->dma->ops->prepare_buf(s->bus->dma, ide_cmd_is_read(s)) < 512) {\n\n /* The PRDs were too short. Reset the Active bit, but don't raise an\n\n * interrupt. */\n\n s->status = READY_STAT | SEEK_STAT;\n\n dma_buf_commit(s, 0);\n\n goto eot;\n\n }\n\n\n\n#ifdef DEBUG_AIO\n\n printf(\"ide_dma_cb: sector_num=%\" PRId64 \" n=%d, cmd_cmd=%d\\n\",\n\n sector_num, n, s->dma_cmd);\n\n#endif\n\n\n\n if ((s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) &&\n\n !ide_sect_range_ok(s, sector_num, n)) {\n\n ide_dma_error(s);\n\n return;\n\n }\n\n\n\n switch (s->dma_cmd) {\n\n case IDE_DMA_READ:\n\n s->bus->dma->aiocb = dma_blk_read(s->blk, &s->sg, sector_num,\n\n ide_dma_cb, s);\n\n break;\n\n case IDE_DMA_WRITE:\n\n s->bus->dma->aiocb = dma_blk_write(s->blk, &s->sg, sector_num,\n\n ide_dma_cb, s);\n\n break;\n\n case IDE_DMA_TRIM:\n\n s->bus->dma->aiocb = dma_blk_io(s->blk, &s->sg, sector_num,\n\n ide_issue_trim, ide_dma_cb, s,\n\n DMA_DIRECTION_TO_DEVICE);\n\n break;\n\n }\n\n return;\n\n\n\neot:\n\n if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) {\n\n block_acct_done(blk_get_stats(s->blk), &s->acct);\n\n }\n\n ide_set_inactive(s, stay_active);\n\n}\n", + "output": "1", + "index": 3075 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void xchg_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int xchg, int simple){\n\n MpegEncContext * const s = &h->s;\n\n int temp8, i;\n\n uint64_t temp64;\n\n int deblock_left;\n\n int deblock_top;\n\n int mb_xy;\n\n int step = 1;\n\n int offset = 1;\n\n int uvoffset= 1;\n\n int top_idx = 1;\n\n\n\n if(!simple && FRAME_MBAFF){\n\n if(s->mb_y&1){\n\n offset = MB_MBAFF ? 1 : 17;\n\n uvoffset= MB_MBAFF ? 1 : 9;\n\n }else{\n\n offset =\n\n uvoffset=\n\n top_idx = MB_MBAFF ? 0 : 1;\n\n }\n\n step= MB_MBAFF ? 2 : 1;\n\n }\n\n\n\n if(h->deblocking_filter == 2) {\n\n mb_xy = h->mb_xy;\n\n deblock_left = h->slice_table[mb_xy] == h->slice_table[mb_xy - 1];\n\n deblock_top = h->slice_table[mb_xy] == h->slice_table[h->top_mb_xy];\n\n } else {\n\n deblock_left = (s->mb_x > 0);\n\n deblock_top = (s->mb_y > !!MB_FIELD);\n\n }\n\n\n\n src_y -= linesize + 1;\n\n src_cb -= uvlinesize + 1;\n\n src_cr -= uvlinesize + 1;\n\n\n\n#define XCHG(a,b,t,xchg)\\\n\nt= a;\\\n\nif(xchg)\\\n\n a= b;\\\n\nb= t;\n\n\n\n if(deblock_left){\n\n for(i = !deblock_top; i<16; i++){\n\n XCHG(h->left_border[offset+i*step], src_y [i* linesize], temp8, xchg);\n\n }\n\n XCHG(h->left_border[offset+i*step], src_y [i* linesize], temp8, 1);\n\n }\n\n\n\n if(deblock_top){\n\n XCHG(*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+0), *(uint64_t*)(src_y +1), temp64, xchg);\n\n XCHG(*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+8), *(uint64_t*)(src_y +9), temp64, 1);\n\n if(s->mb_x+1 < s->mb_width){\n\n XCHG(*(uint64_t*)(h->top_borders[top_idx][s->mb_x+1]), *(uint64_t*)(src_y +17), temp64, 1);\n\n }\n\n }\n\n\n\n if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){\n\n if(deblock_left){\n\n for(i = !deblock_top; i<8; i++){\n\n XCHG(h->left_border[uvoffset+34 +i*step], src_cb[i*uvlinesize], temp8, xchg);\n\n XCHG(h->left_border[uvoffset+34+18+i*step], src_cr[i*uvlinesize], temp8, xchg);\n\n }\n\n XCHG(h->left_border[uvoffset+34 +i*step], src_cb[i*uvlinesize], temp8, 1);\n\n XCHG(h->left_border[uvoffset+34+18+i*step], src_cr[i*uvlinesize], temp8, 1);\n\n }\n\n if(deblock_top){\n\n XCHG(*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+16), *(uint64_t*)(src_cb+1), temp64, 1);\n\n XCHG(*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+24), *(uint64_t*)(src_cr+1), temp64, 1);\n\n }\n\n }\n\n}\n", + "output": "0", + "index": 18749 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int writev_f(BlockBackend *blk, int argc, char **argv)\n\n{\n\n struct timeval t1, t2;\n\n int Cflag = 0, qflag = 0;\n\n int c, cnt;\n\n char *buf;\n\n int64_t offset;\n\n /* Some compilers get confused and warn if this is not initialized. */\n\n int total = 0;\n\n int nr_iov;\n\n int pattern = 0xcd;\n\n QEMUIOVector qiov;\n\n\n\n while ((c = getopt(argc, argv, \"CqP:\")) != EOF) {\n\n switch (c) {\n\n case 'C':\n\n Cflag = 1;\n\n break;\n\n case 'q':\n\n qflag = 1;\n\n break;\n\n case 'P':\n\n pattern = parse_pattern(optarg);\n\n if (pattern < 0) {\n\n return 0;\n\n }\n\n break;\n\n default:\n\n return qemuio_command_usage(&writev_cmd);\n\n }\n\n }\n\n\n\n if (optind > argc - 2) {\n\n return qemuio_command_usage(&writev_cmd);\n\n }\n\n\n\n offset = cvtnum(argv[optind]);\n\n if (offset < 0) {\n\n printf(\"non-numeric length argument -- %s\\n\", argv[optind]);\n\n return 0;\n\n }\n\n optind++;\n\n\n\n if (offset & 0x1ff) {\n\n printf(\"offset %\" PRId64 \" is not sector aligned\\n\",\n\n offset);\n\n return 0;\n\n }\n\n\n\n nr_iov = argc - optind;\n\n buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern);\n\n if (buf == NULL) {\n\n return 0;\n\n }\n\n\n\n gettimeofday(&t1, NULL);\n\n cnt = do_aio_writev(blk, &qiov, offset, &total);\n\n gettimeofday(&t2, NULL);\n\n\n\n if (cnt < 0) {\n\n printf(\"writev failed: %s\\n\", strerror(-cnt));\n\n goto out;\n\n }\n\n\n\n if (qflag) {\n\n goto out;\n\n }\n\n\n\n /* Finally, report back -- -C gives a parsable format */\n\n t2 = tsub(t2, t1);\n\n print_report(\"wrote\", &t2, offset, qiov.size, total, cnt, Cflag);\n\nout:\n\n qemu_iovec_destroy(&qiov);\n\n qemu_io_free(buf);\n\n return 0;\n\n}\n", + "output": "0", + "index": 14793 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "vcard_emul_mirror_card(VReader *vreader)\n\n{\n\n /*\n\n * lookup certs using the C_FindObjects. The Stan Cert handle won't give\n\n * us the real certs until we log in.\n\n */\n\n PK11GenericObject *firstObj, *thisObj;\n\n int cert_count;\n\n unsigned char **certs;\n\n int *cert_len;\n\n VCardKey **keys;\n\n PK11SlotInfo *slot;\n\n VCard *card;\n\n\n\n slot = vcard_emul_reader_get_slot(vreader);\n\n if (slot == NULL) {\n\n return NULL;\n\n }\n\n\n\n firstObj = PK11_FindGenericObjects(slot, CKO_CERTIFICATE);\n\n if (firstObj == NULL) {\n\n return NULL;\n\n }\n\n\n\n /* count the certs */\n\n cert_count = 0;\n\n for (thisObj = firstObj; thisObj;\n\n thisObj = PK11_GetNextGenericObject(thisObj)) {\n\n cert_count++;\n\n }\n\n\n\n if (cert_count == 0) {\n\n PK11_DestroyGenericObjects(firstObj);\n\n return NULL;\n\n }\n\n\n\n /* allocate the arrays */\n\n vcard_emul_alloc_arrays(&certs, &cert_len, &keys, cert_count);\n\n\n\n /* fill in the arrays */\n\n cert_count = 0;\n\n for (thisObj = firstObj; thisObj;\n\n thisObj = PK11_GetNextGenericObject(thisObj)) {\n\n SECItem derCert;\n\n CERTCertificate *cert;\n\n SECStatus rv;\n\n\n\n rv = PK11_ReadRawAttribute(PK11_TypeGeneric, thisObj,\n\n CKA_VALUE, &derCert);\n\n if (rv != SECSuccess) {\n\n continue;\n\n }\n\n /* create floating temp cert. This gives us a cert structure even if\n\n * the token isn't logged in */\n\n cert = CERT_NewTempCertificate(CERT_GetDefaultCertDB(), &derCert,\n\n NULL, PR_FALSE, PR_TRUE);\n\n SECITEM_FreeItem(&derCert, PR_FALSE);\n\n if (cert == NULL) {\n\n continue;\n\n }\n\n\n\n certs[cert_count] = cert->derCert.data;\n\n cert_len[cert_count] = cert->derCert.len;\n\n keys[cert_count] = vcard_emul_make_key(slot, cert);\n\n cert_count++;\n\n CERT_DestroyCertificate(cert); /* key obj still has a reference */\n\n }\n\n\n\n /* now create the card */\n\n card = vcard_emul_make_card(vreader, certs, cert_len, keys, cert_count);\n\n g_free(certs);\n\n g_free(cert_len);\n\n g_free(keys);\n\n\n\n return card;\n\n}\n", + "output": "0", + "index": 5582 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void h264_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha1, int beta1, int8_t *tc0)\n\n{\n\n DECLARE_ALIGNED_8(uint64_t, tmp0[2]);\n\n\n\n __asm__ volatile(\n\n \"movq (%1,%3), %%mm0 \\n\\t\" //p1\n\n \"movq (%1,%3,2), %%mm1 \\n\\t\" //p0\n\n \"movq (%2), %%mm2 \\n\\t\" //q0\n\n \"movq (%2,%3), %%mm3 \\n\\t\" //q1\n\n H264_DEBLOCK_MASK(%6, %7)\n\n\n\n \"movd %5, %%mm4 \\n\\t\"\n\n \"punpcklbw %%mm4, %%mm4 \\n\\t\"\n\n \"punpcklwd %%mm4, %%mm4 \\n\\t\"\n\n \"pcmpeqb %%mm3, %%mm3 \\n\\t\"\n\n \"movq %%mm4, %%mm6 \\n\\t\"\n\n \"pcmpgtb %%mm3, %%mm4 \\n\\t\"\n\n \"movq %%mm6, 8+%0 \\n\\t\"\n\n \"pand %%mm4, %%mm7 \\n\\t\"\n\n \"movq %%mm7, %0 \\n\\t\"\n\n\n\n /* filter p1 */\n\n \"movq (%1), %%mm3 \\n\\t\" //p2\n\n DIFF_GT2_MMX(%%mm1, %%mm3, %%mm5, %%mm6, %%mm4) // |p2-p0|>beta-1\n\n \"pand %%mm7, %%mm6 \\n\\t\" // mask & |p2-p0|beta-1\n\n \"pand %0, %%mm6 \\n\\t\"\n\n \"movq 8+%0, %%mm5 \\n\\t\" // can be merged with the and below but is slower then\n\n \"pand %%mm6, %%mm5 \\n\\t\"\n\n \"psubb %%mm6, %%mm7 \\n\\t\"\n\n \"movq (%2,%3), %%mm3 \\n\\t\"\n\n H264_DEBLOCK_Q1(%%mm3, %%mm4, \"(%2,%3,2)\", \"(%2,%3)\", %%mm5, %%mm6)\n\n\n\n /* filter p0, q0 */\n\n H264_DEBLOCK_P0_Q0(%8, unused)\n\n \"movq %%mm1, (%1,%3,2) \\n\\t\"\n\n \"movq %%mm2, (%2) \\n\\t\"\n\n\n\n : \"=m\"(*tmp0)\n\n : \"r\"(pix-3*stride), \"r\"(pix), \"r\"((x86_reg)stride),\n\n \"m\"(*tmp0/*unused*/), \"m\"(*(uint32_t*)tc0), \"m\"(alpha1), \"m\"(beta1),\n\n \"m\"(ff_bone)\n\n );\n\n}\n", + "output": "0", + "index": 27102 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void integratorcm_write(void *opaque, target_phys_addr_t offset,\n\n uint64_t value, unsigned size)\n\n{\n\n integratorcm_state *s = (integratorcm_state *)opaque;\n\n switch (offset >> 2) {\n\n case 2: /* CM_OSC */\n\n if (s->cm_lock == 0xa05f)\n\n s->cm_osc = value;\n\n break;\n\n case 3: /* CM_CTRL */\n\n integratorcm_set_ctrl(s, value);\n\n break;\n\n case 5: /* CM_LOCK */\n\n s->cm_lock = value & 0xffff;\n\n break;\n\n case 7: /* CM_AUXOSC */\n\n if (s->cm_lock == 0xa05f)\n\n s->cm_auxosc = value;\n\n break;\n\n case 8: /* CM_SDRAM */\n\n s->cm_sdram = value;\n\n break;\n\n case 9: /* CM_INIT */\n\n /* ??? This can change the memory bus frequency. */\n\n s->cm_init = value;\n\n break;\n\n case 12: /* CM_FLAGSS */\n\n s->cm_flags |= value;\n\n break;\n\n case 13: /* CM_FLAGSC */\n\n s->cm_flags &= ~value;\n\n break;\n\n case 14: /* CM_NVFLAGSS */\n\n s->cm_nvflags |= value;\n\n break;\n\n case 15: /* CM_NVFLAGSS */\n\n s->cm_nvflags &= ~value;\n\n break;\n\n case 18: /* CM_IRQ_ENSET */\n\n s->irq_enabled |= value;\n\n integratorcm_update(s);\n\n break;\n\n case 19: /* CM_IRQ_ENCLR */\n\n s->irq_enabled &= ~value;\n\n integratorcm_update(s);\n\n break;\n\n case 20: /* CM_SOFT_INTSET */\n\n s->int_level |= (value & 1);\n\n integratorcm_update(s);\n\n break;\n\n case 21: /* CM_SOFT_INTCLR */\n\n s->int_level &= ~(value & 1);\n\n integratorcm_update(s);\n\n break;\n\n case 26: /* CM_FIQ_ENSET */\n\n s->fiq_enabled |= value;\n\n integratorcm_update(s);\n\n break;\n\n case 27: /* CM_FIQ_ENCLR */\n\n s->fiq_enabled &= ~value;\n\n integratorcm_update(s);\n\n break;\n\n case 32: /* CM_VOLTAGE_CTL0 */\n\n case 33: /* CM_VOLTAGE_CTL1 */\n\n case 34: /* CM_VOLTAGE_CTL2 */\n\n case 35: /* CM_VOLTAGE_CTL3 */\n\n /* ??? Voltage control unimplemented. */\n\n break;\n\n default:\n\n hw_error(\"integratorcm_write: Unimplemented offset 0x%x\\n\",\n\n (int)offset);\n\n break;\n\n }\n\n}\n", + "output": "0", + "index": 18905 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int flv_same_audio_codec(AVCodecContext *acodec, int flags)\n\n{\n\n int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;\n\n int flv_codecid = flags & FLV_AUDIO_CODECID_MASK;\n\n int codec_id;\n\n\n\n if (!acodec->codec_id && !acodec->codec_tag)\n\n return 1;\n\n\n\n if (acodec->bits_per_coded_sample != bits_per_coded_sample)\n\n return 0;\n\n\n\n switch(flv_codecid) {\n\n //no distinction between S16 and S8 PCM codec flags\n\n case FLV_CODECID_PCM:\n\n codec_id = bits_per_coded_sample == 8 ? AV_CODEC_ID_PCM_U8 :\n\n#if HAVE_BIGENDIAN\n\n AV_CODEC_ID_PCM_S16BE;\n\n#else\n\n AV_CODEC_ID_PCM_S16LE;\n\n#endif\n\n return codec_id == acodec->codec_id;\n\n case FLV_CODECID_PCM_LE:\n\n codec_id = bits_per_coded_sample == 8 ? AV_CODEC_ID_PCM_U8 : AV_CODEC_ID_PCM_S16LE;\n\n return codec_id == acodec->codec_id;\n\n case FLV_CODECID_AAC:\n\n return acodec->codec_id == AV_CODEC_ID_AAC;\n\n case FLV_CODECID_ADPCM:\n\n return acodec->codec_id == AV_CODEC_ID_ADPCM_SWF;\n\n case FLV_CODECID_SPEEX:\n\n return acodec->codec_id == AV_CODEC_ID_SPEEX;\n\n case FLV_CODECID_MP3:\n\n return acodec->codec_id == AV_CODEC_ID_MP3;\n\n case FLV_CODECID_NELLYMOSER_8KHZ_MONO:\n\n case FLV_CODECID_NELLYMOSER_16KHZ_MONO:\n\n case FLV_CODECID_NELLYMOSER:\n\n return acodec->codec_id == AV_CODEC_ID_NELLYMOSER;\n\n case FLV_CODECID_PCM_MULAW:\n\n return acodec->sample_rate == 8000 &&\n\n acodec->codec_id == AV_CODEC_ID_PCM_MULAW;\n\n case FLV_CODECID_PCM_ALAW:\n\n return acodec->sample_rate = 8000 &&\n\n acodec->codec_id == AV_CODEC_ID_PCM_ALAW;\n\n default:\n\n return acodec->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);\n\n }\n\n}\n", + "output": "0", + "index": 22829 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void av_estimate_timings_from_pts(AVFormatContext *ic)\n\n{\n\n AVPacket pkt1, *pkt = &pkt1;\n\n AVStream *st;\n\n int read_size, i, ret;\n\n int64_t end_time;\n\n int64_t filesize, offset, duration;\n\n\n\n /* free previous packet */\n\n if (ic->cur_st && ic->cur_st->parser)\n\n av_free_packet(&ic->cur_pkt);\n\n ic->cur_st = NULL;\n\n\n\n /* flush packet queue */\n\n flush_packet_queue(ic);\n\n\n\n for(i=0;inb_streams;i++) {\n\n st = ic->streams[i];\n\n if (st->parser) {\n\n av_parser_close(st->parser);\n\n st->parser= NULL;\n\n }\n\n }\n\n\n\n /* we read the first packets to get the first PTS (not fully\n\n accurate, but it is enough now) */\n\n url_fseek(&ic->pb, 0, SEEK_SET);\n\n read_size = 0;\n\n for(;;) {\n\n if (read_size >= DURATION_MAX_READ_SIZE)\n\n break;\n\n /* if all info is available, we can stop */\n\n for(i = 0;i < ic->nb_streams; i++) {\n\n st = ic->streams[i];\n\n if (st->start_time == AV_NOPTS_VALUE)\n\n break;\n\n }\n\n if (i == ic->nb_streams)\n\n break;\n\n\n\n ret = av_read_packet(ic, pkt);\n\n if (ret != 0)\n\n break;\n\n read_size += pkt->size;\n\n st = ic->streams[pkt->stream_index];\n\n if (pkt->pts != AV_NOPTS_VALUE) {\n\n if (st->start_time == AV_NOPTS_VALUE)\n\n st->start_time = pkt->pts;\n\n }\n\n av_free_packet(pkt);\n\n }\n\n\n\n /* estimate the end time (duration) */\n\n /* XXX: may need to support wrapping */\n\n filesize = ic->file_size;\n\n offset = filesize - DURATION_MAX_READ_SIZE;\n\n if (offset < 0)\n\n offset = 0;\n\n\n\n url_fseek(&ic->pb, offset, SEEK_SET);\n\n read_size = 0;\n\n for(;;) {\n\n if (read_size >= DURATION_MAX_READ_SIZE)\n\n break;\n\n /* if all info is available, we can stop */\n\n for(i = 0;i < ic->nb_streams; i++) {\n\n st = ic->streams[i];\n\n if (st->duration == AV_NOPTS_VALUE)\n\n break;\n\n }\n\n if (i == ic->nb_streams)\n\n break;\n\n\n\n ret = av_read_packet(ic, pkt);\n\n if (ret != 0)\n\n break;\n\n read_size += pkt->size;\n\n st = ic->streams[pkt->stream_index];\n\n if (pkt->pts != AV_NOPTS_VALUE) {\n\n end_time = pkt->pts;\n\n duration = end_time - st->start_time;\n\n if (duration > 0) {\n\n if (st->duration == AV_NOPTS_VALUE ||\n\n st->duration < duration)\n\n st->duration = duration;\n\n }\n\n }\n\n av_free_packet(pkt);\n\n }\n\n\n\n fill_all_stream_timings(ic);\n\n\n\n url_fseek(&ic->pb, 0, SEEK_SET);\n\n}\n", + "output": "1", + "index": 8456 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int vhdx_create_new_region_table(BlockDriverState *bs,\n\n uint64_t image_size,\n\n uint32_t block_size,\n\n uint32_t sector_size,\n\n uint32_t log_size,\n\n bool use_zero_blocks,\n\n VHDXImageType type,\n\n uint64_t *metadata_offset)\n\n{\n\n int ret = 0;\n\n uint32_t offset = 0;\n\n void *buffer = NULL;\n\n uint64_t bat_file_offset;\n\n uint32_t bat_length;\n\n BDRVVHDXState *s = NULL;\n\n VHDXRegionTableHeader *region_table;\n\n VHDXRegionTableEntry *rt_bat;\n\n VHDXRegionTableEntry *rt_metadata;\n\n\n\n assert(metadata_offset != NULL);\n\n\n\n /* Populate enough of the BDRVVHDXState to be able to use the\n\n * pre-existing BAT calculation, translation, and update functions */\n\n s = g_new0(BDRVVHDXState, 1);\n\n\n\n s->chunk_ratio = (VHDX_MAX_SECTORS_PER_BLOCK) *\n\n (uint64_t) sector_size / (uint64_t) block_size;\n\n\n\n s->sectors_per_block = block_size / sector_size;\n\n s->virtual_disk_size = image_size;\n\n s->block_size = block_size;\n\n s->logical_sector_size = sector_size;\n\n\n\n vhdx_set_shift_bits(s);\n\n\n\n vhdx_calc_bat_entries(s);\n\n\n\n /* At this point the VHDX state is populated enough for creation */\n\n\n\n /* a single buffer is used so we can calculate the checksum over the\n\n * entire 64KB block */\n\n buffer = g_malloc0(VHDX_HEADER_BLOCK_SIZE);\n\n region_table = buffer;\n\n offset += sizeof(VHDXRegionTableHeader);\n\n rt_bat = buffer + offset;\n\n offset += sizeof(VHDXRegionTableEntry);\n\n rt_metadata = buffer + offset;\n\n\n\n region_table->signature = VHDX_REGION_SIGNATURE;\n\n region_table->entry_count = 2; /* BAT and Metadata */\n\n\n\n rt_bat->guid = bat_guid;\n\n rt_bat->length = ROUND_UP(s->bat_entries * sizeof(VHDXBatEntry), MiB);\n\n rt_bat->file_offset = ROUND_UP(VHDX_HEADER_SECTION_END + log_size, MiB);\n\n s->bat_offset = rt_bat->file_offset;\n\n\n\n rt_metadata->guid = metadata_guid;\n\n rt_metadata->file_offset = ROUND_UP(rt_bat->file_offset + rt_bat->length,\n\n MiB);\n\n rt_metadata->length = 1 * MiB; /* min size, and more than enough */\n\n *metadata_offset = rt_metadata->file_offset;\n\n\n\n bat_file_offset = rt_bat->file_offset;\n\n bat_length = rt_bat->length;\n\n\n\n vhdx_region_header_le_export(region_table);\n\n vhdx_region_entry_le_export(rt_bat);\n\n vhdx_region_entry_le_export(rt_metadata);\n\n\n\n vhdx_update_checksum(buffer, VHDX_HEADER_BLOCK_SIZE,\n\n offsetof(VHDXRegionTableHeader, checksum));\n\n\n\n\n\n /* The region table gives us the data we need to create the BAT,\n\n * so do that now */\n\n ret = vhdx_create_bat(bs, s, image_size, type, use_zero_blocks,\n\n bat_file_offset, bat_length);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n\n\n /* Now write out the region headers to disk */\n\n ret = bdrv_pwrite(bs, VHDX_REGION_TABLE_OFFSET, buffer,\n\n VHDX_HEADER_BLOCK_SIZE);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n\n\n ret = bdrv_pwrite(bs, VHDX_REGION_TABLE2_OFFSET, buffer,\n\n VHDX_HEADER_BLOCK_SIZE);\n\n if (ret < 0) {\n\n goto exit;\n\n }\n\n\n\nexit:\n\n g_free(s);\n\n g_free(buffer);\n\n return ret;\n\n}\n", + "output": "0", + "index": 10893 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,\n\n AVCodecContext *dec_ctx)\n\n{\n\n AVPacket enc_pkt;\n\n AVFrame *in_frame, *out_frame;\n\n uint8_t *raw_in = NULL, *raw_out = NULL;\n\n int in_offset = 0, out_offset = 0;\n\n int frame_data_size = 0;\n\n int result = 0;\n\n int got_output = 0;\n\n int i = 0;\n\n\n\n in_frame = av_frame_alloc();\n\n if (!in_frame) {\n\n av_log(NULL, AV_LOG_ERROR, \"Can't allocate input frame\\n\");\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n in_frame->nb_samples = enc_ctx->frame_size;\n\n in_frame->format = enc_ctx->sample_fmt;\n\n in_frame->channel_layout = enc_ctx->channel_layout;\n\n if (av_frame_get_buffer(in_frame, 32) != 0) {\n\n av_log(NULL, AV_LOG_ERROR, \"Can't allocate a buffer for input frame\\n\");\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n out_frame = av_frame_alloc();\n\n if (!out_frame) {\n\n av_log(NULL, AV_LOG_ERROR, \"Can't allocate output frame\\n\");\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n raw_in = av_malloc(in_frame->linesize[0] * NUMBER_OF_FRAMES);\n\n if (!raw_in) {\n\n av_log(NULL, AV_LOG_ERROR, \"Can't allocate memory for raw_in\\n\");\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n raw_out = av_malloc(in_frame->linesize[0] * NUMBER_OF_FRAMES);\n\n if (!raw_out) {\n\n av_log(NULL, AV_LOG_ERROR, \"Can't allocate memory for raw_out\\n\");\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n for (i = 0; i < NUMBER_OF_FRAMES; i++) {\n\n av_init_packet(&enc_pkt);\n\n enc_pkt.data = NULL;\n\n enc_pkt.size = 0;\n\n\n\n generate_raw_frame((uint16_t*)(in_frame->data[0]), i, enc_ctx->sample_rate,\n\n enc_ctx->channels, enc_ctx->frame_size);\n\n memcpy(raw_in + in_offset, in_frame->data[0], in_frame->linesize[0]);\n\n in_offset += in_frame->linesize[0];\n\n result = avcodec_encode_audio2(enc_ctx, &enc_pkt, in_frame, &got_output);\n\n if (result < 0) {\n\n av_log(NULL, AV_LOG_ERROR, \"Error encoding audio frame\\n\");\n\n return result;\n\n }\n\n\n\n /* if we get an encoded packet, feed it straight to the decoder */\n\n if (got_output) {\n\n result = avcodec_decode_audio4(dec_ctx, out_frame, &got_output, &enc_pkt);\n\n if (result < 0) {\n\n av_log(NULL, AV_LOG_ERROR, \"Error decoding audio packet\\n\");\n\n return result;\n\n }\n\n\n\n if (got_output) {\n\n if (result != enc_pkt.size) {\n\n av_log(NULL, AV_LOG_INFO, \"Decoder consumed only part of a packet, it is allowed to do so -- need to update this test\\n\");\n\n return AVERROR_UNKNOWN;\n\n }\n\n\n\n if (in_frame->nb_samples != out_frame->nb_samples) {\n\n av_log(NULL, AV_LOG_ERROR, \"Error frames before and after decoding has different number of samples\\n\");\n\n return AVERROR_UNKNOWN;\n\n }\n\n\n\n if (in_frame->channel_layout != out_frame->channel_layout) {\n\n av_log(NULL, AV_LOG_ERROR, \"Error frames before and after decoding has different channel layout\\n\");\n\n return AVERROR_UNKNOWN;\n\n }\n\n\n\n if (in_frame->format != out_frame->format) {\n\n av_log(NULL, AV_LOG_ERROR, \"Error frames before and after decoding has different sample format\\n\");\n\n return AVERROR_UNKNOWN;\n\n }\n\n memcpy(raw_out + out_offset, out_frame->data[0], out_frame->linesize[0]);\n\n out_offset += out_frame->linesize[0];\n\n }\n\n }\n\n av_free_packet(&enc_pkt);\n\n }\n\n\n\n if (memcmp(raw_in, raw_out, frame_data_size * NUMBER_OF_FRAMES) != 0) {\n\n av_log(NULL, AV_LOG_ERROR, \"Output differs\\n\");\n\n return 1;\n\n }\n\n\n\n av_log(NULL, AV_LOG_INFO, \"OK\\n\");\n\n\n\n av_freep(&raw_in);\n\n av_freep(&raw_out);\n\n av_frame_free(&in_frame);\n\n av_frame_free(&out_frame);\n\n return 0;\n\n}\n", + "output": "1", + "index": 6490 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,\n\n AVStream *st, RMStream *ast, int len, AVPacket *pkt,\n\n int *seq, int flags, int64_t timestamp)\n\n{\n\n RMDemuxContext *rm = s->priv_data;\n\n int ret;\n\n\n\n if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n\n rm->current_stream= st->id;\n\n ret = rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, ×tamp);\n\n if(ret)\n\n return ret < 0 ? ret : -1; //got partial frame or error\n\n } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {\n\n if ((ast->deint_id == DEINT_ID_GENR) ||\n\n (ast->deint_id == DEINT_ID_INT4) ||\n\n (ast->deint_id == DEINT_ID_SIPR)) {\n\n int x;\n\n int sps = ast->sub_packet_size;\n\n int cfs = ast->coded_framesize;\n\n int h = ast->sub_packet_h;\n\n int y = ast->sub_packet_cnt;\n\n int w = ast->audio_framesize;\n\n\n\n if (flags & 2)\n\n y = ast->sub_packet_cnt = 0;\n\n if (!y)\n\n ast->audiotimestamp = timestamp;\n\n\n\n switch (ast->deint_id) {\n\n case DEINT_ID_INT4:\n\n for (x = 0; x < h/2; x++)\n\n readfull(s, pb, ast->pkt.data+x*2*w+y*cfs, cfs);\n\n break;\n\n case DEINT_ID_GENR:\n\n for (x = 0; x < w/sps; x++)\n\n readfull(s, pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);\n\n break;\n\n case DEINT_ID_SIPR:\n\n readfull(s, pb, ast->pkt.data + y * w, w);\n\n break;\n\n }\n\n\n\n if (++(ast->sub_packet_cnt) < h)\n\n return -1;\n\n if (ast->deint_id == DEINT_ID_SIPR)\n\n ff_rm_reorder_sipr_data(ast->pkt.data, h, w);\n\n\n\n ast->sub_packet_cnt = 0;\n\n rm->audio_stream_num = st->index;\n\n rm->audio_pkt_cnt = h * w / st->codec->block_align;\n\n } else if ((ast->deint_id == DEINT_ID_VBRF) ||\n\n (ast->deint_id == DEINT_ID_VBRS)) {\n\n int x;\n\n rm->audio_stream_num = st->index;\n\n ast->sub_packet_cnt = (avio_rb16(pb) & 0xf0) >> 4;\n\n if (ast->sub_packet_cnt) {\n\n for (x = 0; x < ast->sub_packet_cnt; x++)\n\n ast->sub_packet_lengths[x] = avio_rb16(pb);\n\n rm->audio_pkt_cnt = ast->sub_packet_cnt;\n\n ast->audiotimestamp = timestamp;\n\n } else\n\n return -1;\n\n } else {\n\n av_get_packet(pb, pkt, len);\n\n rm_ac3_swap_bytes(st, pkt);\n\n }\n\n } else\n\n av_get_packet(pb, pkt, len);\n\n\n\n pkt->stream_index = st->index;\n\n\n\n#if 0\n\n if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n\n if(st->codec->codec_id == AV_CODEC_ID_RV20){\n\n int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1);\n\n av_log(s, AV_LOG_DEBUG, \"%d %\"PRId64\" %d\\n\", *timestamp, *timestamp*512LL/25, seq);\n\n\n\n seq |= (timestamp&~0x3FFF);\n\n if(seq - timestamp > 0x2000) seq -= 0x4000;\n\n if(seq - timestamp < -0x2000) seq += 0x4000;\n\n }\n\n }\n\n#endif\n\n\n\n pkt->pts = timestamp;\n\n if (flags & 2)\n\n pkt->flags |= AV_PKT_FLAG_KEY;\n\n\n\n return st->codec->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0;\n\n}\n", + "output": "0", + "index": 18803 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int xen_add_to_physmap(XenIOState *state,\n\n hwaddr start_addr,\n\n ram_addr_t size,\n\n MemoryRegion *mr,\n\n hwaddr offset_within_region)\n\n{\n\n unsigned long i = 0;\n\n int rc = 0;\n\n XenPhysmap *physmap = NULL;\n\n hwaddr pfn, start_gpfn;\n\n hwaddr phys_offset = memory_region_get_ram_addr(mr);\n\n char path[80], value[17];\n\n const char *mr_name;\n\n\n\n if (get_physmapping(state, start_addr, size)) {\n\n return 0;\n\n }\n\n if (size <= 0) {\n\n return -1;\n\n }\n\n\n\n /* Xen can only handle a single dirty log region for now and we want\n\n * the linear framebuffer to be that region.\n\n * Avoid tracking any regions that is not videoram and avoid tracking\n\n * the legacy vga region. */\n\n if (mr == framebuffer && start_addr > 0xbffff) {\n\n goto go_physmap;\n\n }\n\n return -1;\n\n\n\ngo_physmap:\n\n DPRINTF(\"mapping vram to %\"HWADDR_PRIx\" - %\"HWADDR_PRIx\"\\n\",\n\n start_addr, start_addr + size);\n\n\n\n pfn = phys_offset >> TARGET_PAGE_BITS;\n\n start_gpfn = start_addr >> TARGET_PAGE_BITS;\n\n for (i = 0; i < size >> TARGET_PAGE_BITS; i++) {\n\n unsigned long idx = pfn + i;\n\n xen_pfn_t gpfn = start_gpfn + i;\n\n\n\n rc = xc_domain_add_to_physmap(xen_xc, xen_domid, XENMAPSPACE_gmfn, idx, gpfn);\n\n if (rc) {\n\n DPRINTF(\"add_to_physmap MFN %\"PRI_xen_pfn\" to PFN %\"\n\n PRI_xen_pfn\" failed: %d (errno: %d)\\n\", idx, gpfn, rc, errno);\n\n return -rc;\n\n }\n\n }\n\n\n\n mr_name = memory_region_name(mr);\n\n\n\n physmap = g_malloc(sizeof (XenPhysmap));\n\n\n\n physmap->start_addr = start_addr;\n\n physmap->size = size;\n\n physmap->name = mr_name;\n\n physmap->phys_offset = phys_offset;\n\n\n\n QLIST_INSERT_HEAD(&state->physmap, physmap, list);\n\n\n\n xc_domain_pin_memory_cacheattr(xen_xc, xen_domid,\n\n start_addr >> TARGET_PAGE_BITS,\n\n (start_addr + size - 1) >> TARGET_PAGE_BITS,\n\n XEN_DOMCTL_MEM_CACHEATTR_WB);\n\n\n\n snprintf(path, sizeof(path),\n\n \"/local/domain/0/device-model/%d/physmap/%\"PRIx64\"/start_addr\",\n\n xen_domid, (uint64_t)phys_offset);\n\n snprintf(value, sizeof(value), \"%\"PRIx64, (uint64_t)start_addr);\n\n if (!xs_write(state->xenstore, 0, path, value, strlen(value))) {\n\n return -1;\n\n }\n\n snprintf(path, sizeof(path),\n\n \"/local/domain/0/device-model/%d/physmap/%\"PRIx64\"/size\",\n\n xen_domid, (uint64_t)phys_offset);\n\n snprintf(value, sizeof(value), \"%\"PRIx64, (uint64_t)size);\n\n if (!xs_write(state->xenstore, 0, path, value, strlen(value))) {\n\n return -1;\n\n }\n\n if (mr_name) {\n\n snprintf(path, sizeof(path),\n\n \"/local/domain/0/device-model/%d/physmap/%\"PRIx64\"/name\",\n\n xen_domid, (uint64_t)phys_offset);\n\n if (!xs_write(state->xenstore, 0, path, mr_name, strlen(mr_name))) {\n\n return -1;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 4888 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int cng_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame_ptr, AVPacket *avpkt)\n{\n AVFrame *frame = data;\n CNGContext *p = avctx->priv_data;\n int buf_size = avpkt->size;\n int ret, i;\n int16_t *buf_out;\n float e = 1.0;\n float scaling;\n if (avpkt->size) {\n int dbov = -avpkt->data[0];\n p->target_energy = 1081109975 * ff_exp10(dbov / 10.0) * 0.75;\n memset(p->target_refl_coef, 0, p->order * sizeof(*p->target_refl_coef));\n for (i = 0; i < FFMIN(avpkt->size - 1, p->order); i++) {\n p->target_refl_coef[i] = (avpkt->data[1 + i] - 127) / 128.0;\n if (p->inited) {\n p->energy = p->energy / 2 + p->target_energy / 2;\n for (i = 0; i < p->order; i++)\n p->refl_coef[i] = 0.6 *p->refl_coef[i] + 0.4 * p->target_refl_coef[i];\n } else {\n p->energy = p->target_energy;\n memcpy(p->refl_coef, p->target_refl_coef, p->order * sizeof(*p->refl_coef));\n p->inited = 1;\n make_lpc_coefs(p->lpc_coef, p->refl_coef, p->order);\n for (i = 0; i < p->order; i++)\n e *= 1.0 - p->refl_coef[i]*p->refl_coef[i];\n scaling = sqrt(e * p->energy / 1081109975);\n for (i = 0; i < avctx->frame_size; i++) {\n int r = (av_lfg_get(&p->lfg) & 0xffff) - 0x8000;\n p->excitation[i] = scaling * r;\n ff_celp_lp_synthesis_filterf(p->filter_out + p->order, p->lpc_coef,\n p->excitation, avctx->frame_size, p->order);\n frame->nb_samples = avctx->frame_size;\n if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)\n return ret;\n buf_out = (int16_t *)frame->data[0];\n for (i = 0; i < avctx->frame_size; i++)\n buf_out[i] = p->filter_out[i + p->order];\n memcpy(p->filter_out, p->filter_out + avctx->frame_size,\n p->order * sizeof(*p->filter_out));\n *got_frame_ptr = 1;\n return buf_size;", + "output": "1", + "index": 1480 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int poll_rest(gboolean poll_msgs, HANDLE *handles, gint nhandles,\n\n GPollFD *fds, guint nfds, gint timeout)\n\n{\n\n DWORD ready;\n\n GPollFD *f;\n\n int recursed_result;\n\n\n\n if (poll_msgs) {\n\n /* Wait for either messages or handles\n\n * -> Use MsgWaitForMultipleObjectsEx\n\n */\n\n ready = MsgWaitForMultipleObjectsEx(nhandles, handles, timeout,\n\n QS_ALLINPUT, MWMO_ALERTABLE);\n\n\n\n if (ready == WAIT_FAILED) {\n\n gchar *emsg = g_win32_error_message(GetLastError());\n\n g_warning(\"MsgWaitForMultipleObjectsEx failed: %s\", emsg);\n\n g_free(emsg);\n\n }\n\n } else if (nhandles == 0) {\n\n /* No handles to wait for, just the timeout */\n\n if (timeout == INFINITE) {\n\n ready = WAIT_FAILED;\n\n } else {\n\n SleepEx(timeout, TRUE);\n\n ready = WAIT_TIMEOUT;\n\n }\n\n } else {\n\n /* Wait for just handles\n\n * -> Use WaitForMultipleObjectsEx\n\n */\n\n ready =\n\n WaitForMultipleObjectsEx(nhandles, handles, FALSE, timeout, TRUE);\n\n if (ready == WAIT_FAILED) {\n\n gchar *emsg = g_win32_error_message(GetLastError());\n\n g_warning(\"WaitForMultipleObjectsEx failed: %s\", emsg);\n\n g_free(emsg);\n\n }\n\n }\n\n\n\n if (ready == WAIT_FAILED) {\n\n return -1;\n\n } else if (ready == WAIT_TIMEOUT || ready == WAIT_IO_COMPLETION) {\n\n return 0;\n\n } else if (poll_msgs && ready == WAIT_OBJECT_0 + nhandles) {\n\n for (f = fds; f < &fds[nfds]; ++f) {\n\n if (f->fd == G_WIN32_MSG_HANDLE && f->events & G_IO_IN) {\n\n f->revents |= G_IO_IN;\n\n }\n\n }\n\n\n\n /* If we have a timeout, or no handles to poll, be satisfied\n\n * with just noticing we have messages waiting.\n\n */\n\n if (timeout != 0 || nhandles == 0) {\n\n return 1;\n\n }\n\n\n\n /* If no timeout and handles to poll, recurse to poll them,\n\n * too.\n\n */\n\n recursed_result = poll_rest(FALSE, handles, nhandles, fds, nfds, 0);\n\n return (recursed_result == -1) ? -1 : 1 + recursed_result;\n\n } else if (/* QEMU: removed the following unneeded statement which causes\n\n * a compiler warning: ready >= WAIT_OBJECT_0 && */\n\n ready < WAIT_OBJECT_0 + nhandles) {\n\n for (f = fds; f < &fds[nfds]; ++f) {\n\n if ((HANDLE) f->fd == handles[ready - WAIT_OBJECT_0]) {\n\n f->revents = f->events;\n\n }\n\n }\n\n\n\n /* If no timeout and polling several handles, recurse to poll\n\n * the rest of them.\n\n */\n\n if (timeout == 0 && nhandles > 1) {\n\n /* Remove the handle that fired */\n\n int i;\n\n if (ready < nhandles - 1) {\n\n for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++) {\n\n handles[i-1] = handles[i];\n\n }\n\n }\n\n nhandles--;\n\n recursed_result = poll_rest(FALSE, handles, nhandles, fds, nfds, 0);\n\n return (recursed_result == -1) ? -1 : 1 + recursed_result;\n\n }\n\n return 1;\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 27175 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void decode_block_intra(MadContext * t, DCTELEM * block)\n\n{\n\n MpegEncContext *s = &t->s;\n\n int level, i, j, run;\n\n RLTable *rl = &ff_rl_mpeg1;\n\n const uint8_t *scantable = s->intra_scantable.permutated;\n\n int16_t *quant_matrix = s->intra_matrix;\n\n\n\n block[0] = (128 + get_sbits(&s->gb, 8)) * quant_matrix[0];\n\n\n\n /* The RL decoder is derived from mpeg1_decode_block_intra;\n\n Escaped level and run values a decoded differently */\n\n i = 0;\n\n {\n\n OPEN_READER(re, &s->gb);\n\n /* now quantify & encode AC coefficients */\n\n for (;;) {\n\n UPDATE_CACHE(re, &s->gb);\n\n GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);\n\n\n\n if (level == 127) {\n\n break;\n\n } else if (level != 0) {\n\n i += run;\n\n j = scantable[i];\n\n level = (level*quant_matrix[j]) >> 4;\n\n level = (level-1)|1;\n\n level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);\n\n LAST_SKIP_BITS(re, &s->gb, 1);\n\n } else {\n\n /* escape */\n\n UPDATE_CACHE(re, &s->gb);\n\n level = SHOW_SBITS(re, &s->gb, 10); SKIP_BITS(re, &s->gb, 10);\n\n\n\n UPDATE_CACHE(re, &s->gb);\n\n run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);\n\n\n\n i += run;\n\n j = scantable[i];\n\n if (level < 0) {\n\n level = -level;\n\n level = (level*quant_matrix[j]) >> 4;\n\n level = (level-1)|1;\n\n level = -level;\n\n } else {\n\n level = (level*quant_matrix[j]) >> 4;\n\n level = (level-1)|1;\n\n }\n\n }\n\n if (i > 63) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"ac-tex damaged at %d %d\\n\", s->mb_x, s->mb_y);\n\n return;\n\n }\n\n\n\n block[j] = level;\n\n }\n\n CLOSE_READER(re, &s->gb);\n\n }\n\n}\n", + "output": "0", + "index": 3571 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int encode_frame(AVCodecContext *avctx, unsigned char *buf,\n\n int buf_size, void *data)\n\n{\n\n const AVFrame *pic = data;\n\n int aligned_width = ((avctx->width + 47) / 48) * 48;\n\n int stride = aligned_width * 8 / 3;\n\n int h, w;\n\n const uint16_t *y = (const uint16_t*)pic->data[0];\n\n const uint16_t *u = (const uint16_t*)pic->data[1];\n\n const uint16_t *v = (const uint16_t*)pic->data[2];\n\n uint8_t *p = buf;\n\n uint8_t *pdst = buf;\n\n\n\n if (buf_size < aligned_width * avctx->height * 8 / 3) {\n\n av_log(avctx, AV_LOG_ERROR, \"output buffer too small\\n\");\n\n return -1;\n\n }\n\n\n\n#define CLIP(v) av_clip(v, 4, 1019)\n\n\n\n#define WRITE_PIXELS(a, b, c) \\\n\n do { \\\n\n val = CLIP(*a++); \\\n\n val |= (CLIP(*b++) << 10) | \\\n\n (CLIP(*c++) << 20); \\\n\n bytestream_put_le32(&p, val); \\\n\n } while (0)\n\n\n\n for (h = 0; h < avctx->height; h++) {\n\n uint32_t val;\n\n for (w = 0; w < avctx->width - 5; w += 6) {\n\n WRITE_PIXELS(u, y, v);\n\n WRITE_PIXELS(y, u, y);\n\n WRITE_PIXELS(v, y, u);\n\n WRITE_PIXELS(y, v, y);\n\n }\n\n if (w < avctx->width - 1) {\n\n WRITE_PIXELS(u, y, v);\n\n\n\n val = CLIP(*y++);\n\n if (w == avctx->width - 2)\n\n bytestream_put_le32(&p, val);\n\n }\n\n if (w < avctx->width - 3) {\n\n val |= (CLIP(*u++) << 10) | (CLIP(*y++) << 20);\n\n bytestream_put_le32(&p, val);\n\n\n\n val = CLIP(*v++) | (CLIP(*y++) << 10);\n\n bytestream_put_le32(&p, val);\n\n }\n\n\n\n pdst += stride;\n\n memset(p, 0, pdst - p);\n\n p = pdst;\n\n y += pic->linesize[0] / 2 - avctx->width;\n\n u += pic->linesize[1] / 2 - avctx->width / 2;\n\n v += pic->linesize[2] / 2 - avctx->width / 2;\n\n }\n\n\n\n return p - buf;\n\n}\n", + "output": "1", + "index": 19460 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int vmdk_write(BlockDriverState *bs, int64_t sector_num,\n\n const uint8_t *buf, int nb_sectors,\n\n bool zeroed, bool zero_dry_run)\n\n{\n\n BDRVVmdkState *s = bs->opaque;\n\n VmdkExtent *extent = NULL;\n\n int n, ret;\n\n int64_t index_in_cluster;\n\n uint64_t extent_begin_sector, extent_relative_sector_num;\n\n uint64_t cluster_offset;\n\n VmdkMetaData m_data;\n\n\n\n if (sector_num > bs->total_sectors) {\n\n error_report(\"Wrong offset: sector_num=0x%\" PRIx64\n\n \" total_sectors=0x%\" PRIx64 \"\\n\",\n\n sector_num, bs->total_sectors);\n\n return -EIO;\n\n }\n\n\n\n while (nb_sectors > 0) {\n\n extent = find_extent(s, sector_num, extent);\n\n if (!extent) {\n\n return -EIO;\n\n }\n\n ret = get_cluster_offset(\n\n bs,\n\n extent,\n\n &m_data,\n\n sector_num << 9, !extent->compressed,\n\n &cluster_offset);\n\n if (extent->compressed) {\n\n if (ret == VMDK_OK) {\n\n /* Refuse write to allocated cluster for streamOptimized */\n\n error_report(\"Could not write to allocated cluster\"\n\n \" for streamOptimized\");\n\n return -EIO;\n\n } else {\n\n /* allocate */\n\n ret = get_cluster_offset(\n\n bs,\n\n extent,\n\n &m_data,\n\n sector_num << 9, 1,\n\n &cluster_offset);\n\n }\n\n }\n\n if (ret == VMDK_ERROR) {\n\n return -EINVAL;\n\n }\n\n extent_begin_sector = extent->end_sector - extent->sectors;\n\n extent_relative_sector_num = sector_num - extent_begin_sector;\n\n index_in_cluster = extent_relative_sector_num % extent->cluster_sectors;\n\n n = extent->cluster_sectors - index_in_cluster;\n\n if (n > nb_sectors) {\n\n n = nb_sectors;\n\n }\n\n if (zeroed) {\n\n /* Do zeroed write, buf is ignored */\n\n if (extent->has_zero_grain &&\n\n index_in_cluster == 0 &&\n\n n >= extent->cluster_sectors) {\n\n n = extent->cluster_sectors;\n\n if (!zero_dry_run) {\n\n m_data.offset = VMDK_GTE_ZEROED;\n\n /* update L2 tables */\n\n if (vmdk_L2update(extent, &m_data) != VMDK_OK) {\n\n return -EIO;\n\n }\n\n }\n\n } else {\n\n return -ENOTSUP;\n\n }\n\n } else {\n\n ret = vmdk_write_extent(extent,\n\n cluster_offset, index_in_cluster * 512,\n\n buf, n, sector_num);\n\n if (ret) {\n\n return ret;\n\n }\n\n if (m_data.valid) {\n\n /* update L2 tables */\n\n if (vmdk_L2update(extent, &m_data) != VMDK_OK) {\n\n return -EIO;\n\n }\n\n }\n\n }\n\n nb_sectors -= n;\n\n sector_num += n;\n\n buf += n * 512;\n\n\n\n /* update CID on the first write every time the virtual disk is\n\n * opened */\n\n if (!s->cid_updated) {\n\n ret = vmdk_write_cid(bs, time(NULL));\n\n if (ret < 0) {\n\n return ret;\n\n }\n\n s->cid_updated = true;\n\n }\n\n }\n\n return 0;\n\n}\n", + "output": "1", + "index": 9333 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void gen_compute_eflags_c(DisasContext *s, TCGv reg, bool inv)\n\n{\n\n TCGv t0, t1;\n\n int size;\n\n\n\n switch (s->cc_op) {\n\n case CC_OP_SUBB ... CC_OP_SUBQ:\n\n /* (DATA_TYPE)(CC_DST + CC_SRC) < (DATA_TYPE)CC_SRC */\n\n size = s->cc_op - CC_OP_SUBB;\n\n t1 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, false);\n\n /* If no temporary was used, be careful not to alias t1 and t0. */\n\n t0 = TCGV_EQUAL(t1, cpu_cc_src) ? cpu_tmp0 : reg;\n\n tcg_gen_add_tl(t0, cpu_cc_dst, cpu_cc_src);\n\n gen_extu(size, t0);\n\n goto add_sub;\n\n\n\n case CC_OP_ADDB ... CC_OP_ADDQ:\n\n /* (DATA_TYPE)CC_DST < (DATA_TYPE)CC_SRC */\n\n size = s->cc_op - CC_OP_ADDB;\n\n t1 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, false);\n\n t0 = gen_ext_tl(reg, cpu_cc_dst, size, false);\n\n add_sub:\n\n tcg_gen_setcond_tl(inv ? TCG_COND_GEU : TCG_COND_LTU, reg, t0, t1);\n\n inv = false;\n\n break;\n\n\n\n case CC_OP_SBBB ... CC_OP_SBBQ:\n\n /* (DATA_TYPE)(CC_DST + CC_SRC + 1) <= (DATA_TYPE)CC_SRC */\n\n size = s->cc_op - CC_OP_SBBB;\n\n t1 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, false);\n\n if (TCGV_EQUAL(t1, reg) && TCGV_EQUAL(reg, cpu_cc_src)) {\n\n tcg_gen_mov_tl(cpu_tmp0, cpu_cc_src);\n\n t1 = cpu_tmp0;\n\n }\n\n\n\n tcg_gen_add_tl(reg, cpu_cc_dst, cpu_cc_src);\n\n tcg_gen_addi_tl(reg, reg, 1);\n\n gen_extu(size, reg);\n\n t0 = reg;\n\n goto adc_sbb;\n\n\n\n case CC_OP_ADCB ... CC_OP_ADCQ:\n\n /* (DATA_TYPE)CC_DST <= (DATA_TYPE)CC_SRC */\n\n size = s->cc_op - CC_OP_ADCB;\n\n t1 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, false);\n\n t0 = gen_ext_tl(reg, cpu_cc_dst, size, false);\n\n adc_sbb:\n\n tcg_gen_setcond_tl(inv ? TCG_COND_GTU : TCG_COND_LEU, reg, t0, t1);\n\n inv = false;\n\n break;\n\n\n\n case CC_OP_LOGICB ... CC_OP_LOGICQ:\n\n tcg_gen_movi_tl(reg, 0);\n\n break;\n\n\n\n case CC_OP_INCB ... CC_OP_INCQ:\n\n case CC_OP_DECB ... CC_OP_DECQ:\n\n if (inv) {\n\n tcg_gen_xori_tl(reg, cpu_cc_src, 1);\n\n } else {\n\n tcg_gen_mov_tl(reg, cpu_cc_src);\n\n }\n\n inv = false;\n\n break;\n\n\n\n case CC_OP_SHLB ... CC_OP_SHLQ:\n\n /* (CC_SRC >> (DATA_BITS - 1)) & 1 */\n\n size = s->cc_op - CC_OP_SHLB;\n\n tcg_gen_shri_tl(reg, cpu_cc_src, (8 << size) - 1);\n\n tcg_gen_andi_tl(reg, reg, 1);\n\n break;\n\n\n\n case CC_OP_MULB ... CC_OP_MULQ:\n\n tcg_gen_setcondi_tl(inv ? TCG_COND_EQ : TCG_COND_NE,\n\n reg, cpu_cc_src, 0);\n\n inv = false;\n\n break;\n\n\n\n case CC_OP_EFLAGS:\n\n case CC_OP_SARB ... CC_OP_SARQ:\n\n /* CC_SRC & 1 */\n\n tcg_gen_andi_tl(reg, cpu_cc_src, 1);\n\n break;\n\n\n\n default:\n\n /* The need to compute only C from CC_OP_DYNAMIC is important\n\n in efficiently implementing e.g. INC at the start of a TB. */\n\n gen_update_cc_op(s);\n\n gen_helper_cc_compute_c(cpu_tmp2_i32, cpu_env, cpu_cc_op);\n\n tcg_gen_extu_i32_tl(reg, cpu_tmp2_i32);\n\n break;\n\n }\n\n if (inv) {\n\n tcg_gen_xori_tl(reg, reg, 1);\n\n }\n\n}\n", + "output": "0", + "index": 25324 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void vfio_pci_size_rom(VFIOPCIDevice *vdev)\n\n{\n\n uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);\n\n off_t offset = vdev->config_offset + PCI_ROM_ADDRESS;\n\n DeviceState *dev = DEVICE(vdev);\n\n char name[32];\n\n int fd = vdev->vbasedev.fd;\n\n\n\n if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {\n\n /* Since pci handles romfile, just print a message and return */\n\n if (vfio_blacklist_opt_rom(vdev) && vdev->pdev.romfile) {\n\n error_printf(\"Warning : Device at %04x:%02x:%02x.%x \"\n\n \"is known to cause system instability issues during \"\n\n \"option rom execution. \"\n\n \"Proceeding anyway since user specified romfile\\n\",\n\n vdev->host.domain, vdev->host.bus, vdev->host.slot,\n\n vdev->host.function);\n\n }\n\n return;\n\n }\n\n\n\n /*\n\n * Use the same size ROM BAR as the physical device. The contents\n\n * will get filled in later when the guest tries to read it.\n\n */\n\n if (pread(fd, &orig, 4, offset) != 4 ||\n\n pwrite(fd, &size, 4, offset) != 4 ||\n\n pread(fd, &size, 4, offset) != 4 ||\n\n pwrite(fd, &orig, 4, offset) != 4) {\n\n error_report(\"%s(%04x:%02x:%02x.%x) failed: %m\",\n\n __func__, vdev->host.domain, vdev->host.bus,\n\n vdev->host.slot, vdev->host.function);\n\n return;\n\n }\n\n\n\n size = ~(le32_to_cpu(size) & PCI_ROM_ADDRESS_MASK) + 1;\n\n\n\n if (!size) {\n\n return;\n\n }\n\n\n\n if (vfio_blacklist_opt_rom(vdev)) {\n\n if (dev->opts && qemu_opt_get(dev->opts, \"rombar\")) {\n\n error_printf(\"Warning : Device at %04x:%02x:%02x.%x \"\n\n \"is known to cause system instability issues during \"\n\n \"option rom execution. \"\n\n \"Proceeding anyway since user specified non zero value for \"\n\n \"rombar\\n\",\n\n vdev->host.domain, vdev->host.bus, vdev->host.slot,\n\n vdev->host.function);\n\n } else {\n\n error_printf(\"Warning : Rom loading for device at \"\n\n \"%04x:%02x:%02x.%x has been disabled due to \"\n\n \"system instability issues. \"\n\n \"Specify rombar=1 or romfile to force\\n\",\n\n vdev->host.domain, vdev->host.bus, vdev->host.slot,\n\n vdev->host.function);\n\n return;\n\n }\n\n }\n\n\n\n trace_vfio_pci_size_rom(vdev->vbasedev.name, size);\n\n\n\n snprintf(name, sizeof(name), \"vfio[%04x:%02x:%02x.%x].rom\",\n\n vdev->host.domain, vdev->host.bus, vdev->host.slot,\n\n vdev->host.function);\n\n\n\n memory_region_init_io(&vdev->pdev.rom, OBJECT(vdev),\n\n &vfio_rom_ops, vdev, name, size);\n\n\n\n pci_register_bar(&vdev->pdev, PCI_ROM_SLOT,\n\n PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom);\n\n\n\n vdev->pdev.has_rom = true;\n\n vdev->rom_read_failed = false;\n\n}\n", + "output": "0", + "index": 22998 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_jpegls_decode_lse(MJpegDecodeContext *s)\n\n{\n\n int id;\n\n int tid, wt, maxtab, i, j;\n\n\n\n int len = get_bits(&s->gb, 16); /* length: FIXME: verify field validity */\n\n id = get_bits(&s->gb, 8);\n\n\n\n switch (id) {\n\n case 1:\n\n s->maxval = get_bits(&s->gb, 16);\n\n s->t1 = get_bits(&s->gb, 16);\n\n s->t2 = get_bits(&s->gb, 16);\n\n s->t3 = get_bits(&s->gb, 16);\n\n s->reset = get_bits(&s->gb, 16);\n\n\n\n// ff_jpegls_reset_coding_parameters(s, 0);\n\n //FIXME quant table?\n\n break;\n\n case 2:\n\n s->palette_index = 0;\n\n case 3:\n\n tid= get_bits(&s->gb, 8);\n\n wt = get_bits(&s->gb, 8);\n\n\n\n if (len < 5)\n\n return AVERROR_INVALIDDATA;\n\n\n\n if (wt < 1 || wt > MAX_COMPONENTS) {\n\n avpriv_request_sample(s->avctx, \"wt %d\", wt);\n\n return AVERROR_PATCHWELCOME;\n\n }\n\n\n\n if (!s->maxval)\n\n maxtab = 255;\n\n else if ((5 + wt*(s->maxval+1)) < 65535)\n\n maxtab = s->maxval;\n\n else\n\n maxtab = 65530/wt - 1;\n\n\n\n if(s->avctx->debug & FF_DEBUG_PICT_INFO) {\n\n av_log(s->avctx, AV_LOG_DEBUG, \"LSE palette %d tid:%d wt:%d maxtab:%d\\n\", id, tid, wt, maxtab);\n\n }\n\n if (maxtab >= 256) {\n\n avpriv_request_sample(s->avctx, \">8bit palette\");\n\n return AVERROR_PATCHWELCOME;\n\n }\n\n maxtab = FFMIN(maxtab, (len - 5) / wt + s->palette_index);\n\n\n\n if (s->palette_index > maxtab)\n\n return AVERROR_INVALIDDATA;\n\n\n\n if ((s->avctx->pix_fmt == AV_PIX_FMT_GRAY8 || s->avctx->pix_fmt == AV_PIX_FMT_PAL8) &&\n\n (s->picture_ptr->format == AV_PIX_FMT_GRAY8 || s->picture_ptr->format == AV_PIX_FMT_PAL8)) {\n\n uint32_t *pal = s->picture_ptr->data[1];\n\n s->picture_ptr->format =\n\n s->avctx->pix_fmt = AV_PIX_FMT_PAL8;\n\n for (i=s->palette_index; i<=maxtab; i++) {\n\n pal[i] = 0;\n\n for (j=0; jgb, 8) << (8*(wt-j-1));\n\n }\n\n }\n\n s->palette_index = i;\n\n }\n\n break;\n\n case 4:\n\n avpriv_request_sample(s->avctx, \"oversize image\");\n\n return AVERROR(ENOSYS);\n\n default:\n\n av_log(s->avctx, AV_LOG_ERROR, \"invalid id %d\\n\", id);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n av_dlog(s->avctx, \"ID=%i, T=%i,%i,%i\\n\", id, s->t1, s->t2, s->t3);\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 25447 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)\n\n{\n\n AVFilterContext *ctx = inlink->dst;\n\n ASyncContext *s = ctx->priv;\n\n AVFilterLink *outlink = ctx->outputs[0];\n\n int nb_channels = av_get_channel_layout_nb_channels(buf->audio->channel_layout);\n\n int64_t pts = (buf->pts == AV_NOPTS_VALUE) ? buf->pts :\n\n av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);\n\n int out_size, ret;\n\n int64_t delta;\n\n\n\n /* buffer data until we get the first timestamp */\n\n if (s->pts == AV_NOPTS_VALUE) {\n\n if (pts != AV_NOPTS_VALUE) {\n\n s->pts = pts - get_delay(s);\n\n }\n\n return write_to_fifo(s, buf);\n\n }\n\n\n\n /* now wait for the next timestamp */\n\n if (pts == AV_NOPTS_VALUE) {\n\n return write_to_fifo(s, buf);\n\n }\n\n\n\n /* when we have two timestamps, compute how many samples would we have\n\n * to add/remove to get proper sync between data and timestamps */\n\n delta = pts - s->pts - get_delay(s);\n\n out_size = avresample_available(s->avr);\n\n\n\n if (labs(delta) > s->min_delta) {\n\n av_log(ctx, AV_LOG_VERBOSE, \"Discontinuity - %\"PRId64\" samples.\\n\", delta);\n\n out_size += delta;\n\n } else {\n\n if (s->resample) {\n\n int comp = av_clip(delta, -s->max_comp, s->max_comp);\n\n av_log(ctx, AV_LOG_VERBOSE, \"Compensating %d samples per second.\\n\", comp);\n\n avresample_set_compensation(s->avr, delta, inlink->sample_rate);\n\n }\n\n delta = 0;\n\n }\n\n\n\n if (out_size > 0) {\n\n AVFilterBufferRef *buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE,\n\n out_size);\n\n if (!buf_out) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n\n\n avresample_read(s->avr, (void**)buf_out->extended_data, out_size);\n\n buf_out->pts = s->pts;\n\n\n\n if (delta > 0) {\n\n av_samples_set_silence(buf_out->extended_data, out_size - delta,\n\n delta, nb_channels, buf->format);\n\n }\n\n ret = ff_filter_samples(outlink, buf_out);\n\n if (ret < 0)\n\n goto fail;\n\n s->got_output = 1;\n\n } else {\n\n av_log(ctx, AV_LOG_WARNING, \"Non-monotonous timestamps, dropping \"\n\n \"whole buffer.\\n\");\n\n }\n\n\n\n /* drain any remaining buffered data */\n\n avresample_read(s->avr, NULL, avresample_available(s->avr));\n\n\n\n s->pts = pts - avresample_get_delay(s->avr);\n\n ret = avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,\n\n buf->linesize[0], buf->audio->nb_samples);\n\n\n\nfail:\n\n avfilter_unref_buffer(buf);\n\n\n\n return ret;\n\n}\n", + "output": "1", + "index": 4248 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int vdi_open(BlockDriverState *bs, int flags)\n\n{\n\n BDRVVdiState *s = bs->opaque;\n\n VdiHeader header;\n\n size_t bmap_size;\n\n int ret;\n\n\n\n logout(\"\\n\");\n\n\n\n ret = bdrv_read(bs->file, 0, (uint8_t *)&header, 1);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n vdi_header_to_cpu(&header);\n\n#if defined(CONFIG_VDI_DEBUG)\n\n vdi_header_print(&header);\n\n#endif\n\n\n\n if (header.disk_size % SECTOR_SIZE != 0) {\n\n /* 'VBoxManage convertfromraw' can create images with odd disk sizes.\n\n We accept them but round the disk size to the next multiple of\n\n SECTOR_SIZE. */\n\n logout(\"odd disk size %\" PRIu64 \" B, round up\\n\", header.disk_size);\n\n header.disk_size += SECTOR_SIZE - 1;\n\n header.disk_size &= ~(SECTOR_SIZE - 1);\n\n }\n\n\n\n if (header.version != VDI_VERSION_1_1) {\n\n logout(\"unsupported version %u.%u\\n\",\n\n header.version >> 16, header.version & 0xffff);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (header.offset_bmap % SECTOR_SIZE != 0) {\n\n /* We only support block maps which start on a sector boundary. */\n\n logout(\"unsupported block map offset 0x%x B\\n\", header.offset_bmap);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (header.offset_data % SECTOR_SIZE != 0) {\n\n /* We only support data blocks which start on a sector boundary. */\n\n logout(\"unsupported data offset 0x%x B\\n\", header.offset_data);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (header.sector_size != SECTOR_SIZE) {\n\n logout(\"unsupported sector size %u B\\n\", header.sector_size);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (header.block_size != 1 * MiB) {\n\n logout(\"unsupported block size %u B\\n\", header.block_size);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (header.disk_size >\n\n (uint64_t)header.blocks_in_image * header.block_size) {\n\n logout(\"unsupported disk size %\" PRIu64 \" B\\n\", header.disk_size);\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (!uuid_is_null(header.uuid_link)) {\n\n logout(\"link uuid != 0, unsupported\\n\");\n\n ret = -ENOTSUP;\n\n goto fail;\n\n } else if (!uuid_is_null(header.uuid_parent)) {\n\n logout(\"parent uuid != 0, unsupported\\n\");\n\n ret = -ENOTSUP;\n\n goto fail;\n\n }\n\n\n\n bs->total_sectors = header.disk_size / SECTOR_SIZE;\n\n\n\n s->block_size = header.block_size;\n\n s->block_sectors = header.block_size / SECTOR_SIZE;\n\n s->bmap_sector = header.offset_bmap / SECTOR_SIZE;\n\n s->header = header;\n\n\n\n bmap_size = header.blocks_in_image * sizeof(uint32_t);\n\n bmap_size = (bmap_size + SECTOR_SIZE - 1) / SECTOR_SIZE;\n\n if (bmap_size > 0) {\n\n s->bmap = g_malloc(bmap_size * SECTOR_SIZE);\n\n }\n\n ret = bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size);\n\n if (ret < 0) {\n\n goto fail_free_bmap;\n\n }\n\n\n\n /* Disable migration when vdi images are used */\n\n error_set(&s->migration_blocker,\n\n QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,\n\n \"vdi\", bs->device_name, \"live migration\");\n\n migrate_add_blocker(s->migration_blocker);\n\n\n\n return 0;\n\n\n\n fail_free_bmap:\n\n g_free(s->bmap);\n\n\n\n fail:\n\n return ret;\n\n}\n", + "output": "0", + "index": 26708 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,\n\n int log2_cb_size, int cb_depth)\n\n{\n\n HEVCLocalContext *lc = s->HEVClc;\n\n const int cb_size = 1 << log2_cb_size;\n\n int ret;\n\n\n\n lc->ct.depth = cb_depth;\n\n if (x0 + cb_size <= s->sps->width &&\n\n y0 + cb_size <= s->sps->height &&\n\n log2_cb_size > s->sps->log2_min_cb_size) {\n\n SAMPLE(s->split_cu_flag, x0, y0) =\n\n ff_hevc_split_coding_unit_flag_decode(s, cb_depth, x0, y0);\n\n } else {\n\n SAMPLE(s->split_cu_flag, x0, y0) =\n\n (log2_cb_size > s->sps->log2_min_cb_size);\n\n }\n\n if (s->pps->cu_qp_delta_enabled_flag &&\n\n log2_cb_size >= s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth) {\n\n lc->tu.is_cu_qp_delta_coded = 0;\n\n lc->tu.cu_qp_delta = 0;\n\n }\n\n\n\n if (SAMPLE(s->split_cu_flag, x0, y0)) {\n\n const int cb_size_split = cb_size >> 1;\n\n const int x1 = x0 + cb_size_split;\n\n const int y1 = y0 + cb_size_split;\n\n\n\n int more_data = 0;\n\n\n\n more_data = hls_coding_quadtree(s, x0, y0, log2_cb_size - 1, cb_depth + 1);\n\n if (more_data < 0)\n\n return more_data;\n\n\n\n if (more_data && x1 < s->sps->width)\n\n more_data = hls_coding_quadtree(s, x1, y0, log2_cb_size - 1, cb_depth + 1);\n\n if (more_data && y1 < s->sps->height)\n\n more_data = hls_coding_quadtree(s, x0, y1, log2_cb_size - 1, cb_depth + 1);\n\n if (more_data && x1 < s->sps->width &&\n\n y1 < s->sps->height) {\n\n return hls_coding_quadtree(s, x1, y1, log2_cb_size - 1, cb_depth + 1);\n\n }\n\n if (more_data)\n\n return ((x1 + cb_size_split) < s->sps->width ||\n\n (y1 + cb_size_split) < s->sps->height);\n\n else\n\n return 0;\n\n } else {\n\n ret = hls_coding_unit(s, x0, y0, log2_cb_size);\n\n if (ret < 0)\n\n return ret;\n\n if ((!((x0 + cb_size) %\n\n (1 << (s->sps->log2_ctb_size))) ||\n\n (x0 + cb_size >= s->sps->width)) &&\n\n (!((y0 + cb_size) %\n\n (1 << (s->sps->log2_ctb_size))) ||\n\n (y0 + cb_size >= s->sps->height))) {\n\n int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(s);\n\n return !end_of_slice_flag;\n\n } else {\n\n return 1;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 8342 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int qsv_transcode_init(OutputStream *ost)\n\n{\n\n InputStream *ist;\n\n const enum AVPixelFormat *pix_fmt;\n\n\n\n AVDictionaryEntry *e;\n\n const AVOption *opt;\n\n int flags = 0;\n\n\n\n int err, i;\n\n\n\n QSVContext *qsv = NULL;\n\n AVQSVContext *hwctx = NULL;\n\n mfxIMPL impl;\n\n mfxVersion ver = { { 3, 1 } };\n\n\n\n /* check if the encoder supports QSV */\n\n if (!ost->enc->pix_fmts)\n\n return 0;\n\n for (pix_fmt = ost->enc->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++)\n\n if (*pix_fmt == AV_PIX_FMT_QSV)\n\n break;\n\n if (*pix_fmt == AV_PIX_FMT_NONE)\n\n return 0;\n\n\n\n if (strcmp(ost->avfilter, \"null\") || ost->source_index < 0)\n\n return 0;\n\n\n\n /* check if the decoder supports QSV and the output only goes to this stream */\n\n ist = input_streams[ost->source_index];\n\n if (ist->hwaccel_id != HWACCEL_QSV || !ist->dec || !ist->dec->pix_fmts)\n\n return 0;\n\n for (pix_fmt = ist->dec->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++)\n\n if (*pix_fmt == AV_PIX_FMT_QSV)\n\n break;\n\n if (*pix_fmt == AV_PIX_FMT_NONE)\n\n return 0;\n\n\n\n for (i = 0; i < nb_output_streams; i++)\n\n if (output_streams[i] != ost &&\n\n output_streams[i]->source_index == ost->source_index)\n\n return 0;\n\n\n\n av_log(NULL, AV_LOG_VERBOSE, \"Setting up QSV transcoding\\n\");\n\n\n\n qsv = av_mallocz(sizeof(*qsv));\n\n hwctx = av_qsv_alloc_context();\n\n if (!qsv || !hwctx)\n\n goto fail;\n\n\n\n impl = choose_implementation(ist);\n\n\n\n err = MFXInit(impl, &ver, &qsv->session);\n\n if (err != MFX_ERR_NONE) {\n\n av_log(NULL, AV_LOG_ERROR, \"Error initializing an MFX session: %d\\n\", err);\n\n goto fail;\n\n }\n\n\n\n e = av_dict_get(ost->encoder_opts, \"flags\", NULL, 0);\n\n opt = av_opt_find(ost->enc_ctx, \"flags\", NULL, 0, 0);\n\n if (e && opt)\n\n av_opt_eval_flags(ost->enc_ctx, opt, e->value, &flags);\n\n\n\n qsv->ost = ost;\n\n\n\n hwctx->session = qsv->session;\n\n hwctx->iopattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY;\n\n hwctx->opaque_alloc = 1;\n\n hwctx->nb_opaque_surfaces = 16;\n\n\n\n ost->hwaccel_ctx = qsv;\n\n ost->enc_ctx->hwaccel_context = hwctx;\n\n ost->enc_ctx->pix_fmt = AV_PIX_FMT_QSV;\n\n\n\n ist->hwaccel_ctx = qsv;\n\n ist->dec_ctx->pix_fmt = AV_PIX_FMT_QSV;\n\n ist->resample_pix_fmt = AV_PIX_FMT_QSV;\n\n\n\n return 0;\n\n\n\nfail:\n\n av_freep(&hwctx);\n\n av_freep(&qsv);\n\n return AVERROR_UNKNOWN;\n\n}\n", + "output": "0", + "index": 13084 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int vhost_virtqueue_start(struct vhost_dev *dev,\n\n struct VirtIODevice *vdev,\n\n struct vhost_virtqueue *vq,\n\n unsigned idx)\n\n{\n\n hwaddr s, l, a;\n\n int r;\n\n int vhost_vq_index = idx - dev->vq_index;\n\n struct vhost_vring_file file = {\n\n .index = vhost_vq_index\n\n };\n\n struct vhost_vring_state state = {\n\n .index = vhost_vq_index\n\n };\n\n struct VirtQueue *vvq = virtio_get_queue(vdev, idx);\n\n\n\n assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs);\n\n\n\n vq->num = state.num = virtio_queue_get_num(vdev, idx);\n\n r = dev->vhost_ops->vhost_call(dev, VHOST_SET_VRING_NUM, &state);\n\n if (r) {\n\n return -errno;\n\n }\n\n\n\n state.num = virtio_queue_get_last_avail_idx(vdev, idx);\n\n r = dev->vhost_ops->vhost_call(dev, VHOST_SET_VRING_BASE, &state);\n\n if (r) {\n\n return -errno;\n\n }\n\n\n\n if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1) &&\n\n virtio_legacy_is_cross_endian(vdev)) {\n\n r = vhost_virtqueue_set_vring_endian_legacy(dev,\n\n virtio_is_big_endian(vdev),\n\n vhost_vq_index);\n\n if (r) {\n\n return -errno;\n\n }\n\n }\n\n\n\n s = l = virtio_queue_get_desc_size(vdev, idx);\n\n a = virtio_queue_get_desc_addr(vdev, idx);\n\n vq->desc = cpu_physical_memory_map(a, &l, 0);\n\n if (!vq->desc || l != s) {\n\n r = -ENOMEM;\n\n goto fail_alloc_desc;\n\n }\n\n s = l = virtio_queue_get_avail_size(vdev, idx);\n\n a = virtio_queue_get_avail_addr(vdev, idx);\n\n vq->avail = cpu_physical_memory_map(a, &l, 0);\n\n if (!vq->avail || l != s) {\n\n r = -ENOMEM;\n\n goto fail_alloc_avail;\n\n }\n\n vq->used_size = s = l = virtio_queue_get_used_size(vdev, idx);\n\n vq->used_phys = a = virtio_queue_get_used_addr(vdev, idx);\n\n vq->used = cpu_physical_memory_map(a, &l, 1);\n\n if (!vq->used || l != s) {\n\n r = -ENOMEM;\n\n goto fail_alloc_used;\n\n }\n\n\n\n vq->ring_size = s = l = virtio_queue_get_ring_size(vdev, idx);\n\n vq->ring_phys = a = virtio_queue_get_ring_addr(vdev, idx);\n\n vq->ring = cpu_physical_memory_map(a, &l, 1);\n\n if (!vq->ring || l != s) {\n\n r = -ENOMEM;\n\n goto fail_alloc_ring;\n\n }\n\n\n\n r = vhost_virtqueue_set_addr(dev, vq, vhost_vq_index, dev->log_enabled);\n\n if (r < 0) {\n\n r = -errno;\n\n goto fail_alloc;\n\n }\n\n\n\n file.fd = event_notifier_get_fd(virtio_queue_get_host_notifier(vvq));\n\n r = dev->vhost_ops->vhost_call(dev, VHOST_SET_VRING_KICK, &file);\n\n if (r) {\n\n r = -errno;\n\n goto fail_kick;\n\n }\n\n\n\n /* Clear and discard previous events if any. */\n\n event_notifier_test_and_clear(&vq->masked_notifier);\n\n\n\n return 0;\n\n\n\nfail_kick:\n\nfail_alloc:\n\n cpu_physical_memory_unmap(vq->ring, virtio_queue_get_ring_size(vdev, idx),\n\n 0, 0);\n\nfail_alloc_ring:\n\n cpu_physical_memory_unmap(vq->used, virtio_queue_get_used_size(vdev, idx),\n\n 0, 0);\n\nfail_alloc_used:\n\n cpu_physical_memory_unmap(vq->avail, virtio_queue_get_avail_size(vdev, idx),\n\n 0, 0);\n\nfail_alloc_avail:\n\n cpu_physical_memory_unmap(vq->desc, virtio_queue_get_desc_size(vdev, idx),\n\n 0, 0);\n\nfail_alloc_desc:\n\n return r;\n\n}\n", + "output": "0", + "index": 1916 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc,\n\n PutBitContext *pb, float *coeffs, int samples,\n\n int real_ch)\n\n{\n\n int pass, i, j, p, k;\n\n int psize = rc->partition_size;\n\n int partitions = (rc->end - rc->begin) / psize;\n\n int channels = (rc->type == 2) ? 1 : real_ch;\n\n int classes[MAX_CHANNELS][NUM_RESIDUE_PARTITIONS];\n\n int classwords = venc->codebooks[rc->classbook].ndimentions;\n\n\n\n assert(rc->type == 2);\n\n assert(real_ch == 2);\n\n for (p = 0; p < partitions; p++) {\n\n float max1 = 0., max2 = 0.;\n\n int s = rc->begin + p * psize;\n\n for (k = s; k < s + psize; k += 2) {\n\n max1 = FFMAX(max1, fabs(coeffs[ k / real_ch]));\n\n max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch]));\n\n }\n\n\n\n for (i = 0; i < rc->classifications - 1; i++)\n\n if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])\n\n break;\n\n classes[0][p] = i;\n\n }\n\n\n\n for (pass = 0; pass < 8; pass++) {\n\n p = 0;\n\n while (p < partitions) {\n\n if (pass == 0)\n\n for (j = 0; j < channels; j++) {\n\n vorbis_enc_codebook * book = &venc->codebooks[rc->classbook];\n\n int entry = 0;\n\n for (i = 0; i < classwords; i++) {\n\n entry *= rc->classifications;\n\n entry += classes[j][p + i];\n\n }\n\n put_codeword(pb, book, entry);\n\n }\n\n for (i = 0; i < classwords && p < partitions; i++, p++) {\n\n for (j = 0; j < channels; j++) {\n\n int nbook = rc->books[classes[j][p]][pass];\n\n vorbis_enc_codebook * book = &venc->codebooks[nbook];\n\n float *buf = coeffs + samples*j + rc->begin + p*psize;\n\n if (nbook == -1)\n\n continue;\n\n\n\n assert(rc->type == 0 || rc->type == 2);\n\n assert(!(psize % book->ndimentions));\n\n\n\n if (rc->type == 0) {\n\n for (k = 0; k < psize; k += book->ndimentions) {\n\n float *a = put_vector(book, pb, &buf[k]);\n\n int l;\n\n for (l = 0; l < book->ndimentions; l++)\n\n buf[k + l] -= a[l];\n\n }\n\n } else {\n\n int s = rc->begin + p * psize, a1, b1;\n\n a1 = (s % real_ch) * samples;\n\n b1 = s / real_ch;\n\n s = real_ch * samples;\n\n for (k = 0; k < psize; k += book->ndimentions) {\n\n int dim, a2 = a1, b2 = b1;\n\n float vec[MAX_CODEBOOK_DIM], *pv = vec;\n\n for (dim = book->ndimentions; dim--; ) {\n\n *pv++ = coeffs[a2 + b2];\n\n if ((a2 += samples) == s) {\n\n a2 = 0;\n\n b2++;\n\n }\n\n }\n\n pv = put_vector(book, pb, vec);\n\n for (dim = book->ndimentions; dim--; ) {\n\n coeffs[a1 + b1] -= *pv++;\n\n if ((a1 += samples) == s) {\n\n a1 = 0;\n\n b1++;\n\n }\n\n }\n\n }\n\n }\n\n }\n\n }\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 14769 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void render_memory_region(FlatView *view,\n\n MemoryRegion *mr,\n\n Int128 base,\n\n AddrRange clip,\n\n bool readonly)\n\n{\n\n MemoryRegion *subregion;\n\n unsigned i;\n\n hwaddr offset_in_region;\n\n Int128 remain;\n\n Int128 now;\n\n FlatRange fr;\n\n AddrRange tmp;\n\n\n\n if (!mr->enabled) {\n\n return;\n\n }\n\n\n\n int128_addto(&base, int128_make64(mr->addr));\n\n readonly |= mr->readonly;\n\n\n\n tmp = addrrange_make(base, mr->size);\n\n\n\n if (!addrrange_intersects(tmp, clip)) {\n\n return;\n\n }\n\n\n\n clip = addrrange_intersection(tmp, clip);\n\n\n\n if (mr->alias) {\n\n int128_subfrom(&base, int128_make64(mr->alias->addr));\n\n int128_subfrom(&base, int128_make64(mr->alias_offset));\n\n render_memory_region(view, mr->alias, base, clip, readonly);\n\n return;\n\n }\n\n\n\n /* Render subregions in priority order. */\n\n QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {\n\n render_memory_region(view, subregion, base, clip, readonly);\n\n }\n\n\n\n if (!mr->terminates) {\n\n return;\n\n }\n\n\n\n offset_in_region = int128_get64(int128_sub(clip.start, base));\n\n base = clip.start;\n\n remain = clip.size;\n\n\n\n /* Render the region itself into any gaps left by the current view. */\n\n for (i = 0; i < view->nr && int128_nz(remain); ++i) {\n\n if (int128_ge(base, addrrange_end(view->ranges[i].addr))) {\n\n continue;\n\n }\n\n if (int128_lt(base, view->ranges[i].addr.start)) {\n\n now = int128_min(remain,\n\n int128_sub(view->ranges[i].addr.start, base));\n\n fr.mr = mr;\n\n fr.offset_in_region = offset_in_region;\n\n fr.addr = addrrange_make(base, now);\n\n fr.dirty_log_mask = mr->dirty_log_mask;\n\n fr.romd_mode = mr->romd_mode;\n\n fr.readonly = readonly;\n\n flatview_insert(view, i, &fr);\n\n ++i;\n\n int128_addto(&base, now);\n\n offset_in_region += int128_get64(now);\n\n int128_subfrom(&remain, now);\n\n }\n\n now = int128_sub(int128_min(int128_add(base, remain),\n\n addrrange_end(view->ranges[i].addr)),\n\n base);\n\n int128_addto(&base, now);\n\n offset_in_region += int128_get64(now);\n\n int128_subfrom(&remain, now);\n\n }\n\n if (int128_nz(remain)) {\n\n fr.mr = mr;\n\n fr.offset_in_region = offset_in_region;\n\n fr.addr = addrrange_make(base, remain);\n\n fr.dirty_log_mask = mr->dirty_log_mask;\n\n fr.romd_mode = mr->romd_mode;\n\n fr.readonly = readonly;\n\n flatview_insert(view, i, &fr);\n\n }\n\n}\n", + "output": "0", + "index": 22101 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int pci_e1000_init(PCIDevice *pci_dev)\n\n{\n\n E1000State *d = DO_UPCAST(E1000State, dev, pci_dev);\n\n uint8_t *pci_conf;\n\n uint16_t checksum = 0;\n\n int i;\n\n uint8_t *macaddr;\n\n\n\n pci_conf = d->dev.config;\n\n\n\n pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);\n\n pci_config_set_device_id(pci_conf, E1000_DEVID);\n\n *(uint16_t *)(pci_conf+0x04) = cpu_to_le16(0x0407);\n\n *(uint16_t *)(pci_conf+0x06) = cpu_to_le16(0x0010);\n\n pci_conf[0x08] = 0x03;\n\n pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);\n\n pci_conf[0x0c] = 0x10;\n\n\n\n pci_conf[0x3d] = 1; // interrupt pin 0\n\n\n\n d->mmio_index = cpu_register_io_memory(e1000_mmio_read,\n\n e1000_mmio_write, d);\n\n\n\n pci_register_bar((PCIDevice *)d, 0, PNPMMIO_SIZE,\n\n PCI_ADDRESS_SPACE_MEM, e1000_mmio_map);\n\n\n\n pci_register_bar((PCIDevice *)d, 1, IOPORT_SIZE,\n\n PCI_ADDRESS_SPACE_IO, ioport_map);\n\n\n\n memmove(d->eeprom_data, e1000_eeprom_template,\n\n sizeof e1000_eeprom_template);\n\n qemu_macaddr_default_if_unset(&d->conf.macaddr);\n\n macaddr = d->conf.macaddr.a;\n\n for (i = 0; i < 3; i++)\n\n d->eeprom_data[i] = (macaddr[2*i+1]<<8) | macaddr[2*i];\n\n for (i = 0; i < EEPROM_CHECKSUM_REG; i++)\n\n checksum += d->eeprom_data[i];\n\n checksum = (uint16_t) EEPROM_SUM - checksum;\n\n d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;\n\n\n\n d->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,\n\n d->conf.vlan, d->conf.peer,\n\n d->dev.qdev.info->name, d->dev.qdev.id,\n\n e1000_can_receive, e1000_receive, NULL,\n\n NULL, e1000_cleanup, d);\n\n d->vc->link_status_changed = e1000_set_link_status;\n\n\n\n qemu_format_nic_info_str(d->vc, macaddr);\n\n\n\n vmstate_register(-1, &vmstate_e1000, d);\n\n e1000_reset(d);\n\n\n\n#if 0 /* rom bev support is broken -> can't load unconditionally */\n\n if (!pci_dev->qdev.hotplugged) {\n\n static int loaded = 0;\n\n if (!loaded) {\n\n rom_add_option(\"pxe-e1000.bin\");\n\n loaded = 1;\n\n }\n\n }\n\n#endif\n\n return 0;\n\n}\n", + "output": "0", + "index": 14857 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_b_mbs(VC9Context *v)\n\n{\n\n int x, y, current_mb = 0 , last_mb = v->height_mb*v->width_mb,\n\n i /* MB / B postion information */;\n\n int direct_b_bit = 0, skip_mb_bit = 0;\n\n int ac_pred;\n\n int b_mv1 = 0, b_mv2 = 0, b_mv_type = 0;\n\n int mquant, mqdiff; /* MB quant stuff */\n\n int tt_block; /* Block transform type */\n\n \n\n for (y=0; yheight_mb; y++)\n\n {\n\n for (x=0; xwidth_mb; x++)\n\n {\n\n if (v->direct_mb_plane[current_mb])\n\n direct_b_bit = get_bits(&v->gb, 1);\n\n if (1 /* Skip mode is raw */)\n\n {\n\n /* FIXME getting tired commenting */\n\n#if 0\n\n skip_mb_bit = get_bits(&v->gb, n); //vlc\n\n#endif\n\n }\n\n if (!direct_b_bit)\n\n {\n\n if (skip_mb_bit)\n\n {\n\n /* FIXME getting tired commenting */\n\n#if 0\n\n b_mv_type = get_bits(&v->gb, n); //vlc\n\n#endif\n\n }\n\n else\n\n { \n\n /* FIXME getting tired commenting */\n\n#if 0\n\n b_mv1 = get_bits(&v->gb, n); //VLC\n\n#endif\n\n if (1 /* b_mv1 isn't intra */)\n\n {\n\n /* FIXME: actually read it */\n\n b_mv_type = 0; //vlc\n\n }\n\n }\n\n }\n\n if (!skip_mb_bit)\n\n {\n\n if (b_mv1 != last_mb)\n\n {\n\n GET_MQUANT();\n\n if (1 /* intra mb */)\n\n ac_pred = get_bits(&v->gb, 1);\n\n }\n\n else\n\n {\n\n if (1 /* forward_mb is interpolate */)\n\n {\n\n /* FIXME: actually read it */\n\n b_mv2 = 0; //vlc\n\n }\n\n if (1 /* b_mv2 isn't the last */)\n\n {\n\n if (1 /* intra_mb */)\n\n ac_pred = get_bits(&v->gb, 1);\n\n GET_MQUANT();\n\n }\n\n }\n\n }\n\n //End1\n\n /* FIXME getting tired, commenting */\n\n#if 0\n\n if (v->ttmbf)\n\n v->ttmb = get_bits(&v->gb, n); //vlc\n\n#endif\n\n }\n\n //End2\n\n for (i=0; i<6; i++)\n\n {\n\n /* FIXME: process the block */\n\n }\n\n\n\n current_mb++;\n\n }\n\n return 0;\n\n}\n", + "output": "0", + "index": 5481 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void lz_unpack(const unsigned char *src, unsigned char *dest, int dest_len)\n\n{\n\n const unsigned char *s;\n\n unsigned char *d;\n\n unsigned char *d_end;\n\n unsigned char queue[QUEUE_SIZE];\n\n unsigned int qpos;\n\n unsigned int dataleft;\n\n unsigned int chainofs;\n\n unsigned int chainlen;\n\n unsigned int speclen;\n\n unsigned char tag;\n\n unsigned int i, j;\n\n\n\n s = src;\n\n d = dest;\n\n d_end = d + dest_len;\n\n dataleft = AV_RL32(s);\n\n s += 4;\n\n memset(queue, 0x20, QUEUE_SIZE);\n\n if (AV_RL32(s) == 0x56781234) {\n\n s += 4;\n\n qpos = 0x111;\n\n speclen = 0xF + 3;\n\n } else {\n\n qpos = 0xFEE;\n\n speclen = 100; /* no speclen */\n\n }\n\n\n\n while (dataleft > 0) {\n\n tag = *s++;\n\n if ((tag == 0xFF) && (dataleft > 8)) {\n\n if (d + 8 > d_end)\n\n return;\n\n for (i = 0; i < 8; i++) {\n\n queue[qpos++] = *d++ = *s++;\n\n qpos &= QUEUE_MASK;\n\n }\n\n dataleft -= 8;\n\n } else {\n\n for (i = 0; i < 8; i++) {\n\n if (dataleft == 0)\n\n break;\n\n if (tag & 0x01) {\n\n if (d + 1 > d_end)\n\n return;\n\n queue[qpos++] = *d++ = *s++;\n\n qpos &= QUEUE_MASK;\n\n dataleft--;\n\n } else {\n\n chainofs = *s++;\n\n chainofs |= ((*s & 0xF0) << 4);\n\n chainlen = (*s++ & 0x0F) + 3;\n\n if (chainlen == speclen)\n\n chainlen = *s++ + 0xF + 3;\n\n if (d + chainlen > d_end)\n\n return;\n\n for (j = 0; j < chainlen; j++) {\n\n *d = queue[chainofs++ & QUEUE_MASK];\n\n queue[qpos++] = *d++;\n\n qpos &= QUEUE_MASK;\n\n }\n\n dataleft -= chainlen;\n\n }\n\n tag >>= 1;\n\n }\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 11985 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int xen_pt_msgctrl_reg_write(XenPCIPassthroughState *s,\n\n XenPTReg *cfg_entry, uint16_t *val,\n\n uint16_t dev_value, uint16_t valid_mask)\n\n{\n\n XenPTRegInfo *reg = cfg_entry->reg;\n\n XenPTMSI *msi = s->msi;\n\n uint16_t writable_mask = 0;\n\n uint16_t throughable_mask = 0;\n\n uint16_t raw_val;\n\n\n\n /* Currently no support for multi-vector */\n\n if (*val & PCI_MSI_FLAGS_QSIZE) {\n\n XEN_PT_WARN(&s->dev, \"Tries to set more than 1 vector ctrl %x\\n\", *val);\n\n }\n\n\n\n /* modify emulate register */\n\n writable_mask = reg->emu_mask & ~reg->ro_mask & valid_mask;\n\n cfg_entry->data = XEN_PT_MERGE_VALUE(*val, cfg_entry->data, writable_mask);\n\n msi->flags |= cfg_entry->data & ~PCI_MSI_FLAGS_ENABLE;\n\n\n\n /* create value for writing to I/O device register */\n\n raw_val = *val;\n\n throughable_mask = ~reg->emu_mask & valid_mask;\n\n *val = XEN_PT_MERGE_VALUE(*val, dev_value, throughable_mask);\n\n\n\n /* update MSI */\n\n if (raw_val & PCI_MSI_FLAGS_ENABLE) {\n\n /* setup MSI pirq for the first time */\n\n if (!msi->initialized) {\n\n /* Init physical one */\n\n XEN_PT_LOG(&s->dev, \"setup MSI\\n\");\n\n if (xen_pt_msi_setup(s)) {\n\n /* We do not broadcast the error to the framework code, so\n\n * that MSI errors are contained in MSI emulation code and\n\n * QEMU can go on running.\n\n * Guest MSI would be actually not working.\n\n */\n\n *val &= ~PCI_MSI_FLAGS_ENABLE;\n\n XEN_PT_WARN(&s->dev, \"Can not map MSI.\\n\");\n\n return 0;\n\n }\n\n if (xen_pt_msi_update(s)) {\n\n *val &= ~PCI_MSI_FLAGS_ENABLE;\n\n XEN_PT_WARN(&s->dev, \"Can not bind MSI\\n\");\n\n return 0;\n\n }\n\n msi->initialized = true;\n\n msi->mapped = true;\n\n }\n\n msi->flags |= PCI_MSI_FLAGS_ENABLE;\n\n } else {\n\n msi->flags &= ~PCI_MSI_FLAGS_ENABLE;\n\n }\n\n\n\n /* pass through MSI_ENABLE bit */\n\n *val &= ~PCI_MSI_FLAGS_ENABLE;\n\n *val |= raw_val & PCI_MSI_FLAGS_ENABLE;\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 20882 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int alloc_cluster_link_l2(BlockDriverState *bs, uint64_t cluster_offset,\n\n QCowL2Meta *m)\n\n{\n\n BDRVQcowState *s = bs->opaque;\n\n int i, j = 0, l2_index, ret;\n\n uint64_t *old_cluster, start_sect, l2_offset, *l2_table;\n\n\n\n if (m->nb_clusters == 0)\n\n return 0;\n\n\n\n old_cluster = qemu_malloc(m->nb_clusters * sizeof(uint64_t));\n\n\n\n /* copy content of unmodified sectors */\n\n start_sect = (m->offset & ~(s->cluster_size - 1)) >> 9;\n\n if (m->n_start) {\n\n ret = copy_sectors(bs, start_sect, cluster_offset, 0, m->n_start);\n\n if (ret < 0)\n\n goto err;\n\n }\n\n\n\n if (m->nb_available & (s->cluster_sectors - 1)) {\n\n uint64_t end = m->nb_available & ~(uint64_t)(s->cluster_sectors - 1);\n\n ret = copy_sectors(bs, start_sect + end, cluster_offset + (end << 9),\n\n m->nb_available - end, s->cluster_sectors);\n\n if (ret < 0)\n\n goto err;\n\n }\n\n\n\n ret = -EIO;\n\n /* update L2 table */\n\n if (!get_cluster_table(bs, m->offset, &l2_table, &l2_offset, &l2_index))\n\n goto err;\n\n\n\n for (i = 0; i < m->nb_clusters; i++) {\n\n if(l2_table[l2_index + i] != 0)\n\n old_cluster[j++] = l2_table[l2_index + i];\n\n\n\n l2_table[l2_index + i] = cpu_to_be64((cluster_offset +\n\n (i << s->cluster_bits)) | QCOW_OFLAG_COPIED);\n\n }\n\n\n\n if (bdrv_pwrite(s->hd, l2_offset + l2_index * sizeof(uint64_t),\n\n l2_table + l2_index, m->nb_clusters * sizeof(uint64_t)) !=\n\n m->nb_clusters * sizeof(uint64_t))\n\n goto err;\n\n\n\n for (i = 0; i < j; i++)\n\n free_any_clusters(bs, old_cluster[i], 1);\n\n\n\n ret = 0;\n\nerr:\n\n qemu_free(old_cluster);\n\n return ret;\n\n }\n", + "output": "1", + "index": 2575 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "cpu_x86_dump_seg_cache(CPUState *env, FILE *f,\n\n int (*cpu_fprintf)(FILE *f, const char *fmt, ...),\n\n const char *name, struct SegmentCache *sc)\n\n{\n\n#ifdef TARGET_X86_64\n\n if (env->hflags & HF_CS64_MASK) {\n\n cpu_fprintf(f, \"%-3s=%04x %016\" PRIx64 \" %08x %08x\", name,\n\n sc->selector, sc->base, sc->limit, sc->flags);\n\n } else\n\n#endif\n\n {\n\n cpu_fprintf(f, \"%-3s=%04x %08x %08x %08x\", name, sc->selector,\n\n (uint32_t)sc->base, sc->limit, sc->flags);\n\n }\n\n\n\n if (!(env->hflags & HF_PE_MASK) || !(sc->flags & DESC_P_MASK))\n\n goto done;\n\n\n\n cpu_fprintf(f, \" DPL=%d \", (sc->flags & DESC_DPL_MASK) >> DESC_DPL_SHIFT);\n\n if (sc->flags & DESC_S_MASK) {\n\n if (sc->flags & DESC_CS_MASK) {\n\n cpu_fprintf(f, (sc->flags & DESC_L_MASK) ? \"CS64\" :\n\n ((sc->flags & DESC_B_MASK) ? \"CS32\" : \"CS16\"));\n\n cpu_fprintf(f, \" [%c%c\", (sc->flags & DESC_C_MASK) ? 'C' : '-',\n\n (sc->flags & DESC_R_MASK) ? 'R' : '-');\n\n } else {\n\n cpu_fprintf(f, (sc->flags & DESC_B_MASK) ? \"DS \" : \"DS16\");\n\n cpu_fprintf(f, \" [%c%c\", (sc->flags & DESC_E_MASK) ? 'E' : '-',\n\n (sc->flags & DESC_W_MASK) ? 'W' : '-');\n\n }\n\n cpu_fprintf(f, \"%c]\", (sc->flags & DESC_A_MASK) ? 'A' : '-');\n\n } else {\n\n static const char *sys_type_name[2][16] = {\n\n { /* 32 bit mode */\n\n \"Reserved\", \"TSS16-avl\", \"LDT\", \"TSS16-busy\",\n\n \"CallGate16\", \"TaskGate\", \"IntGate16\", \"TrapGate16\",\n\n \"Reserved\", \"TSS32-avl\", \"Reserved\", \"TSS32-busy\",\n\n \"CallGate32\", \"Reserved\", \"IntGate32\", \"TrapGate32\"\n\n },\n\n { /* 64 bit mode */\n\n \"\", \"Reserved\", \"LDT\", \"Reserved\", \"Reserved\",\n\n \"Reserved\", \"Reserved\", \"Reserved\", \"Reserved\",\n\n \"TSS64-avl\", \"Reserved\", \"TSS64-busy\", \"CallGate64\",\n\n \"Reserved\", \"IntGate64\", \"TrapGate64\"\n\n }\n\n };\n\n cpu_fprintf(f, \"%s\",\n\n sys_type_name[(env->hflags & HF_LMA_MASK) ? 1 : 0]\n\n [(sc->flags & DESC_TYPE_MASK)\n\n >> DESC_TYPE_SHIFT]);\n\n }\n\ndone:\n\n cpu_fprintf(f, \"\\n\");\n\n}\n", + "output": "0", + "index": 14877 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_slice_header(FFV1Context *f, FFV1Context *fs)\n\n{\n\n RangeCoder *c = &fs->c;\n\n uint8_t state[CONTEXT_SIZE];\n\n unsigned ps, i, context_count;\n\n memset(state, 128, sizeof(state));\n\n\n\n if (fs->ac > 1) {\n\n for (i = 1; i < 256; i++) {\n\n fs->c.one_state[i] = f->state_transition[i];\n\n fs->c.zero_state[256 - i] = 256 - fs->c.one_state[i];\n\n }\n\n }\n\n\n\n fs->slice_x = get_symbol(c, state, 0) * f->width;\n\n fs->slice_y = get_symbol(c, state, 0) * f->height;\n\n fs->slice_width = (get_symbol(c, state, 0) + 1) * f->width + fs->slice_x;\n\n fs->slice_height = (get_symbol(c, state, 0) + 1) * f->height + fs->slice_y;\n\n\n\n fs->slice_x /= f->num_h_slices;\n\n fs->slice_y /= f->num_v_slices;\n\n fs->slice_width = fs->slice_width / f->num_h_slices - fs->slice_x;\n\n fs->slice_height = fs->slice_height / f->num_v_slices - fs->slice_y;\n\n if ((unsigned)fs->slice_width > f->width ||\n\n (unsigned)fs->slice_height > f->height)\n\n return AVERROR_INVALIDDATA;\n\n if ((unsigned)fs->slice_x + (uint64_t)fs->slice_width > f->width ||\n\n (unsigned)fs->slice_y + (uint64_t)fs->slice_height > f->height)\n\n return AVERROR_INVALIDDATA;\n\n\n\n for (i = 0; i < f->plane_count; i++) {\n\n PlaneContext *const p = &fs->plane[i];\n\n int idx = get_symbol(c, state, 0);\n\n if (idx > (unsigned)f->quant_table_count) {\n\n av_log(f->avctx, AV_LOG_ERROR, \"quant_table_index out of range\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n p->quant_table_index = idx;\n\n memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table));\n\n context_count = f->context_count[idx];\n\n\n\n if (p->context_count < context_count) {\n\n av_freep(&p->state);\n\n av_freep(&p->vlc_state);\n\n }\n\n p->context_count = context_count;\n\n }\n\n\n\n ps = get_symbol(c, state, 0);\n\n if (ps == 1) {\n\n f->cur->interlaced_frame = 1;\n\n f->cur->top_field_first = 1;\n\n } else if (ps == 2) {\n\n f->cur->interlaced_frame = 1;\n\n f->cur->top_field_first = 0;\n\n } else if (ps == 3) {\n\n f->cur->interlaced_frame = 0;\n\n }\n\n f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0);\n\n f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0);\n\n\n\n if (av_image_check_sar(f->width, f->height,\n\n f->cur->sample_aspect_ratio) < 0) {\n\n av_log(f->avctx, AV_LOG_WARNING, \"ignoring invalid SAR: %u/%u\\n\",\n\n f->cur->sample_aspect_ratio.num,\n\n f->cur->sample_aspect_ratio.den);\n\n f->cur->sample_aspect_ratio = (AVRational){ 0, 1 };\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 10738 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int av_probe_input_buffer2(AVIOContext *pb, AVInputFormat **fmt,\n\n const char *filename, void *logctx,\n\n unsigned int offset, unsigned int max_probe_size)\n\n{\n\n AVProbeData pd = { filename ? filename : \"\" };\n\n uint8_t *buf = NULL;\n\n uint8_t *mime_type;\n\n int ret = 0, probe_size, buf_offset = 0;\n\n int score = 0;\n\n\n\n if (!max_probe_size)\n\n max_probe_size = PROBE_BUF_MAX;\n\n else if (max_probe_size < PROBE_BUF_MIN) {\n\n av_log(logctx, AV_LOG_ERROR,\n\n \"Specified probe size value %u cannot be < %u\\n\", max_probe_size, PROBE_BUF_MIN);\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n if (offset >= max_probe_size)\n\n return AVERROR(EINVAL);\n\n\n\n#ifdef FF_API_PROBE_MIME\n\n if (pb->av_class)\n\n av_opt_get(pb, \"mime_type\", AV_OPT_SEARCH_CHILDREN, &pd.mime_type);\n\n#endif\n\n\n\n#if !FF_API_PROBE_MIME\n\n if (!*fmt && pb->av_class && av_opt_get(pb, \"mime_type\", AV_OPT_SEARCH_CHILDREN, &mime_type) >= 0 && mime_type) {\n\n if (!av_strcasecmp(mime_type, \"audio/aacp\")) {\n\n *fmt = av_find_input_format(\"aac\");\n\n }\n\n av_freep(&mime_type);\n\n }\n\n#endif\n\n\n\n for (probe_size = PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt;\n\n probe_size = FFMIN(probe_size << 1,\n\n FFMAX(max_probe_size, probe_size + 1))) {\n\n score = probe_size < max_probe_size ? AVPROBE_SCORE_RETRY : 0;\n\n\n\n /* Read probe data. */\n\n if ((ret = av_reallocp(&buf, probe_size + AVPROBE_PADDING_SIZE)) < 0)\n\n goto fail;\n\n if ((ret = avio_read(pb, buf + buf_offset,\n\n probe_size - buf_offset)) < 0) {\n\n /* Fail if error was not end of file, otherwise, lower score. */\n\n if (ret != AVERROR_EOF)\n\n goto fail;\n\n\n\n score = 0;\n\n ret = 0; /* error was end of file, nothing read */\n\n }\n\n buf_offset += ret;\n\n if (buf_offset < offset)\n\n continue;\n\n pd.buf_size = buf_offset - offset;\n\n pd.buf = &buf[offset];\n\n\n\n memset(pd.buf + pd.buf_size, 0, AVPROBE_PADDING_SIZE);\n\n\n\n /* Guess file format. */\n\n *fmt = av_probe_input_format2(&pd, 1, &score);\n\n if (*fmt) {\n\n /* This can only be true in the last iteration. */\n\n if (score <= AVPROBE_SCORE_RETRY) {\n\n av_log(logctx, AV_LOG_WARNING,\n\n \"Format %s detected only with low score of %d, \"\n\n \"misdetection possible!\\n\", (*fmt)->name, score);\n\n } else\n\n av_log(logctx, AV_LOG_DEBUG,\n\n \"Format %s probed with size=%d and score=%d\\n\",\n\n (*fmt)->name, probe_size, score);\n\n#if 0\n\n FILE *f = fopen(\"probestat.tmp\", \"ab\");\n\n fprintf(f, \"probe_size:%d format:%s score:%d filename:%s\\n\", probe_size, (*fmt)->name, score, filename);\n\n fclose(f);\n\n#endif\n\n }\n\n }\n\n\n\n if (!*fmt)\n\n ret = AVERROR_INVALIDDATA;\n\n\n\nfail:\n\n /* Rewind. Reuse probe buffer to avoid seeking. */\n\n if (ret >= 0)\n\n ret = ffio_rewind_with_probe_data(pb, &buf, buf_offset);\n\n\n\n#ifdef FF_API_PROBE_MIME\n\n av_free(pd.mime_type);\n\n#endif\n\n return ret < 0 ? ret : score;\n\n}\n", + "output": "0", + "index": 12351 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int frame_thread_init(AVCodecContext *avctx)\n\n{\n\n int thread_count = avctx->thread_count;\n\n AVCodec *codec = avctx->codec;\n\n AVCodecContext *src = avctx;\n\n FrameThreadContext *fctx;\n\n int i, err = 0;\n\n\n\n if (thread_count <= 1) {\n\n avctx->active_thread_type = 0;\n\n return 0;\n\n }\n\n\n\n avctx->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext));\n\n\n\n fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count);\n\n pthread_mutex_init(&fctx->buffer_mutex, NULL);\n\n fctx->delaying = 1;\n\n\n\n for (i = 0; i < thread_count; i++) {\n\n AVCodecContext *copy = av_malloc(sizeof(AVCodecContext));\n\n PerThreadContext *p = &fctx->threads[i];\n\n\n\n pthread_mutex_init(&p->mutex, NULL);\n\n pthread_mutex_init(&p->progress_mutex, NULL);\n\n pthread_cond_init(&p->input_cond, NULL);\n\n pthread_cond_init(&p->progress_cond, NULL);\n\n pthread_cond_init(&p->output_cond, NULL);\n\n\n\n p->parent = fctx;\n\n p->avctx = copy;\n\n\n\n if (!copy) {\n\n err = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n\n\n *copy = *src;\n\n copy->thread_opaque = p;\n\n copy->pkt = &p->avpkt;\n\n\n\n if (!i) {\n\n src = copy;\n\n\n\n if (codec->init)\n\n err = codec->init(copy);\n\n\n\n update_context_from_thread(avctx, copy, 1);\n\n } else {\n\n copy->priv_data = av_malloc(codec->priv_data_size);\n\n if (!copy->priv_data) {\n\n err = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n memcpy(copy->priv_data, src->priv_data, codec->priv_data_size);\n\n copy->internal = av_malloc(sizeof(AVCodecInternal));\n\n if (!copy->internal) {\n\n err = AVERROR(ENOMEM);\n\n goto error;\n\n }\n\n *(copy->internal) = *(src->internal);\n\n copy->internal->is_copy = 1;\n\n\n\n if (codec->init_thread_copy)\n\n err = codec->init_thread_copy(copy);\n\n }\n\n\n\n if (err) goto error;\n\n\n\n pthread_create(&p->thread, NULL, frame_worker_thread, p);\n\n }\n\n\n\n return 0;\n\n\n\nerror:\n\n frame_thread_free(avctx, i+1);\n\n\n\n return err;\n\n}\n", + "output": "1", + "index": 22299 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int encode_audio_frame(AVFormatContext *s, OutputStream *ost,\n\n const uint8_t *buf, int buf_size)\n\n{\n\n AVCodecContext *enc = ost->st->codec;\n\n AVFrame *frame = NULL;\n\n AVPacket pkt;\n\n int ret, got_packet;\n\n\n\n av_init_packet(&pkt);\n\n pkt.data = NULL;\n\n pkt.size = 0;\n\n\n\n if (buf && buf_size) {\n\n if (!ost->output_frame) {\n\n ost->output_frame = avcodec_alloc_frame();\n\n if (!ost->output_frame) {\n\n av_log(NULL, AV_LOG_FATAL, \"out-of-memory in encode_audio_frame()\\n\");\n\n exit_program(1);\n\n }\n\n }\n\n frame = ost->output_frame;\n\n if (frame->extended_data != frame->data)\n\n av_freep(&frame->extended_data);\n\n avcodec_get_frame_defaults(frame);\n\n\n\n frame->nb_samples = buf_size /\n\n (enc->channels * av_get_bytes_per_sample(enc->sample_fmt));\n\n if ((ret = avcodec_fill_audio_frame(frame, enc->channels, enc->sample_fmt,\n\n buf, buf_size, 1)) < 0) {\n\n av_log(NULL, AV_LOG_FATAL, \"Audio encoding failed (avcodec_fill_audio_frame)\\n\");\n\n exit_program(1);\n\n }\n\n\n\n frame->pts = ost->sync_opts;\n\n ost->sync_opts += frame->nb_samples;\n\n }\n\n\n\n got_packet = 0;\n\n update_benchmark(NULL);\n\n if (avcodec_encode_audio2(enc, &pkt, frame, &got_packet) < 0) {\n\n av_log(NULL, AV_LOG_FATAL, \"Audio encoding failed (avcodec_encode_audio2)\\n\");\n\n exit_program(1);\n\n }\n\n update_benchmark(\"encode_audio %d.%d\", ost->file_index, ost->index);\n\n\n\n ret = pkt.size;\n\n\n\n if (got_packet) {\n\n if (pkt.pts != AV_NOPTS_VALUE)\n\n pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base);\n\n if (pkt.dts != AV_NOPTS_VALUE) {\n\n int64_t max = ost->st->cur_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT);\n\n pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base);\n\n if (ost->st->cur_dts && ost->st->cur_dts != AV_NOPTS_VALUE && max > pkt.dts) {\n\n av_log(s, max - pkt.dts > 2 ? AV_LOG_WARNING : AV_LOG_DEBUG, \"Audio timestamp %\"PRId64\" < %\"PRId64\" invalid, cliping\\n\", pkt.dts, max);\n\n pkt.pts = pkt.dts = max;\n\n }\n\n }\n\n if (pkt.duration > 0)\n\n pkt.duration = av_rescale_q(pkt.duration, enc->time_base, ost->st->time_base);\n\n\n\n write_frame(s, &pkt, ost);\n\n\n\n audio_size += pkt.size;\n\n\n\n av_free_packet(&pkt);\n\n }\n\n\n\n if (debug_ts) {\n\n av_log(NULL, AV_LOG_INFO, \"encoder -> type:audio \"\n\n \"pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\\n\",\n\n av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ost->st->time_base),\n\n av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ost->st->time_base));\n\n }\n\n\n\n return ret;\n\n}\n", + "output": "1", + "index": 663 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int mov_write_mvhd_tag(AVIOContext *pb, MOVMuxContext *mov)\n\n{\n\n int max_track_id = 1, i;\n\n int64_t max_track_len_temp, max_track_len = 0;\n\n int version;\n\n\n\n for (i = 0; i < mov->nb_streams; i++) {\n\n if (mov->tracks[i].entry > 0) {\n\n max_track_len_temp = av_rescale_rnd(mov->tracks[i].track_duration,\n\n MOV_TIMESCALE,\n\n mov->tracks[i].timescale,\n\n AV_ROUND_UP);\n\n if (max_track_len < max_track_len_temp)\n\n max_track_len = max_track_len_temp;\n\n if (max_track_id < mov->tracks[i].track_id)\n\n max_track_id = mov->tracks[i].track_id;\n\n }\n\n }\n\n\n\n version = max_track_len < UINT32_MAX ? 0 : 1;\n\n (version == 1) ? avio_wb32(pb, 120) : avio_wb32(pb, 108); /* size */\n\n ffio_wfourcc(pb, \"mvhd\");\n\n avio_w8(pb, version);\n\n avio_wb24(pb, 0); /* flags */\n\n if (version == 1) {\n\n avio_wb64(pb, mov->time);\n\n avio_wb64(pb, mov->time);\n\n } else {\n\n avio_wb32(pb, mov->time); /* creation time */\n\n avio_wb32(pb, mov->time); /* modification time */\n\n }\n\n avio_wb32(pb, MOV_TIMESCALE);\n\n (version == 1) ? avio_wb64(pb, max_track_len) : avio_wb32(pb, max_track_len); /* duration of longest track */\n\n\n\n avio_wb32(pb, 0x00010000); /* reserved (preferred rate) 1.0 = normal */\n\n avio_wb16(pb, 0x0100); /* reserved (preferred volume) 1.0 = normal */\n\n avio_wb16(pb, 0); /* reserved */\n\n avio_wb32(pb, 0); /* reserved */\n\n avio_wb32(pb, 0); /* reserved */\n\n\n\n /* Matrix structure */\n\n avio_wb32(pb, 0x00010000); /* reserved */\n\n avio_wb32(pb, 0x0); /* reserved */\n\n avio_wb32(pb, 0x0); /* reserved */\n\n avio_wb32(pb, 0x0); /* reserved */\n\n avio_wb32(pb, 0x00010000); /* reserved */\n\n avio_wb32(pb, 0x0); /* reserved */\n\n avio_wb32(pb, 0x0); /* reserved */\n\n avio_wb32(pb, 0x0); /* reserved */\n\n avio_wb32(pb, 0x40000000); /* reserved */\n\n\n\n avio_wb32(pb, 0); /* reserved (preview time) */\n\n avio_wb32(pb, 0); /* reserved (preview duration) */\n\n avio_wb32(pb, 0); /* reserved (poster time) */\n\n avio_wb32(pb, 0); /* reserved (selection time) */\n\n avio_wb32(pb, 0); /* reserved (selection duration) */\n\n avio_wb32(pb, 0); /* reserved (current time) */\n\n avio_wb32(pb, max_track_id + 1); /* Next track id */\n\n return 0x6c;\n\n}\n", + "output": "0", + "index": 4750 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void setup_rt_frame(int sig, struct target_sigaction *ka,\n\n target_siginfo_t *info,\n\n target_sigset_t *set, CPUS390XState *env)\n\n{\n\n int i;\n\n rt_sigframe *frame;\n\n abi_ulong frame_addr;\n\n\n\n frame_addr = get_sigframe(ka, env, sizeof *frame);\n\n qemu_log(\"%s: frame_addr 0x%llx\\n\", __FUNCTION__,\n\n (unsigned long long)frame_addr);\n\n if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {\n\n goto give_sigsegv;\n\n }\n\n\n\n qemu_log(\"%s: 1\\n\", __FUNCTION__);\n\n if (copy_siginfo_to_user(&frame->info, info)) {\n\n goto give_sigsegv;\n\n }\n\n\n\n /* Create the ucontext. */\n\n __put_user(0, &frame->uc.tuc_flags);\n\n __put_user((abi_ulong)0, (abi_ulong *)&frame->uc.tuc_link);\n\n __put_user(target_sigaltstack_used.ss_sp, &frame->uc.tuc_stack.ss_sp);\n\n __put_user(sas_ss_flags(get_sp_from_cpustate(env)),\n\n &frame->uc.tuc_stack.ss_flags);\n\n __put_user(target_sigaltstack_used.ss_size, &frame->uc.tuc_stack.ss_size);\n\n save_sigregs(env, &frame->uc.tuc_mcontext);\n\n for (i = 0; i < TARGET_NSIG_WORDS; i++) {\n\n __put_user((abi_ulong)set->sig[i],\n\n (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]);\n\n }\n\n\n\n /* Set up to return from userspace. If provided, use a stub\n\n already in userspace. */\n\n if (ka->sa_flags & TARGET_SA_RESTORER) {\n\n env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;\n\n } else {\n\n env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;\n\n if (__put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,\n\n (uint16_t *)(frame->retcode))) {\n\n goto give_sigsegv;\n\n }\n\n }\n\n\n\n /* Set up backchain. */\n\n if (__put_user(env->regs[15], (abi_ulong *) frame)) {\n\n goto give_sigsegv;\n\n }\n\n\n\n /* Set up registers for signal handler */\n\n env->regs[15] = frame_addr;\n\n env->psw.addr = (target_ulong) ka->_sa_handler | PSW_ADDR_AMODE;\n\n\n\n env->regs[2] = sig; //map_signal(sig);\n\n env->regs[3] = frame_addr + offsetof(typeof(*frame), info);\n\n env->regs[4] = frame_addr + offsetof(typeof(*frame), uc);\n\n return;\n\n\n\ngive_sigsegv:\n\n qemu_log(\"%s: give_sigsegv\\n\", __FUNCTION__);\n\n unlock_user_struct(frame, frame_addr, 1);\n\n force_sig(TARGET_SIGSEGV);\n\n}\n", + "output": "0", + "index": 23054 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter,\n\n const int16_t **lumSrc, int lumFilterSize,\n\n const int16_t *chrFilter, const int16_t **chrUSrc,\n\n const int16_t **chrVSrc, int chrFilterSize,\n\n const int16_t **alpSrc, uint8_t *dest, int dstW,\n\n int y, enum AVPixelFormat target)\n\n{\n\n const uint8_t * const d128=dither_8x8_220[y&7];\n\n int i;\n\n unsigned acc = 0;\n\n int err = 0;\n\n\n\n for (i = 0; i < dstW; i += 2) {\n\n int j;\n\n int Y1 = 1 << 18;\n\n int Y2 = 1 << 18;\n\n\n\n for (j = 0; j < lumFilterSize; j++) {\n\n Y1 += lumSrc[j][i] * lumFilter[j];\n\n Y2 += lumSrc[j][i+1] * lumFilter[j];\n\n }\n\n Y1 >>= 19;\n\n Y2 >>= 19;\n\n if ((Y1 | Y2) & 0x100) {\n\n Y1 = av_clip_uint8(Y1);\n\n Y2 = av_clip_uint8(Y2);\n\n }\n\n if (c->flags & SWS_ERROR_DIFFUSION) {\n\n Y1 += (7*err + 1*c->dither_error[0][i] + 5*c->dither_error[0][i+1] + 3*c->dither_error[0][i+2] + 8 - 256)>>4;\n\n c->dither_error[0][i] = err;\n\n acc = 2*acc + (Y1 >= 128);\n\n Y1 -= 220*(acc&1);\n\n\n\n err = Y2 + ((7*Y1 + 1*c->dither_error[0][i+1] + 5*c->dither_error[0][i+2] + 3*c->dither_error[0][i+3] + 8 - 256)>>4);\n\n c->dither_error[0][i+1] = Y1;\n\n acc = 2*acc + (err >= 128);\n\n err -= 220*(acc&1);\n\n } else {\n\n accumulate_bit(acc, Y1 + d128[(i + 0) & 7]);\n\n accumulate_bit(acc, Y2 + d128[(i + 1) & 7]);\n\n }\n\n if ((i & 7) == 6) {\n\n output_pixel(*dest++, acc);\n\n }\n\n }\n\n c->dither_error[0][i] = err;\n\n\n\n if (i & 6) {\n\n output_pixel(*dest, acc);\n\n }\n\n}\n", + "output": "0", + "index": 18569 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,\n\n const char *boot_device,\n\n BusState *idebus0, BusState *idebus1,\n\n ISADevice *s)\n\n{\n\n int val, nb, nb_heads, max_track, last_sect, i;\n\n FDriveType fd_type[2];\n\n DriveInfo *fd[2];\n\n static pc_cmos_init_late_arg arg;\n\n\n\n /* various important CMOS locations needed by PC/Bochs bios */\n\n\n\n /* memory size */\n\n val = 640; /* base memory in K */\n\n rtc_set_memory(s, 0x15, val);\n\n rtc_set_memory(s, 0x16, val >> 8);\n\n\n\n val = (ram_size / 1024) - 1024;\n\n if (val > 65535)\n\n val = 65535;\n\n rtc_set_memory(s, 0x17, val);\n\n rtc_set_memory(s, 0x18, val >> 8);\n\n rtc_set_memory(s, 0x30, val);\n\n rtc_set_memory(s, 0x31, val >> 8);\n\n\n\n if (above_4g_mem_size) {\n\n rtc_set_memory(s, 0x5b, (unsigned int)above_4g_mem_size >> 16);\n\n rtc_set_memory(s, 0x5c, (unsigned int)above_4g_mem_size >> 24);\n\n rtc_set_memory(s, 0x5d, (uint64_t)above_4g_mem_size >> 32);\n\n }\n\n\n\n if (ram_size > (16 * 1024 * 1024))\n\n val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536);\n\n else\n\n val = 0;\n\n if (val > 65535)\n\n val = 65535;\n\n rtc_set_memory(s, 0x34, val);\n\n rtc_set_memory(s, 0x35, val >> 8);\n\n\n\n /* set the number of CPU */\n\n rtc_set_memory(s, 0x5f, smp_cpus - 1);\n\n\n\n /* set boot devices, and disable floppy signature check if requested */\n\n if (set_boot_dev(s, boot_device, fd_bootchk)) {\n\n exit(1);\n\n }\n\n\n\n /* floppy type */\n\n for (i = 0; i < 2; i++) {\n\n fd[i] = drive_get(IF_FLOPPY, 0, i);\n\n if (fd[i]) {\n\n bdrv_get_floppy_geometry_hint(fd[i]->bdrv, &nb_heads, &max_track,\n\n &last_sect, FDRIVE_DRV_NONE,\n\n &fd_type[i]);\n\n } else {\n\n fd_type[i] = FDRIVE_DRV_NONE;\n\n }\n\n }\n\n val = (cmos_get_fd_drive_type(fd_type[0]) << 4) |\n\n cmos_get_fd_drive_type(fd_type[1]);\n\n rtc_set_memory(s, 0x10, val);\n\n\n\n val = 0;\n\n nb = 0;\n\n if (fd_type[0] < FDRIVE_DRV_NONE) {\n\n nb++;\n\n }\n\n if (fd_type[1] < FDRIVE_DRV_NONE) {\n\n nb++;\n\n }\n\n switch (nb) {\n\n case 0:\n\n break;\n\n case 1:\n\n val |= 0x01; /* 1 drive, ready for boot */\n\n break;\n\n case 2:\n\n val |= 0x41; /* 2 drives, ready for boot */\n\n break;\n\n }\n\n val |= 0x02; /* FPU is there */\n\n val |= 0x04; /* PS/2 mouse installed */\n\n rtc_set_memory(s, REG_EQUIPMENT_BYTE, val);\n\n\n\n /* hard drives */\n\n arg.rtc_state = s;\n\n arg.idebus0 = idebus0;\n\n arg.idebus1 = idebus1;\n\n qemu_register_reset(pc_cmos_init_late, &arg);\n\n}\n", + "output": "0", + "index": 13015 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int hds_write_header(AVFormatContext *s)\n\n{\n\n HDSContext *c = s->priv_data;\n\n int ret = 0, i;\n\n AVOutputFormat *oformat;\n\n\n\n mkdir(s->filename, 0777);\n\n\n\n oformat = av_guess_format(\"flv\", NULL, NULL);\n\n if (!oformat) {\n\n ret = AVERROR_MUXER_NOT_FOUND;\n\n goto fail;\n\n }\n\n\n\n c->streams = av_mallocz(sizeof(*c->streams) * s->nb_streams);\n\n if (!c->streams) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n\n\n for (i = 0; i < s->nb_streams; i++) {\n\n OutputStream *os = &c->streams[c->nb_streams];\n\n AVFormatContext *ctx;\n\n AVStream *st = s->streams[i];\n\n\n\n if (!st->codec->bit_rate) {\n\n av_log(s, AV_LOG_ERROR, \"No bit rate set for stream %d\\n\", i);\n\n ret = AVERROR(EINVAL);\n\n goto fail;\n\n }\n\n if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n\n if (os->has_video) {\n\n c->nb_streams++;\n\n os++;\n\n }\n\n os->has_video = 1;\n\n } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {\n\n if (os->has_audio) {\n\n c->nb_streams++;\n\n os++;\n\n }\n\n os->has_audio = 1;\n\n } else {\n\n av_log(s, AV_LOG_ERROR, \"Unsupported stream type in stream %d\\n\", i);\n\n ret = AVERROR(EINVAL);\n\n goto fail;\n\n }\n\n os->bitrate += s->streams[i]->codec->bit_rate;\n\n\n\n if (!os->ctx) {\n\n os->first_stream = i;\n\n ctx = avformat_alloc_context();\n\n if (!ctx) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n os->ctx = ctx;\n\n ctx->oformat = oformat;\n\n ctx->interrupt_callback = s->interrupt_callback;\n\n\n\n ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf),\n\n AVIO_FLAG_WRITE, os,\n\n NULL, hds_write, NULL);\n\n if (!ctx->pb) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n } else {\n\n ctx = os->ctx;\n\n }\n\n s->streams[i]->id = c->nb_streams;\n\n\n\n if (!(st = avformat_new_stream(ctx, NULL))) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n avcodec_copy_context(st->codec, s->streams[i]->codec);\n\n st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;\n\n }\n\n if (c->streams[c->nb_streams].ctx)\n\n c->nb_streams++;\n\n\n\n for (i = 0; i < c->nb_streams; i++) {\n\n OutputStream *os = &c->streams[i];\n\n int j;\n\n if ((ret = avformat_write_header(os->ctx, NULL)) < 0) {\n\n goto fail;\n\n }\n\n os->ctx_inited = 1;\n\n avio_flush(os->ctx->pb);\n\n for (j = 0; j < os->ctx->nb_streams; j++)\n\n s->streams[os->first_stream + j]->time_base = os->ctx->streams[j]->time_base;\n\n\n\n snprintf(os->temp_filename, sizeof(os->temp_filename),\n\n \"%s/stream%d_temp\", s->filename, i);\n\n init_file(s, os, 0);\n\n\n\n if (!os->has_video && c->min_frag_duration <= 0) {\n\n av_log(s, AV_LOG_WARNING,\n\n \"No video stream in output stream %d and no min frag duration set\\n\", i);\n\n ret = AVERROR(EINVAL);\n\n }\n\n os->fragment_index = 1;\n\n write_abst(s, os, 0);\n\n }\n\n ret = write_manifest(s, 0);\n\n\n\nfail:\n\n if (ret)\n\n hds_free(s);\n\n return ret;\n\n}\n", + "output": "0", + "index": 11824 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int rtmp_write(URLContext *s, const uint8_t *buf, int size)\n{\n RTMPContext *rt = s->priv_data;\n int size_temp = size;\n int pktsize, pkttype;\n uint32_t ts;\n const uint8_t *buf_temp = buf;\n uint8_t c;\n int ret;\n do {\n if (rt->skip_bytes) {\n int skip = FFMIN(rt->skip_bytes, size_temp);\n buf_temp += skip;\n size_temp -= skip;\n rt->skip_bytes -= skip;\n continue;\n if (rt->flv_header_bytes < 11) {\n const uint8_t *header = rt->flv_header;\n int copy = FFMIN(11 - rt->flv_header_bytes, size_temp);\n bytestream_get_buffer(&buf_temp, rt->flv_header + rt->flv_header_bytes, copy);\n rt->flv_header_bytes += copy;\n size_temp -= copy;\n if (rt->flv_header_bytes < 11)\n break;\n pkttype = bytestream_get_byte(&header);\n pktsize = bytestream_get_be24(&header);\n ts = bytestream_get_be24(&header);\n ts |= bytestream_get_byte(&header) << 24;\n bytestream_get_be24(&header);\n rt->flv_size = pktsize;\n //force 12bytes header\n if (((pkttype == RTMP_PT_VIDEO || pkttype == RTMP_PT_AUDIO) && ts == 0) ||\n pkttype == RTMP_PT_NOTIFY) {\n if (pkttype == RTMP_PT_NOTIFY)\n pktsize += 16;\n rt->prev_pkt[1][RTMP_SOURCE_CHANNEL].channel_id = 0;\n //this can be a big packet, it's better to send it right here\n if ((ret = ff_rtmp_packet_create(&rt->out_pkt, RTMP_SOURCE_CHANNEL,\n pkttype, ts, pktsize)) < 0)\n rt->out_pkt.extra = rt->main_channel_id;\n rt->flv_data = rt->out_pkt.data;\n if (pkttype == RTMP_PT_NOTIFY)\n ff_amf_write_string(&rt->flv_data, \"@setDataFrame\");\n if (rt->flv_size - rt->flv_off > size_temp) {\n bytestream_get_buffer(&buf_temp, rt->flv_data + rt->flv_off, size_temp);\n rt->flv_off += size_temp;\n size_temp = 0;\n } else {\n bytestream_get_buffer(&buf_temp, rt->flv_data + rt->flv_off, rt->flv_size - rt->flv_off);\n size_temp -= rt->flv_size - rt->flv_off;\n rt->flv_off += rt->flv_size - rt->flv_off;\n if (rt->flv_off == rt->flv_size) {\n rt->skip_bytes = 4;\n if ((ret = ff_rtmp_packet_write(rt->stream, &rt->out_pkt,\n rt->chunk_size, rt->prev_pkt[1])) < 0)\n ff_rtmp_packet_destroy(&rt->out_pkt);\n rt->flv_size = 0;\n rt->flv_off = 0;\n rt->flv_header_bytes = 0;\n } while (buf_temp - buf < size);", + "output": "1", + "index": 12816 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int create_header64(DumpState *s)\n\n{\n\n int ret = 0;\n\n DiskDumpHeader64 *dh = NULL;\n\n KdumpSubHeader64 *kh = NULL;\n\n size_t size;\n\n int endian = s->dump_info.d_endian;\n\n uint32_t block_size;\n\n uint32_t sub_hdr_size;\n\n uint32_t bitmap_blocks;\n\n uint32_t status = 0;\n\n uint64_t offset_note;\n\n\n\n /* write common header, the version of kdump-compressed format is 6th */\n\n size = sizeof(DiskDumpHeader64);\n\n dh = g_malloc0(size);\n\n\n\n strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));\n\n dh->header_version = cpu_convert_to_target32(6, endian);\n\n block_size = s->page_size;\n\n dh->block_size = cpu_convert_to_target32(block_size, endian);\n\n sub_hdr_size = sizeof(struct KdumpSubHeader64) + s->note_size;\n\n sub_hdr_size = DIV_ROUND_UP(sub_hdr_size, block_size);\n\n dh->sub_hdr_size = cpu_convert_to_target32(sub_hdr_size, endian);\n\n /* dh->max_mapnr may be truncated, full 64bit is in kh.max_mapnr_64 */\n\n dh->max_mapnr = cpu_convert_to_target32(MIN(s->max_mapnr, UINT_MAX),\n\n endian);\n\n dh->nr_cpus = cpu_convert_to_target32(s->nr_cpus, endian);\n\n bitmap_blocks = DIV_ROUND_UP(s->len_dump_bitmap, block_size) * 2;\n\n dh->bitmap_blocks = cpu_convert_to_target32(bitmap_blocks, endian);\n\n strncpy(dh->utsname.machine, ELF_MACHINE_UNAME, sizeof(dh->utsname.machine));\n\n\n\n if (s->flag_compress & DUMP_DH_COMPRESSED_ZLIB) {\n\n status |= DUMP_DH_COMPRESSED_ZLIB;\n\n }\n\n#ifdef CONFIG_LZO\n\n if (s->flag_compress & DUMP_DH_COMPRESSED_LZO) {\n\n status |= DUMP_DH_COMPRESSED_LZO;\n\n }\n\n#endif\n\n#ifdef CONFIG_SNAPPY\n\n if (s->flag_compress & DUMP_DH_COMPRESSED_SNAPPY) {\n\n status |= DUMP_DH_COMPRESSED_SNAPPY;\n\n }\n\n#endif\n\n dh->status = cpu_convert_to_target32(status, endian);\n\n\n\n if (write_buffer(s->fd, 0, dh, size) < 0) {\n\n dump_error(s, \"dump: failed to write disk dump header.\\n\");\n\n ret = -1;\n\n goto out;\n\n }\n\n\n\n /* write sub header */\n\n size = sizeof(KdumpSubHeader64);\n\n kh = g_malloc0(size);\n\n\n\n /* 64bit max_mapnr_64 */\n\n kh->max_mapnr_64 = cpu_convert_to_target64(s->max_mapnr, endian);\n\n kh->phys_base = cpu_convert_to_target64(PHYS_BASE, endian);\n\n kh->dump_level = cpu_convert_to_target32(DUMP_LEVEL, endian);\n\n\n\n offset_note = DISKDUMP_HEADER_BLOCKS * block_size + size;\n\n kh->offset_note = cpu_convert_to_target64(offset_note, endian);\n\n kh->note_size = cpu_convert_to_target64(s->note_size, endian);\n\n\n\n if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *\n\n block_size, kh, size) < 0) {\n\n dump_error(s, \"dump: failed to write kdump sub header.\\n\");\n\n ret = -1;\n\n goto out;\n\n }\n\n\n\n /* write note */\n\n s->note_buf = g_malloc0(s->note_size);\n\n s->note_buf_offset = 0;\n\n\n\n /* use s->note_buf to store notes temporarily */\n\n if (write_elf64_notes(buf_write_note, s) < 0) {\n\n ret = -1;\n\n goto out;\n\n }\n\n\n\n if (write_buffer(s->fd, offset_note, s->note_buf,\n\n s->note_size) < 0) {\n\n dump_error(s, \"dump: failed to write notes\");\n\n ret = -1;\n\n goto out;\n\n }\n\n\n\n /* get offset of dump_bitmap */\n\n s->offset_dump_bitmap = (DISKDUMP_HEADER_BLOCKS + sub_hdr_size) *\n\n block_size;\n\n\n\n /* get offset of page */\n\n s->offset_page = (DISKDUMP_HEADER_BLOCKS + sub_hdr_size + bitmap_blocks) *\n\n block_size;\n\n\n\nout:\n\n g_free(dh);\n\n g_free(kh);\n\n g_free(s->note_buf);\n\n\n\n return ret;\n\n}\n", + "output": "0", + "index": 1608 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void do_apply_filter(APEContext *ctx, int version, APEFilter *f,\n\n int32_t *data, int count, int order, int fracbits)\n\n{\n\n int res;\n\n int absres;\n\n\n\n while (count--) {\n\n /* round fixedpoint scalar product */\n\n res = ctx->adsp.scalarproduct_and_madd_int16(f->coeffs,\n\n f->delay - order,\n\n f->adaptcoeffs - order,\n\n order, APESIGN(*data));\n\n res = (res + (1 << (fracbits - 1))) >> fracbits;\n\n res += *data;\n\n *data++ = res;\n\n\n\n /* Update the output history */\n\n *f->delay++ = av_clip_int16(res);\n\n\n\n if (version < 3980) {\n\n /* Version ??? to < 3.98 files (untested) */\n\n f->adaptcoeffs[0] = (res == 0) ? 0 : ((res >> 28) & 8) - 4;\n\n f->adaptcoeffs[-4] >>= 1;\n\n f->adaptcoeffs[-8] >>= 1;\n\n } else {\n\n /* Version 3.98 and later files */\n\n\n\n /* Update the adaption coefficients */\n\n absres = FFABS(res);\n\n if (absres)\n\n *f->adaptcoeffs = ((res & (-1<<31)) ^ (-1<<30)) >>\n\n (25 + (absres <= f->avg*3) + (absres <= f->avg*4/3));\n\n else\n\n *f->adaptcoeffs = 0;\n\n\n\n f->avg += (absres - f->avg) / 16;\n\n\n\n f->adaptcoeffs[-1] >>= 1;\n\n f->adaptcoeffs[-2] >>= 1;\n\n f->adaptcoeffs[-8] >>= 1;\n\n }\n\n\n\n f->adaptcoeffs++;\n\n\n\n /* Have we filled the history buffer? */\n\n if (f->delay == f->historybuffer + HISTORY_SIZE + (order * 2)) {\n\n memmove(f->historybuffer, f->delay - (order * 2),\n\n (order * 2) * sizeof(*f->historybuffer));\n\n f->delay = f->historybuffer + order * 2;\n\n f->adaptcoeffs = f->historybuffer + order;\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 11551 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int encode_slice(AVCodecContext *c, void *arg)\n\n{\n\n FFV1Context *fs = *(void **)arg;\n\n FFV1Context *f = fs->avctx->priv_data;\n\n int width = fs->slice_width;\n\n int height = fs->slice_height;\n\n int x = fs->slice_x;\n\n int y = fs->slice_y;\n\n const AVFrame *const p = f->frame;\n\n const int ps = (av_pix_fmt_desc_get(c->pix_fmt)->flags & AV_PIX_FMT_FLAG_PLANAR)\n\n ? (f->bits_per_raw_sample > 8) + 1\n\n : 4;\n\n\n\n if (f->key_frame)\n\n ffv1_clear_slice_state(f, fs);\n\n if (f->version > 2) {\n\n encode_slice_header(f, fs);\n\n }\n\n if (!fs->ac) {\n\n if (f->version > 2)\n\n put_rac(&fs->c, (uint8_t[]) { 129 }, 0);\n\n fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate( &fs->c) : 0;\n\n init_put_bits(&fs->pb, fs->c.bytestream_start + fs->ac_byte_count,\n\n fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count);\n\n }\n\n\n\n if (f->colorspace == 0) {\n\n const int chroma_width = -((-width) >> f->chroma_h_shift);\n\n const int chroma_height = -((-height) >> f->chroma_v_shift);\n\n const int cx = x >> f->chroma_h_shift;\n\n const int cy = y >> f->chroma_v_shift;\n\n\n\n encode_plane(fs, p->data[0] + ps * x + y * p->linesize[0],\n\n width, height, p->linesize[0], 0);\n\n\n\n if (f->chroma_planes) {\n\n encode_plane(fs, p->data[1] + ps * cx + cy * p->linesize[1],\n\n chroma_width, chroma_height, p->linesize[1], 1);\n\n encode_plane(fs, p->data[2] + ps * cx + cy * p->linesize[2],\n\n chroma_width, chroma_height, p->linesize[2], 1);\n\n }\n\n if (fs->transparency)\n\n encode_plane(fs, p->data[3] + ps * x + y * p->linesize[3], width,\n\n height, p->linesize[3], 2);\n\n } else {\n\n const uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0],\n\n p->data[1] + ps * x + y * p->linesize[1],\n\n p->data[2] + ps * x + y * p->linesize[2] };\n\n encode_rgb_frame(fs, planes, width, height, p->linesize);\n\n }\n\n emms_c();\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 13113 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void tcg_target_qemu_prologue (TCGContext *s)\n\n{\n\n int i, frame_size;\n\n#ifndef __APPLE__\n\n uint64_t addr;\n\n#endif\n\n\n\n frame_size = 0\n\n + 8 /* back chain */\n\n + 8 /* CR */\n\n + 8 /* LR */\n\n + 8 /* compiler doubleword */\n\n + 8 /* link editor doubleword */\n\n + 8 /* TOC save area */\n\n + TCG_STATIC_CALL_ARGS_SIZE\n\n + ARRAY_SIZE (tcg_target_callee_save_regs) * 8\n\n ;\n\n frame_size = (frame_size + 15) & ~15;\n\n\n\n#ifndef __APPLE__\n\n /* First emit adhoc function descriptor */\n\n addr = (uint64_t) s->code_ptr + 24;\n\n tcg_out32 (s, addr >> 32); tcg_out32 (s, addr); /* entry point */\n\n s->code_ptr += 16; /* skip TOC and environment pointer */\n\n#endif\n\n\n\n /* Prologue */\n\n tcg_out32 (s, MFSPR | RT (0) | LR);\n\n tcg_out32 (s, STDU | RS (1) | RA (1) | (-frame_size & 0xffff));\n\n for (i = 0; i < ARRAY_SIZE (tcg_target_callee_save_regs); ++i)\n\n tcg_out32 (s, (STD\n\n | RS (tcg_target_callee_save_regs[i])\n\n | RA (1)\n\n | (i * 8 + 48 + TCG_STATIC_CALL_ARGS_SIZE)\n\n )\n\n );\n\n tcg_out32 (s, STD | RS (0) | RA (1) | (frame_size + 16));\n\n\n\n#ifdef CONFIG_USE_GUEST_BASE\n\n if (GUEST_BASE) {\n\n tcg_out_movi (s, TCG_TYPE_I64, TCG_GUEST_BASE_REG, GUEST_BASE);\n\n tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG);\n\n }\n\n#endif\n\n\n\n tcg_out32 (s, MTSPR | RS (3) | CTR);\n\n tcg_out32 (s, BCCTR | BO_ALWAYS);\n\n\n\n /* Epilogue */\n\n tb_ret_addr = s->code_ptr;\n\n\n\n for (i = 0; i < ARRAY_SIZE (tcg_target_callee_save_regs); ++i)\n\n tcg_out32 (s, (LD\n\n | RT (tcg_target_callee_save_regs[i])\n\n | RA (1)\n\n | (i * 8 + 48 + TCG_STATIC_CALL_ARGS_SIZE)\n\n )\n\n );\n\n tcg_out32 (s, LD | RT (0) | RA (1) | (frame_size + 16));\n\n tcg_out32 (s, MTSPR | RS (0) | LR);\n\n tcg_out32 (s, ADDI | RT (1) | RA (1) | frame_size);\n\n tcg_out32 (s, BCLR | BO_ALWAYS);\n\n}\n", + "output": "0", + "index": 18862 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int http_receive_data(HTTPContext *c)\n\n{\n\n HTTPContext *c1;\n\n\n\n if (c->buffer_end > c->buffer_ptr) {\n\n int len;\n\n\n\n len = recv(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);\n\n if (len < 0) {\n\n if (ff_neterrno() != FF_NETERROR(EAGAIN) &&\n\n ff_neterrno() != FF_NETERROR(EINTR))\n\n /* error : close connection */\n\n goto fail;\n\n } else if (len == 0)\n\n /* end of connection : close it */\n\n goto fail;\n\n else {\n\n c->buffer_ptr += len;\n\n c->data_count += len;\n\n update_datarate(&c->datarate, c->data_count);\n\n }\n\n }\n\n\n\n if (c->buffer_ptr - c->buffer >= 2 && c->data_count > FFM_PACKET_SIZE) {\n\n if (c->buffer[0] != 'f' ||\n\n c->buffer[1] != 'm') {\n\n http_log(\"Feed stream has become desynchronized -- disconnecting\\n\");\n\n goto fail;\n\n }\n\n }\n\n\n\n if (c->buffer_ptr >= c->buffer_end) {\n\n FFStream *feed = c->stream;\n\n /* a packet has been received : write it in the store, except\n\n if header */\n\n if (c->data_count > FFM_PACKET_SIZE) {\n\n\n\n // printf(\"writing pos=0x%\"PRIx64\" size=0x%\"PRIx64\"\\n\", feed->feed_write_index, feed->feed_size);\n\n /* XXX: use llseek or url_seek */\n\n lseek(c->feed_fd, feed->feed_write_index, SEEK_SET);\n\n if (write(c->feed_fd, c->buffer, FFM_PACKET_SIZE) < 0) {\n\n http_log(\"Error writing to feed file: %s\\n\", strerror(errno));\n\n goto fail;\n\n }\n\n\n\n feed->feed_write_index += FFM_PACKET_SIZE;\n\n /* update file size */\n\n if (feed->feed_write_index > c->stream->feed_size)\n\n feed->feed_size = feed->feed_write_index;\n\n\n\n /* handle wrap around if max file size reached */\n\n if (c->stream->feed_max_size && feed->feed_write_index >= c->stream->feed_max_size)\n\n feed->feed_write_index = FFM_PACKET_SIZE;\n\n\n\n /* write index */\n\n ffm_write_write_index(c->feed_fd, feed->feed_write_index);\n\n\n\n /* wake up any waiting connections */\n\n for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {\n\n if (c1->state == HTTPSTATE_WAIT_FEED &&\n\n c1->stream->feed == c->stream->feed)\n\n c1->state = HTTPSTATE_SEND_DATA;\n\n }\n\n } else {\n\n /* We have a header in our hands that contains useful data */\n\n AVFormatContext *s = NULL;\n\n ByteIOContext *pb;\n\n AVInputFormat *fmt_in;\n\n int i;\n\n\n\n url_open_buf(&pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY);\n\n pb->is_streamed = 1;\n\n\n\n /* use feed output format name to find corresponding input format */\n\n fmt_in = av_find_input_format(feed->fmt->name);\n\n if (!fmt_in)\n\n goto fail;\n\n\n\n av_open_input_stream(&s, pb, c->stream->feed_filename, fmt_in, NULL);\n\n\n\n /* Now we have the actual streams */\n\n if (s->nb_streams != feed->nb_streams) {\n\n av_close_input_stream(s);\n\n av_free(pb);\n\n goto fail;\n\n }\n\n\n\n for (i = 0; i < s->nb_streams; i++)\n\n memcpy(feed->streams[i]->codec,\n\n s->streams[i]->codec, sizeof(AVCodecContext));\n\n\n\n av_close_input_stream(s);\n\n av_free(pb);\n\n }\n\n c->buffer_ptr = c->buffer;\n\n }\n\n\n\n return 0;\n\n fail:\n\n c->stream->feed_opened = 0;\n\n close(c->feed_fd);\n\n /* wake up any waiting connections to stop waiting for feed */\n\n for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) {\n\n if (c1->state == HTTPSTATE_WAIT_FEED &&\n\n c1->stream->feed == c->stream->feed)\n\n c1->state = HTTPSTATE_SEND_DATA_TRAILER;\n\n }\n\n return -1;\n\n}\n", + "output": "0", + "index": 26869 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static Aml *build_crs(PCIHostState *host,\n\n GPtrArray *io_ranges, GPtrArray *mem_ranges)\n\n{\n\n Aml *crs = aml_resource_template();\n\n uint8_t max_bus = pci_bus_num(host->bus);\n\n uint8_t type;\n\n int devfn;\n\n\n\n for (devfn = 0; devfn < ARRAY_SIZE(host->bus->devices); devfn++) {\n\n int i;\n\n uint64_t range_base, range_limit;\n\n PCIDevice *dev = host->bus->devices[devfn];\n\n\n\n if (!dev) {\n\n continue;\n\n }\n\n\n\n for (i = 0; i < PCI_NUM_REGIONS; i++) {\n\n PCIIORegion *r = &dev->io_regions[i];\n\n\n\n range_base = r->addr;\n\n range_limit = r->addr + r->size - 1;\n\n\n\n /*\n\n * Work-around for old bioses\n\n * that do not support multiple root buses\n\n */\n\n if (!range_base || range_base > range_limit) {\n\n continue;\n\n }\n\n\n\n if (r->type & PCI_BASE_ADDRESS_SPACE_IO) {\n\n aml_append(crs,\n\n aml_word_io(AML_MIN_FIXED, AML_MAX_FIXED,\n\n AML_POS_DECODE, AML_ENTIRE_RANGE,\n\n 0,\n\n range_base,\n\n range_limit,\n\n 0,\n\n range_limit - range_base + 1));\n\n crs_range_insert(io_ranges, range_base, range_limit);\n\n } else { /* \"memory\" */\n\n aml_append(crs,\n\n aml_dword_memory(AML_POS_DECODE, AML_MIN_FIXED,\n\n AML_MAX_FIXED, AML_NON_CACHEABLE,\n\n AML_READ_WRITE,\n\n 0,\n\n range_base,\n\n range_limit,\n\n 0,\n\n range_limit - range_base + 1));\n\n crs_range_insert(mem_ranges, range_base, range_limit);\n\n }\n\n }\n\n\n\n type = dev->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTION;\n\n if (type == PCI_HEADER_TYPE_BRIDGE) {\n\n uint8_t subordinate = dev->config[PCI_SUBORDINATE_BUS];\n\n if (subordinate > max_bus) {\n\n max_bus = subordinate;\n\n }\n\n\n\n range_base = pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_IO);\n\n range_limit = pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_IO);\n\n\n\n /*\n\n * Work-around for old bioses\n\n * that do not support multiple root buses\n\n */\n\n if (range_base || range_base > range_limit) {\n\n aml_append(crs,\n\n aml_word_io(AML_MIN_FIXED, AML_MAX_FIXED,\n\n AML_POS_DECODE, AML_ENTIRE_RANGE,\n\n 0,\n\n range_base,\n\n range_limit,\n\n 0,\n\n range_limit - range_base + 1));\n\n crs_range_insert(io_ranges, range_base, range_limit);\n\n }\n\n\n\n range_base =\n\n pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_MEMORY);\n\n range_limit =\n\n pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_MEMORY);\n\n\n\n /*\n\n * Work-around for old bioses\n\n * that do not support multiple root buses\n\n */\n\n if (range_base || range_base > range_limit) {\n\n aml_append(crs,\n\n aml_dword_memory(AML_POS_DECODE, AML_MIN_FIXED,\n\n AML_MAX_FIXED, AML_NON_CACHEABLE,\n\n AML_READ_WRITE,\n\n 0,\n\n range_base,\n\n range_limit,\n\n 0,\n\n range_limit - range_base + 1));\n\n crs_range_insert(mem_ranges, range_base, range_limit);\n\n }\n\n\n\n range_base =\n\n pci_bridge_get_base(dev, PCI_BASE_ADDRESS_MEM_PREFETCH);\n\n range_limit =\n\n pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_MEM_PREFETCH);\n\n\n\n /*\n\n * Work-around for old bioses\n\n * that do not support multiple root buses\n\n */\n\n if (range_base || range_base > range_limit) {\n\n aml_append(crs,\n\n aml_dword_memory(AML_POS_DECODE, AML_MIN_FIXED,\n\n AML_MAX_FIXED, AML_NON_CACHEABLE,\n\n AML_READ_WRITE,\n\n 0,\n\n range_base,\n\n range_limit,\n\n 0,\n\n range_limit - range_base + 1));\n\n crs_range_insert(mem_ranges, range_base, range_limit);\n\n }\n\n }\n\n }\n\n\n\n aml_append(crs,\n\n aml_word_bus_number(AML_MIN_FIXED, AML_MAX_FIXED, AML_POS_DECODE,\n\n 0,\n\n pci_bus_num(host->bus),\n\n max_bus,\n\n 0,\n\n max_bus - pci_bus_num(host->bus) + 1));\n\n\n\n return crs;\n\n}\n", + "output": "0", + "index": 26781 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int avformat_open_input(AVFormatContext **ps, const char *filename,\n\n AVInputFormat *fmt, AVDictionary **options)\n\n{\n\n AVFormatContext *s = *ps;\n\n int ret = 0;\n\n AVDictionary *tmp = NULL;\n\n ID3v2ExtraMeta *id3v2_extra_meta = NULL;\n\n\n\n if (!s && !(s = avformat_alloc_context()))\n\n return AVERROR(ENOMEM);\n\n if (!s->av_class) {\n\n av_log(NULL, AV_LOG_ERROR, \"Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n if (fmt)\n\n s->iformat = fmt;\n\n\n\n if (options)\n\n av_dict_copy(&tmp, *options, 0);\n\n\n\n if ((ret = av_opt_set_dict(s, &tmp)) < 0)\n\n goto fail;\n\n\n\n if ((ret = init_input(s, filename, &tmp)) < 0)\n\n goto fail;\n\n s->probe_score = ret;\n\n avio_skip(s->pb, s->skip_initial_bytes);\n\n\n\n /* Check filename in case an image number is expected. */\n\n if (s->iformat->flags & AVFMT_NEEDNUMBER) {\n\n if (!av_filename_number_test(filename)) {\n\n ret = AVERROR(EINVAL);\n\n goto fail;\n\n }\n\n }\n\n\n\n s->duration = s->start_time = AV_NOPTS_VALUE;\n\n av_strlcpy(s->filename, filename ? filename : \"\", sizeof(s->filename));\n\n\n\n /* Allocate private data. */\n\n if (s->iformat->priv_data_size > 0) {\n\n if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) {\n\n ret = AVERROR(ENOMEM);\n\n goto fail;\n\n }\n\n if (s->iformat->priv_class) {\n\n *(const AVClass **) s->priv_data = s->iformat->priv_class;\n\n av_opt_set_defaults(s->priv_data);\n\n if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)\n\n goto fail;\n\n }\n\n }\n\n\n\n /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */\n\n if (s->pb)\n\n ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);\n\n\n\n if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->iformat->read_header)\n\n if ((ret = s->iformat->read_header(s)) < 0)\n\n goto fail;\n\n\n\n if (id3v2_extra_meta) {\n\n if (!strcmp(s->iformat->name, \"mp3\") || !strcmp(s->iformat->name, \"aac\") ||\n\n !strcmp(s->iformat->name, \"tta\")) {\n\n if ((ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0)\n\n goto fail;\n\n } else\n\n av_log(s, AV_LOG_DEBUG, \"demuxer does not support additional id3 data, skipping\\n\");\n\n }\n\n ff_id3v2_free_extra_meta(&id3v2_extra_meta);\n\n\n\n if ((ret = avformat_queue_attached_pictures(s)) < 0)\n\n goto fail;\n\n\n\n if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->data_offset)\n\n s->data_offset = avio_tell(s->pb);\n\n\n\n s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;\n\n\n\n if (options) {\n\n av_dict_free(options);\n\n *options = tmp;\n\n }\n\n *ps = s;\n\n return 0;\n\n\n\nfail:\n\n ff_id3v2_free_extra_meta(&id3v2_extra_meta);\n\n av_dict_free(&tmp);\n\n if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO))\n\n avio_close(s->pb);\n\n avformat_free_context(s);\n\n *ps = NULL;\n\n return ret;\n\n}\n", + "output": "0", + "index": 3124 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode(AVCodecContext *avctx, void *data, int *data_size,\n\n AVPacket *avpkt)\n\n{\n\n const uint8_t *buf = avpkt->data;\n\n int buf_size = avpkt->size;\n\n\n\n const uint8_t *buf_end;\n\n uint8_t segment_type;\n\n int segment_length;\n\n int i, ret;\n\n\n\n av_dlog(avctx, \"PGS sub packet:\\n\");\n\n\n\n for (i = 0; i < buf_size; i++) {\n\n av_dlog(avctx, \"%02x \", buf[i]);\n\n if (i % 16 == 15)\n\n av_dlog(avctx, \"\\n\");\n\n }\n\n\n\n if (i & 15)\n\n av_dlog(avctx, \"\\n\");\n\n\n\n *data_size = 0;\n\n\n\n /* Ensure that we have received at a least a segment code and segment length */\n\n if (buf_size < 3)\n\n return -1;\n\n\n\n buf_end = buf + buf_size;\n\n\n\n /* Step through buffer to identify segments */\n\n while (buf < buf_end) {\n\n segment_type = bytestream_get_byte(&buf);\n\n segment_length = bytestream_get_be16(&buf);\n\n\n\n av_dlog(avctx, \"Segment Length %d, Segment Type %x\\n\", segment_length, segment_type);\n\n\n\n if (segment_type != DISPLAY_SEGMENT && segment_length > buf_end - buf)\n\n break;\n\n\n\n switch (segment_type) {\n\n case PALETTE_SEGMENT:\n\n parse_palette_segment(avctx, buf, segment_length);\n\n break;\n\n case PICTURE_SEGMENT:\n\n parse_picture_segment(avctx, buf, segment_length);\n\n break;\n\n case PRESENTATION_SEGMENT:\n\n ret = parse_presentation_segment(avctx, buf, segment_length, avpkt->pts);\n\n if (ret < 0)\n\n return ret;\n\n break;\n\n case WINDOW_SEGMENT:\n\n /*\n\n * Window Segment Structure (No new information provided):\n\n * 2 bytes: Unknown,\n\n * 2 bytes: X position of subtitle,\n\n * 2 bytes: Y position of subtitle,\n\n * 2 bytes: Width of subtitle,\n\n * 2 bytes: Height of subtitle.\n\n */\n\n break;\n\n case DISPLAY_SEGMENT:\n\n *data_size = display_end_segment(avctx, data, buf, segment_length);\n\n break;\n\n default:\n\n av_log(avctx, AV_LOG_ERROR, \"Unknown subtitle segment type 0x%x, length %d\\n\",\n\n segment_type, segment_length);\n\n break;\n\n }\n\n\n\n buf += segment_length;\n\n }\n\n\n\n return buf_size;\n\n}\n", + "output": "0", + "index": 27204 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSList *group,\n\n GtkWidget *view_menu)\n\n{\n\n const char *label;\n\n char buffer[32];\n\n char path[32];\n\n#if VTE_CHECK_VERSION(0, 26, 0)\n\n VtePty *pty;\n\n#endif\n\n GIOChannel *chan;\n\n GtkWidget *scrolled_window;\n\n GtkAdjustment *vadjustment;\n\n int master_fd, slave_fd;\n\n\n\n snprintf(buffer, sizeof(buffer), \"vc%d\", index);\n\n snprintf(path, sizeof(path), \"/View/VC%d\", index);\n\n\n\n vc->chr = vcs[index];\n\n\n\n if (vc->chr->label) {\n\n label = vc->chr->label;\n\n } else {\n\n label = buffer;\n\n }\n\n\n\n vc->menu_item = gtk_radio_menu_item_new_with_mnemonic(group, label);\n\n group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(vc->menu_item));\n\n gtk_menu_item_set_accel_path(GTK_MENU_ITEM(vc->menu_item), path);\n\n gtk_accel_map_add_entry(path, GDK_KEY_2 + index, GDK_CONTROL_MASK | GDK_MOD1_MASK);\n\n\n\n vc->terminal = vte_terminal_new();\n\n\n\n master_fd = qemu_openpty_raw(&slave_fd, NULL);\n\n g_assert(master_fd != -1);\n\n\n\n#if VTE_CHECK_VERSION(0, 26, 0)\n\n pty = vte_pty_new_foreign(master_fd, NULL);\n\n vte_terminal_set_pty_object(VTE_TERMINAL(vc->terminal), pty);\n\n#else\n\n vte_terminal_set_pty(VTE_TERMINAL(vc->terminal), master_fd);\n\n#endif\n\n\n\n vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc->terminal), -1);\n\n\n\n vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc->terminal));\n\n\n\n scrolled_window = gtk_scrolled_window_new(NULL, vadjustment);\n\n gtk_container_add(GTK_CONTAINER(scrolled_window), vc->terminal);\n\n\n\n vte_terminal_set_size(VTE_TERMINAL(vc->terminal), 80, 25);\n\n\n\n vc->fd = slave_fd;\n\n vc->chr->opaque = vc;\n\n vc->scrolled_window = scrolled_window;\n\n\n\n gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vc->scrolled_window),\n\n GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);\n\n\n\n gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), scrolled_window, gtk_label_new(label));\n\n g_signal_connect(vc->menu_item, \"activate\",\n\n G_CALLBACK(gd_menu_switch_vc), s);\n\n\n\n gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc->menu_item);\n\n\n\n qemu_chr_be_generic_open(vc->chr);\n\n if (vc->chr->init) {\n\n vc->chr->init(vc->chr);\n\n }\n\n\n\n chan = g_io_channel_unix_new(vc->fd);\n\n g_io_add_watch(chan, G_IO_IN, gd_vc_in, vc);\n\n\n\n return group;\n\n}\n", + "output": "0", + "index": 14732 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref)\n\n{\n\n BufferSourceContext *c = buffer_filter->priv;\n\n AVFilterLink *outlink = buffer_filter->outputs[0];\n\n int ret;\n\n\n\n if (c->picref) {\n\n av_log(buffer_filter, AV_LOG_ERROR,\n\n \"Buffering several frames is not supported. \"\n\n \"Please consume all available frames before adding a new one.\\n\"\n\n );\n\n //return -1;\n\n }\n\n\n\n if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) {\n\n AVFilterContext *scale = buffer_filter->outputs[0]->dst;\n\n AVFilterLink *link;\n\n char scale_param[1024];\n\n\n\n av_log(buffer_filter, AV_LOG_INFO,\n\n \"Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\\n\",\n\n c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name,\n\n picref->video->w, picref->video->h, av_pix_fmt_descriptors[picref->format].name);\n\n\n\n if (!scale || strcmp(scale->filter->name, \"scale\")) {\n\n AVFilter *f = avfilter_get_by_name(\"scale\");\n\n\n\n av_log(buffer_filter, AV_LOG_INFO, \"Inserting scaler filter\\n\");\n\n if ((ret = avfilter_open(&scale, f, \"Input equalizer\")) < 0)\n\n return ret;\n\n\n\n snprintf(scale_param, sizeof(scale_param)-1, \"%d:%d:%s\", c->w, c->h, c->sws_param);\n\n if ((ret = avfilter_init_filter(scale, scale_param, NULL)) < 0) {\n\n avfilter_free(scale);\n\n return ret;\n\n }\n\n\n\n if ((ret = avfilter_insert_filter(buffer_filter->outputs[0], scale, 0, 0)) < 0) {\n\n avfilter_free(scale);\n\n return ret;\n\n }\n\n scale->outputs[0]->time_base = scale->inputs[0]->time_base;\n\n\n\n scale->outputs[0]->format= c->pix_fmt;\n\n } else if (!strcmp(scale->filter->name, \"scale\")) {\n\n snprintf(scale_param, sizeof(scale_param)-1, \"%d:%d:%s\",\n\n scale->outputs[0]->w, scale->outputs[0]->h, c->sws_param);\n\n scale->filter->init(scale, scale_param, NULL);\n\n }\n\n\n\n c->pix_fmt = scale->inputs[0]->format = picref->format;\n\n c->w = scale->inputs[0]->w = picref->video->w;\n\n c->h = scale->inputs[0]->h = picref->video->h;\n\n\n\n link = scale->outputs[0];\n\n if ((ret = link->srcpad->config_props(link)) < 0)\n\n return ret;\n\n }\n\n\n\n c->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,\n\n picref->video->w, picref->video->h);\n\n av_image_copy(c->picref->data, c->picref->linesize,\n\n picref->data, picref->linesize,\n\n picref->format, picref->video->w, picref->video->h);\n\n avfilter_copy_buffer_ref_props(c->picref, picref);\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 10962 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void ffmpeg_cleanup(int ret)\n{\n int i, j;\n if (do_benchmark) {\n int maxrss = getmaxrss() / 1024;\n av_log(NULL, AV_LOG_INFO, \"bench: maxrss=%ikB\\n\", maxrss);\n }\n for (i = 0; i < nb_filtergraphs; i++) {\n FilterGraph *fg = filtergraphs[i];\n avfilter_graph_free(&fg->graph);\n for (j = 0; j < fg->nb_inputs; j++) {\n av_freep(&fg->inputs[j]->name);\n av_freep(&fg->inputs[j]);\n }\n av_freep(&fg->inputs);\n for (j = 0; j < fg->nb_outputs; j++) {\n av_freep(&fg->outputs[j]->name);\n av_freep(&fg->outputs[j]);\n }\n av_freep(&fg->outputs);\n av_freep(&fg->graph_desc);\n av_freep(&filtergraphs[i]);\n }\n av_freep(&filtergraphs);\n av_freep(&subtitle_out);\n /* close files */\n for (i = 0; i < nb_output_files; i++) {\n OutputFile *of = output_files[i];\n AVFormatContext *s;\n if (!of)\n continue;\n s = of->ctx;\n if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE))\n avio_closep(&s->pb);\n avformat_free_context(s);\n av_dict_free(&of->opts);\n av_freep(&output_files[i]);\n }\n for (i = 0; i < nb_output_streams; i++) {\n OutputStream *ost = output_streams[i];\n AVBitStreamFilterContext *bsfc;\n if (!ost)\n continue;\n bsfc = ost->bitstream_filters;\n while (bsfc) {\n AVBitStreamFilterContext *next = bsfc->next;\n av_bitstream_filter_close(bsfc);\n bsfc = next;\n }\n ost->bitstream_filters = NULL;\n av_frame_free(&ost->filtered_frame);\n av_frame_free(&ost->last_frame);\n av_parser_close(ost->parser);\n av_freep(&ost->forced_keyframes);\n av_expr_free(ost->forced_keyframes_pexpr);\n av_freep(&ost->avfilter);\n av_freep(&ost->logfile_prefix);\n av_freep(&ost->audio_channels_map);\n ost->audio_channels_mapped = 0;\n avcodec_free_context(&ost->enc_ctx);\n av_freep(&output_streams[i]);\n }\n#if HAVE_PTHREADS\n free_input_threads();\n#endif\n for (i = 0; i < nb_input_files; i++) {\n avformat_close_input(&input_files[i]->ctx);\n av_freep(&input_files[i]);\n }\n for (i = 0; i < nb_input_streams; i++) {\n InputStream *ist = input_streams[i];\n av_frame_free(&ist->decoded_frame);\n av_frame_free(&ist->filter_frame);\n av_dict_free(&ist->decoder_opts);\n avsubtitle_free(&ist->prev_sub.subtitle);\n av_frame_free(&ist->sub2video.frame);\n av_freep(&ist->filters);\n av_freep(&ist->hwaccel_device);\n avcodec_free_context(&ist->dec_ctx);\n av_freep(&input_streams[i]);\n }\n if (vstats_file) {\n if (fclose(vstats_file))\n av_log(NULL, AV_LOG_ERROR,\n \"Error closing vstats file, loss of information possible: %s\\n\",\n av_err2str(AVERROR(errno)));\n }\n av_freep(&vstats_filename);\n av_freep(&input_streams);\n av_freep(&input_files);\n av_freep(&output_streams);\n av_freep(&output_files);\n uninit_opts();\n avformat_network_deinit();\n if (received_sigterm) {\n av_log(NULL, AV_LOG_INFO, \"Exiting normally, received signal %d.\\n\",\n (int) received_sigterm);\n } else if (ret && transcode_init_done) {\n av_log(NULL, AV_LOG_INFO, \"Conversion failed!\\n\");\n }\n term_exit();\n ffmpeg_exited = 1;\n}", + "output": "1", + "index": 3170 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int inet_listen_opts(QemuOpts *opts, int port_offset)\n\n{\n\n struct addrinfo ai,*res,*e;\n\n const char *addr;\n\n char port[33];\n\n char uaddr[INET6_ADDRSTRLEN+1];\n\n char uport[33];\n\n int slisten,rc,to,try_next;\n\n\n\n memset(&ai,0, sizeof(ai));\n\n ai.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;\n\n ai.ai_family = PF_UNSPEC;\n\n ai.ai_socktype = SOCK_STREAM;\n\n\n\n if ((qemu_opt_get(opts, \"host\") == NULL) ||\n\n (qemu_opt_get(opts, \"port\") == NULL)) {\n\n fprintf(stderr, \"%s: host and/or port not specified\\n\", __FUNCTION__);\n\n return -1;\n\n }\n\n pstrcpy(port, sizeof(port), qemu_opt_get(opts, \"port\"));\n\n addr = qemu_opt_get(opts, \"host\");\n\n\n\n to = qemu_opt_get_number(opts, \"to\", 0);\n\n if (qemu_opt_get_bool(opts, \"ipv4\", 0))\n\n ai.ai_family = PF_INET;\n\n if (qemu_opt_get_bool(opts, \"ipv6\", 0))\n\n ai.ai_family = PF_INET6;\n\n\n\n /* lookup */\n\n if (port_offset)\n\n snprintf(port, sizeof(port), \"%d\", atoi(port) + port_offset);\n\n rc = getaddrinfo(strlen(addr) ? addr : NULL, port, &ai, &res);\n\n if (rc != 0) {\n\n fprintf(stderr,\"getaddrinfo(%s,%s): %s\\n\", addr, port,\n\n gai_strerror(rc));\n\n return -1;\n\n }\n\n\n\n /* create socket + bind */\n\n for (e = res; e != NULL; e = e->ai_next) {\n\n getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,\n\n\t\t uaddr,INET6_ADDRSTRLEN,uport,32,\n\n\t\t NI_NUMERICHOST | NI_NUMERICSERV);\n\n slisten = qemu_socket(e->ai_family, e->ai_socktype, e->ai_protocol);\n\n if (slisten < 0) {\n\n fprintf(stderr,\"%s: socket(%s): %s\\n\", __FUNCTION__,\n\n inet_strfamily(e->ai_family), strerror(errno));\n\n continue;\n\n }\n\n\n\n setsockopt(slisten,SOL_SOCKET,SO_REUSEADDR,(void*)&on,sizeof(on));\n\n#ifdef IPV6_V6ONLY\n\n if (e->ai_family == PF_INET6) {\n\n /* listen on both ipv4 and ipv6 */\n\n setsockopt(slisten,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&off,\n\n sizeof(off));\n\n }\n\n#endif\n\n\n\n for (;;) {\n\n if (bind(slisten, e->ai_addr, e->ai_addrlen) == 0) {\n\n goto listen;\n\n }\n\n try_next = to && (inet_getport(e) <= to + port_offset);\n\n if (!try_next)\n\n fprintf(stderr,\"%s: bind(%s,%s,%d): %s\\n\", __FUNCTION__,\n\n inet_strfamily(e->ai_family), uaddr, inet_getport(e),\n\n strerror(errno));\n\n if (try_next) {\n\n inet_setport(e, inet_getport(e) + 1);\n\n continue;\n\n }\n\n break;\n\n }\n\n closesocket(slisten);\n\n }\n\n fprintf(stderr, \"%s: FAILED\\n\", __FUNCTION__);\n\n freeaddrinfo(res);\n\n return -1;\n\n\n\nlisten:\n\n if (listen(slisten,1) != 0) {\n\n perror(\"listen\");\n\n closesocket(slisten);\n\n freeaddrinfo(res);\n\n return -1;\n\n }\n\n snprintf(uport, sizeof(uport), \"%d\", inet_getport(e) - port_offset);\n\n qemu_opt_set(opts, \"host\", uaddr);\n\n qemu_opt_set(opts, \"port\", uport);\n\n qemu_opt_set(opts, \"ipv6\", (e->ai_family == PF_INET6) ? \"on\" : \"off\");\n\n qemu_opt_set(opts, \"ipv4\", (e->ai_family != PF_INET6) ? \"on\" : \"off\");\n\n freeaddrinfo(res);\n\n return slisten;\n\n}\n", + "output": "0", + "index": 5392 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void cris_alu_op_exec(DisasContext *dc, int op, \n\n TCGv dst, TCGv a, TCGv b, int size)\n\n{\n\n /* Emit the ALU insns. */\n\n switch (op) {\n\n case CC_OP_ADD:\n\n tcg_gen_add_tl(dst, a, b);\n\n /* Extended arithmetics. */\n\n t_gen_addx_carry(dc, dst);\n\n break;\n\n case CC_OP_ADDC:\n\n tcg_gen_add_tl(dst, a, b);\n\n t_gen_add_flag(dst, 0); /* C_FLAG. */\n\n break;\n\n case CC_OP_MCP:\n\n tcg_gen_add_tl(dst, a, b);\n\n t_gen_add_flag(dst, 8); /* R_FLAG. */\n\n break;\n\n case CC_OP_SUB:\n\n tcg_gen_sub_tl(dst, a, b);\n\n /* Extended arithmetics. */\n\n t_gen_subx_carry(dc, dst);\n\n break;\n\n case CC_OP_MOVE:\n\n tcg_gen_mov_tl(dst, b);\n\n break;\n\n case CC_OP_OR:\n\n tcg_gen_or_tl(dst, a, b);\n\n break;\n\n case CC_OP_AND:\n\n tcg_gen_and_tl(dst, a, b);\n\n break;\n\n case CC_OP_XOR:\n\n tcg_gen_xor_tl(dst, a, b);\n\n break;\n\n case CC_OP_LSL:\n\n t_gen_lsl(dst, a, b);\n\n break;\n\n case CC_OP_LSR:\n\n t_gen_lsr(dst, a, b);\n\n break;\n\n case CC_OP_ASR:\n\n t_gen_asr(dst, a, b);\n\n break;\n\n case CC_OP_NEG:\n\n tcg_gen_neg_tl(dst, b);\n\n /* Extended arithmetics. */\n\n t_gen_subx_carry(dc, dst);\n\n break;\n\n case CC_OP_LZ:\n\n gen_helper_lz(dst, b);\n\n break;\n\n case CC_OP_MULS:\n\n tcg_gen_muls2_tl(dst, cpu_PR[PR_MOF], a, b);\n\n break;\n\n case CC_OP_MULU:\n\n tcg_gen_mulu2_tl(dst, cpu_PR[PR_MOF], a, b);\n\n break;\n\n case CC_OP_DSTEP:\n\n t_gen_cris_dstep(dst, a, b);\n\n break;\n\n case CC_OP_MSTEP:\n\n t_gen_cris_mstep(dst, a, b, cpu_PR[PR_CCS]);\n\n break;\n\n case CC_OP_BOUND:\n\n {\n\n int l1;\n\n l1 = gen_new_label();\n\n tcg_gen_mov_tl(dst, a);\n\n tcg_gen_brcond_tl(TCG_COND_LEU, a, b, l1);\n\n tcg_gen_mov_tl(dst, b);\n\n gen_set_label(l1);\n\n }\n\n break;\n\n case CC_OP_CMP:\n\n tcg_gen_sub_tl(dst, a, b);\n\n /* Extended arithmetics. */\n\n t_gen_subx_carry(dc, dst);\n\n break;\n\n default:\n\n qemu_log(\"illegal ALU op.\\n\");\n\n BUG();\n\n break;\n\n }\n\n\n\n if (size == 1) {\n\n tcg_gen_andi_tl(dst, dst, 0xff);\n\n } else if (size == 2) {\n\n tcg_gen_andi_tl(dst, dst, 0xffff);\n\n }\n\n}\n", + "output": "0", + "index": 10299 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void internal_snapshot_prepare(BlkTransactionState *common,\n\n Error **errp)\n\n{\n\n Error *local_err = NULL;\n\n const char *device;\n\n const char *name;\n\n BlockBackend *blk;\n\n BlockDriverState *bs;\n\n QEMUSnapshotInfo old_sn, *sn;\n\n bool ret;\n\n qemu_timeval tv;\n\n BlockdevSnapshotInternal *internal;\n\n InternalSnapshotState *state;\n\n int ret1;\n\n\n\n g_assert(common->action->kind ==\n\n TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC);\n\n internal = common->action->blockdev_snapshot_internal_sync;\n\n state = DO_UPCAST(InternalSnapshotState, common, common);\n\n\n\n /* 1. parse input */\n\n device = internal->device;\n\n name = internal->name;\n\n\n\n /* 2. check for validation */\n\n blk = blk_by_name(device);\n\n if (!blk) {\n\n error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,\n\n \"Device '%s' not found\", device);\n\n return;\n\n }\n\n\n\n /* AioContext is released in .clean() */\n\n state->aio_context = blk_get_aio_context(blk);\n\n aio_context_acquire(state->aio_context);\n\n\n\n if (!blk_is_available(blk)) {\n\n error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);\n\n return;\n\n }\n\n bs = blk_bs(blk);\n\n\n\n state->bs = bs;\n\n bdrv_drained_begin(bs);\n\n\n\n if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT, errp)) {\n\n return;\n\n }\n\n\n\n if (bdrv_is_read_only(bs)) {\n\n error_setg(errp, \"Device '%s' is read only\", device);\n\n return;\n\n }\n\n\n\n if (!bdrv_can_snapshot(bs)) {\n\n error_setg(errp, \"Block format '%s' used by device '%s' \"\n\n \"does not support internal snapshots\",\n\n bs->drv->format_name, device);\n\n return;\n\n }\n\n\n\n if (!strlen(name)) {\n\n error_setg(errp, \"Name is empty\");\n\n return;\n\n }\n\n\n\n /* check whether a snapshot with name exist */\n\n ret = bdrv_snapshot_find_by_id_and_name(bs, NULL, name, &old_sn,\n\n &local_err);\n\n if (local_err) {\n\n error_propagate(errp, local_err);\n\n return;\n\n } else if (ret) {\n\n error_setg(errp,\n\n \"Snapshot with name '%s' already exists on device '%s'\",\n\n name, device);\n\n return;\n\n }\n\n\n\n /* 3. take the snapshot */\n\n sn = &state->sn;\n\n pstrcpy(sn->name, sizeof(sn->name), name);\n\n qemu_gettimeofday(&tv);\n\n sn->date_sec = tv.tv_sec;\n\n sn->date_nsec = tv.tv_usec * 1000;\n\n sn->vm_clock_nsec = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);\n\n\n\n ret1 = bdrv_snapshot_create(bs, sn);\n\n if (ret1 < 0) {\n\n error_setg_errno(errp, -ret1,\n\n \"Failed to create snapshot '%s' on device '%s'\",\n\n name, device);\n\n return;\n\n }\n\n\n\n /* 4. succeed, mark a snapshot is created */\n\n state->created = true;\n\n}\n", + "output": "0", + "index": 11174 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)\n\n{\n\n const char *name;\n\n const char *type;\n\n int i;\n\n\n\n type = qemu_opt_get(opts, \"type\");\n\n if (!type) {\n\n qerror_report(QERR_MISSING_PARAMETER, \"type\");\n\n return -1;\n\n }\n\n\n\n if (is_netdev) {\n\n if (strcmp(type, \"tap\") != 0 &&\n\n#ifdef CONFIG_SLIRP\n\n strcmp(type, \"user\") != 0 &&\n\n#endif\n\n#ifdef CONFIG_VDE\n\n strcmp(type, \"vde\") != 0 &&\n\n#endif\n\n strcmp(type, \"socket\") != 0) {\n\n qerror_report(QERR_INVALID_PARAMETER_VALUE, \"type\",\n\n \"a netdev backend type\");\n\n return -1;\n\n }\n\n\n\n if (qemu_opt_get(opts, \"vlan\")) {\n\n qerror_report(QERR_INVALID_PARAMETER, \"vlan\");\n\n return -1;\n\n }\n\n if (qemu_opt_get(opts, \"name\")) {\n\n qerror_report(QERR_INVALID_PARAMETER, \"name\");\n\n return -1;\n\n }\n\n if (!qemu_opts_id(opts)) {\n\n qerror_report(QERR_MISSING_PARAMETER, \"id\");\n\n return -1;\n\n }\n\n }\n\n\n\n name = qemu_opts_id(opts);\n\n if (!name) {\n\n name = qemu_opt_get(opts, \"name\");\n\n }\n\n\n\n for (i = 0; i < NET_CLIENT_TYPE_MAX; i++) {\n\n if (net_client_types[i].type != NULL &&\n\n !strcmp(net_client_types[i].type, type)) {\n\n VLANState *vlan = NULL;\n\n int ret;\n\n\n\n if (qemu_opts_validate(opts, &net_client_types[i].desc[0]) == -1) {\n\n return -1;\n\n }\n\n\n\n /* Do not add to a vlan if it's a -netdev or a nic with a\n\n * netdev= parameter. */\n\n if (!(is_netdev ||\n\n (strcmp(type, \"nic\") == 0 && qemu_opt_get(opts, \"netdev\")))) {\n\n vlan = qemu_find_vlan(qemu_opt_get_number(opts, \"vlan\", 0), 1);\n\n }\n\n\n\n ret = 0;\n\n if (net_client_types[i].init) {\n\n ret = net_client_types[i].init(opts, mon, name, vlan);\n\n if (ret < 0) {\n\n /* TODO push error reporting into init() methods */\n\n qerror_report(QERR_DEVICE_INIT_FAILED, type);\n\n return -1;\n\n }\n\n }\n\n return ret;\n\n }\n\n }\n\n\n\n qerror_report(QERR_INVALID_PARAMETER_VALUE, \"type\",\n\n \"a network client type\");\n\n return -1;\n\n}\n", + "output": "1", + "index": 17525 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void msi_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len)\n\n{\n\n uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev));\n\n bool msi64bit = flags & PCI_MSI_FLAGS_64BIT;\n\n bool msi_per_vector_mask = flags & PCI_MSI_FLAGS_MASKBIT;\n\n unsigned int nr_vectors;\n\n uint8_t log_num_vecs;\n\n uint8_t log_max_vecs;\n\n unsigned int vector;\n\n uint32_t pending;\n\n\n\n if (!ranges_overlap(addr, len, dev->msi_cap, msi_cap_sizeof(flags))) {\n\n return;\n\n }\n\n\n\n#ifdef MSI_DEBUG\n\n MSI_DEV_PRINTF(dev, \"addr 0x%\"PRIx32\" val 0x%\"PRIx32\" len %d\\n\",\n\n addr, val, len);\n\n MSI_DEV_PRINTF(dev, \"ctrl: 0x%\"PRIx16\" address: 0x%\"PRIx32,\n\n flags,\n\n pci_get_long(dev->config + msi_address_lo_off(dev)));\n\n if (msi64bit) {\n\n fprintf(stderr, \" address-hi: 0x%\"PRIx32,\n\n pci_get_long(dev->config + msi_address_hi_off(dev)));\n\n }\n\n fprintf(stderr, \" data: 0x%\"PRIx16,\n\n pci_get_word(dev->config + msi_data_off(dev, msi64bit)));\n\n if (flags & PCI_MSI_FLAGS_MASKBIT) {\n\n fprintf(stderr, \" mask 0x%\"PRIx32\" pending 0x%\"PRIx32,\n\n pci_get_long(dev->config + msi_mask_off(dev, msi64bit)),\n\n pci_get_long(dev->config + msi_pending_off(dev, msi64bit)));\n\n }\n\n fprintf(stderr, \"\\n\");\n\n#endif\n\n\n\n if (!(flags & PCI_MSI_FLAGS_ENABLE)) {\n\n return;\n\n }\n\n\n\n /*\n\n * Now MSI is enabled, clear INTx# interrupts.\n\n * the driver is prohibited from writing enable bit to mask\n\n * a service request. But the guest OS could do this.\n\n * So we just discard the interrupts as moderate fallback.\n\n *\n\n * 6.8.3.3. Enabling Operation\n\n * While enabled for MSI or MSI-X operation, a function is prohibited\n\n * from using its INTx# pin (if implemented) to request\n\n * service (MSI, MSI-X, and INTx# are mutually exclusive).\n\n */\n\n pci_device_deassert_intx(dev);\n\n\n\n /*\n\n * nr_vectors might be set bigger than capable. So clamp it.\n\n * This is not legal by spec, so we can do anything we like,\n\n * just don't crash the host\n\n */\n\n log_num_vecs =\n\n (flags & PCI_MSI_FLAGS_QSIZE) >> (ffs(PCI_MSI_FLAGS_QSIZE) - 1);\n\n log_max_vecs =\n\n (flags & PCI_MSI_FLAGS_QMASK) >> (ffs(PCI_MSI_FLAGS_QMASK) - 1);\n\n if (log_num_vecs > log_max_vecs) {\n\n flags &= ~PCI_MSI_FLAGS_QSIZE;\n\n flags |= log_max_vecs << (ffs(PCI_MSI_FLAGS_QSIZE) - 1);\n\n pci_set_word(dev->config + msi_flags_off(dev), flags);\n\n }\n\n\n\n if (!msi_per_vector_mask) {\n\n /* if per vector masking isn't supported,\n\n there is no pending interrupt. */\n\n return;\n\n }\n\n\n\n nr_vectors = msi_nr_vectors(flags);\n\n\n\n /* This will discard pending interrupts, if any. */\n\n pending = pci_get_long(dev->config + msi_pending_off(dev, msi64bit));\n\n pending &= 0xffffffff >> (PCI_MSI_VECTORS_MAX - nr_vectors);\n\n pci_set_long(dev->config + msi_pending_off(dev, msi64bit), pending);\n\n\n\n /* deliver pending interrupts which are unmasked */\n\n for (vector = 0; vector < nr_vectors; ++vector) {\n\n if (msi_is_masked(dev, vector) || !(pending & (1U << vector))) {\n\n continue;\n\n }\n\n\n\n pci_long_test_and_clear_mask(\n\n dev->config + msi_pending_off(dev, msi64bit), 1U << vector);\n\n msi_notify(dev, vector);\n\n }\n\n}\n", + "output": "0", + "index": 23041 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int mmu_translate_region(CPUS390XState *env, target_ulong vaddr,\n\n uint64_t asc, uint64_t entry, int level,\n\n target_ulong *raddr, int *flags, int rw)\n\n{\n\n CPUState *cs = CPU(s390_env_get_cpu(env));\n\n uint64_t origin, offs, new_entry;\n\n const int pchks[4] = {\n\n PGM_SEGMENT_TRANS, PGM_REG_THIRD_TRANS,\n\n PGM_REG_SEC_TRANS, PGM_REG_FIRST_TRANS\n\n };\n\n\n\n PTE_DPRINTF(\"%s: 0x%\" PRIx64 \"\\n\", __func__, entry);\n\n\n\n origin = entry & _REGION_ENTRY_ORIGIN;\n\n offs = (vaddr >> (17 + 11 * level / 4)) & 0x3ff8;\n\n\n\n new_entry = ldq_phys(cs->as, origin + offs);\n\n PTE_DPRINTF(\"%s: 0x%\" PRIx64 \" + 0x%\" PRIx64 \" => 0x%016\" PRIx64 \"\\n\",\n\n __func__, origin, offs, new_entry);\n\n\n\n if ((new_entry & _REGION_ENTRY_INV) != 0) {\n\n /* XXX different regions have different faults */\n\n DPRINTF(\"%s: invalid region\\n\", __func__);\n\n trigger_page_fault(env, vaddr, PGM_SEGMENT_TRANS, asc, rw);\n\n return -1;\n\n }\n\n\n\n if ((new_entry & _REGION_ENTRY_TYPE_MASK) != level) {\n\n trigger_page_fault(env, vaddr, PGM_TRANS_SPEC, asc, rw);\n\n return -1;\n\n }\n\n\n\n /* XXX region protection flags */\n\n /* *flags &= ~PAGE_WRITE */\n\n\n\n if (level == _ASCE_TYPE_SEGMENT) {\n\n return mmu_translate_segment(env, vaddr, asc, new_entry, raddr, flags,\n\n rw);\n\n }\n\n\n\n /* Check region table offset and length */\n\n offs = (vaddr >> (28 + 11 * (level - 4) / 4)) & 3;\n\n if (offs < ((new_entry & _REGION_ENTRY_TF) >> 6)\n\n || offs > (new_entry & _REGION_ENTRY_LENGTH)) {\n\n DPRINTF(\"%s: invalid offset or len (%lx)\\n\", __func__, new_entry);\n\n trigger_page_fault(env, vaddr, pchks[level / 4 - 1], asc, rw);\n\n return -1;\n\n }\n\n\n\n /* yet another region */\n\n return mmu_translate_region(env, vaddr, asc, new_entry, level - 4,\n\n raddr, flags, rw);\n\n}\n", + "output": "0", + "index": 15029 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err)\n\n{\n\n\n\n if (err == 0 || errno != ENOENT) {\n\n err = -errno;\n\n goto out;\n\n }\n\n\n\n if (vs->perm & P9_STAT_MODE_DIR) {\n\n err = v9fs_do_mkdir(s, vs);\n\n v9fs_create_post_mkdir(s, vs, err);\n\n } else if (vs->perm & P9_STAT_MODE_SYMLINK) {\n\n err = v9fs_do_symlink(s, vs);\n\n v9fs_create_post_perms(s, vs, err);\n\n } else if (vs->perm & P9_STAT_MODE_LINK) {\n\n int32_t nfid = atoi(vs->extension.data);\n\n V9fsFidState *nfidp = lookup_fid(s, nfid);\n\n if (nfidp == NULL) {\n\n err = -errno;\n\n v9fs_post_create(s, vs, err);\n\n }\n\n err = v9fs_do_link(s, &nfidp->path, &vs->fullname);\n\n v9fs_create_post_perms(s, vs, err);\n\n } else if (vs->perm & P9_STAT_MODE_DEVICE) {\n\n char ctype;\n\n uint32_t major, minor;\n\n mode_t nmode = 0;\n\n\n\n if (sscanf(vs->extension.data, \"%c %u %u\", &ctype, &major,\n\n &minor) != 3) {\n\n err = -errno;\n\n v9fs_post_create(s, vs, err);\n\n }\n\n\n\n switch (ctype) {\n\n case 'c':\n\n nmode = S_IFCHR;\n\n break;\n\n case 'b':\n\n nmode = S_IFBLK;\n\n break;\n\n default:\n\n err = -EIO;\n\n v9fs_post_create(s, vs, err);\n\n }\n\n\n\n nmode |= vs->perm & 0777;\n\n err = v9fs_do_mknod(s, vs, nmode, makedev(major, minor));\n\n v9fs_create_post_perms(s, vs, err);\n\n } else if (vs->perm & P9_STAT_MODE_NAMED_PIPE) {\n\n err = v9fs_do_mknod(s, vs, S_IFIFO | (vs->perm & 0777), 0);\n\n v9fs_post_create(s, vs, err);\n\n } else if (vs->perm & P9_STAT_MODE_SOCKET) {\n\n err = v9fs_do_mksock(s, &vs->fullname);\n\n v9fs_create_post_mksock(s, vs, err);\n\n } else {\n\n vs->fidp->fd = v9fs_do_open2(s, vs);\n\n v9fs_create_post_open2(s, vs, err);\n\n }\n\n\n\n return;\n\n\n\nout:\n\n v9fs_post_create(s, vs, err);\n\n}\n", + "output": "0", + "index": 24754 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_0(PAFVideoDecContext *c, uint8_t *pkt, uint8_t code)\n\n{\n\n uint32_t opcode_size, offset;\n\n uint8_t *dst, *dend, mask = 0, color = 0;\n\n const uint8_t *src, *send, *opcodes;\n\n int i, j, op = 0;\n\n\n\n i = bytestream2_get_byte(&c->gb);\n\n if (i) {\n\n if (code & 0x10) {\n\n int align;\n\n\n\n align = bytestream2_tell(&c->gb) & 3;\n\n if (align)\n\n bytestream2_skip(&c->gb, 4 - align);\n\n }\n\n do {\n\n int page, val, x, y;\n\n val = bytestream2_get_be16(&c->gb);\n\n page = val >> 14;\n\n x = (val & 0x7F) * 2;\n\n y = ((val >> 7) & 0x7F) * 2;\n\n dst = c->frame[page] + x + y * c->width;\n\n dend = c->frame[page] + c->frame_size;\n\n offset = (x & 0x7F) * 2;\n\n j = bytestream2_get_le16(&c->gb) + offset;\n\n do {\n\n offset++;\n\n if (dst + 3 * c->width + 4 > dend)\n\n return AVERROR_INVALIDDATA;\n\n read4x4block(c, dst, c->width);\n\n if ((offset & 0x3F) == 0)\n\n dst += c->width * 3;\n\n dst += 4;\n\n } while (offset < j);\n\n } while (--i);\n\n }\n\n\n\n dst = c->frame[c->current_frame];\n\n dend = c->frame[c->current_frame] + c->frame_size;\n\n do {\n\n set_src_position(c, &src, &send);\n\n if ((src + 3 * c->width + 4 > send) ||\n\n (dst + 3 * c->width + 4 > dend))\n\n return AVERROR_INVALIDDATA;\n\n copy_block4(dst, src, c->width, c->width, 4);\n\n i++;\n\n if ((i & 0x3F) == 0)\n\n dst += c->width * 3;\n\n dst += 4;\n\n } while (i < c->video_size / 16);\n\n\n\n opcode_size = bytestream2_get_le16(&c->gb);\n\n bytestream2_skip(&c->gb, 2);\n\n\n\n if (bytestream2_get_bytes_left(&c->gb) < opcode_size)\n\n return AVERROR_INVALIDDATA;\n\n\n\n opcodes = pkt + bytestream2_tell(&c->gb);\n\n bytestream2_skipu(&c->gb, opcode_size);\n\n\n\n dst = c->frame[c->current_frame];\n\n\n\n for (i = 0; i < c->height; i += 4, dst += c->width * 3)\n\n for (j = 0; j < c->width; j += 4, dst += 4) {\n\n int opcode, k = 0;\n\n if (op > opcode_size)\n\n return AVERROR_INVALIDDATA;\n\n if (j & 4) {\n\n opcode = opcodes[op] & 15;\n\n op++;\n\n } else {\n\n opcode = opcodes[op] >> 4;\n\n }\n\n\n\n while (block_sequences[opcode][k]) {\n\n offset = c->width * 2;\n\n code = block_sequences[opcode][k++];\n\n\n\n switch (code) {\n\n case 2:\n\n offset = 0;\n\n case 3:\n\n color = bytestream2_get_byte(&c->gb);\n\n case 4:\n\n mask = bytestream2_get_byte(&c->gb);\n\n copy_color_mask(dst + offset, c->width, mask, color);\n\n break;\n\n case 5:\n\n offset = 0;\n\n case 6:\n\n set_src_position(c, &src, &send);\n\n case 7:\n\n if (src + offset + c->width + 4 > send)\n\n return AVERROR_INVALIDDATA;\n\n mask = bytestream2_get_byte(&c->gb);\n\n copy_src_mask(dst + offset, c->width, mask, src + offset);\n\n break;\n\n }\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "1", + "index": 16614 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static av_cold int flashsv2_encode_init(AVCodecContext * avctx)\n\n{\n\n FlashSV2Context *s = avctx->priv_data;\n\n\n\n s->avctx = avctx;\n\n\n\n s->comp = avctx->compression_level;\n\n if (s->comp == -1)\n\n s->comp = 9;\n\n if (s->comp < 0 || s->comp > 9) {\n\n\n \"Compression level should be 0-9, not %d\\n\", s->comp);\n\n\n\n\n\n\n\n if ((avctx->width > 4095) || (avctx->height > 4095)) {\n\n\n \"Input dimensions too large, input must be max 4096x4096 !\\n\");\n\n\n\n\n\n\n\n\n\n\n if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0)\n\n\n\n\n\n\n s->last_key_frame = 0;\n\n\n\n s->image_width = avctx->width;\n\n s->image_height = avctx->height;\n\n\n\n s->block_width = (s->image_width / 12) & ~15;\n\n s->block_height = (s->image_height / 12) & ~15;\n\n\n\n if(!s->block_width)\n\n s->block_width = 1;\n\n if(!s->block_height)\n\n s->block_height = 1;\n\n\n\n s->rows = (s->image_height + s->block_height - 1) / s->block_height;\n\n s->cols = (s->image_width + s->block_width - 1) / s->block_width;\n\n\n\n s->frame_size = s->image_width * s->image_height * 3;\n\n s->blocks_size = s->rows * s->cols * sizeof(Block);\n\n\n\n s->encbuffer = av_mallocz(s->frame_size);\n\n s->keybuffer = av_mallocz(s->frame_size);\n\n s->databuffer = av_mallocz(s->frame_size * 6);\n\n s->current_frame = av_mallocz(s->frame_size);\n\n s->key_frame = av_mallocz(s->frame_size);\n\n s->frame_blocks = av_mallocz(s->blocks_size);\n\n s->key_blocks = av_mallocz(s->blocks_size);\n\n\n\n init_blocks(s, s->frame_blocks, s->encbuffer, s->databuffer);\n\n init_blocks(s, s->key_blocks, s->keybuffer, 0);\n\n reset_stats(s);\n\n#ifndef FLASHSV2_DUMB\n\n s->total_bits = 1;\n\n#endif\n\n\n\n s->use_custom_palette = 0;\n\n s->palette_type = -1; // so that the palette will be generated in reconfigure_at_keyframe\n\n\n\n if (!s->encbuffer || !s->keybuffer || !s->databuffer\n\n || !s->current_frame || !s->key_frame || !s->key_blocks\n\n || !s->frame_blocks) {\n\n av_log(avctx, AV_LOG_ERROR, \"Memory allocation failed.\\n\");\n\n cleanup(s);\n\n\n\n\n\n return 0;\n", + "output": "1", + "index": 17562 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count,\n\n const uint8_t *in_arg [SWR_CH_MAX], int in_count){\n\n AudioData * in= &s->in;\n\n AudioData *out= &s->out;\n\n\n\n if (!swr_is_initialized(s)) {\n\n av_log(s, AV_LOG_ERROR, \"Context has not been initialized\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n while(s->drop_output > 0){\n\n int ret;\n\n uint8_t *tmp_arg[SWR_CH_MAX];\n\n#define MAX_DROP_STEP 16384\n\n if((ret=swri_realloc_audio(&s->drop_temp, FFMIN(s->drop_output, MAX_DROP_STEP)))<0)\n\n return ret;\n\n\n\n reversefill_audiodata(&s->drop_temp, tmp_arg);\n\n s->drop_output *= -1; //FIXME find a less hackish solution\n\n ret = swr_convert(s, tmp_arg, FFMIN(-s->drop_output, MAX_DROP_STEP), in_arg, in_count); //FIXME optimize but this is as good as never called so maybe it doesn't matter\n\n s->drop_output *= -1;\n\n in_count = 0;\n\n if(ret>0) {\n\n s->drop_output -= ret;\n\n if (!s->drop_output && !out_arg)\n\n return 0;\n\n continue;\n\n }\n\n\n\n av_assert0(s->drop_output);\n\n return 0;\n\n }\n\n\n\n if(!in_arg){\n\n if(s->resample){\n\n if (!s->flushed)\n\n s->resampler->flush(s);\n\n s->resample_in_constraint = 0;\n\n s->flushed = 1;\n\n }else if(!s->in_buffer_count){\n\n return 0;\n\n }\n\n }else\n\n fill_audiodata(in , (void*)in_arg);\n\n\n\n fill_audiodata(out, out_arg);\n\n\n\n if(s->resample){\n\n int ret = swr_convert_internal(s, out, out_count, in, in_count);\n\n if(ret>0 && !s->drop_output)\n\n s->outpts += ret * (int64_t)s->in_sample_rate;\n\n return ret;\n\n }else{\n\n AudioData tmp= *in;\n\n int ret2=0;\n\n int ret, size;\n\n size = FFMIN(out_count, s->in_buffer_count);\n\n if(size){\n\n buf_set(&tmp, &s->in_buffer, s->in_buffer_index);\n\n ret= swr_convert_internal(s, out, size, &tmp, size);\n\n if(ret<0)\n\n return ret;\n\n ret2= ret;\n\n s->in_buffer_count -= ret;\n\n s->in_buffer_index += ret;\n\n buf_set(out, out, ret);\n\n out_count -= ret;\n\n if(!s->in_buffer_count)\n\n s->in_buffer_index = 0;\n\n }\n\n\n\n if(in_count){\n\n size= s->in_buffer_index + s->in_buffer_count + in_count - out_count;\n\n\n\n if(in_count > out_count) { //FIXME move after swr_convert_internal\n\n if( size > s->in_buffer.count\n\n && s->in_buffer_count + in_count - out_count <= s->in_buffer_index){\n\n buf_set(&tmp, &s->in_buffer, s->in_buffer_index);\n\n copy(&s->in_buffer, &tmp, s->in_buffer_count);\n\n s->in_buffer_index=0;\n\n }else\n\n if((ret=swri_realloc_audio(&s->in_buffer, size)) < 0)\n\n return ret;\n\n }\n\n\n\n if(out_count){\n\n size = FFMIN(in_count, out_count);\n\n ret= swr_convert_internal(s, out, size, in, size);\n\n if(ret<0)\n\n return ret;\n\n buf_set(in, in, ret);\n\n in_count -= ret;\n\n ret2 += ret;\n\n }\n\n if(in_count){\n\n buf_set(&tmp, &s->in_buffer, s->in_buffer_index + s->in_buffer_count);\n\n copy(&tmp, in, in_count);\n\n s->in_buffer_count += in_count;\n\n }\n\n }\n\n if(ret2>0 && !s->drop_output)\n\n s->outpts += ret2 * (int64_t)s->in_sample_rate;\n\n return ret2;\n\n }\n\n}\n", + "output": "1", + "index": 2969 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int decode_frame(AVCodecContext *avctx,\n\n void *data, int *data_size,\n\n AVPacket *avpkt)\n\n{\n\n const uint8_t *buf = avpkt->data;\n\n int buf_size = avpkt->size;\n\n H264Context *h = avctx->priv_data;\n\n MpegEncContext *s = &h->s;\n\n AVFrame *pict = data;\n\n int buf_index;\n\n\n\n s->flags= avctx->flags;\n\n s->flags2= avctx->flags2;\n\n\n\n /* end of stream, output what is still in the buffers */\n\n out:\n\n if (buf_size == 0) {\n\n Picture *out;\n\n int i, out_idx;\n\n\n\n s->current_picture_ptr = NULL;\n\n\n\n//FIXME factorize this with the output code below\n\n out = h->delayed_pic[0];\n\n out_idx = 0;\n\n for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame && !h->delayed_pic[i]->mmco_reset; i++)\n\n if(h->delayed_pic[i]->poc < out->poc){\n\n out = h->delayed_pic[i];\n\n out_idx = i;\n\n }\n\n\n\n for(i=out_idx; h->delayed_pic[i]; i++)\n\n h->delayed_pic[i] = h->delayed_pic[i+1];\n\n\n\n if(out){\n\n *data_size = sizeof(AVFrame);\n\n *pict= *(AVFrame*)out;\n\n }\n\n\n\n return 0;\n\n }\n\n\n\n buf_index=decode_nal_units(h, buf, buf_size);\n\n if(buf_index < 0)\n\n return -1;\n\n\n\n if (!s->current_picture_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {\n\n buf_size = 0;\n\n goto out;\n\n }\n\n\n\n if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){\n\n if (avctx->skip_frame >= AVDISCARD_NONREF)\n\n return 0;\n\n av_log(avctx, AV_LOG_ERROR, \"no frame!\\n\");\n\n return -1;\n\n }\n\n\n\n if(!(s->flags2 & CODEC_FLAG2_CHUNKS) || (s->mb_y >= s->mb_height && s->mb_height)){\n\n\n\n if(s->flags2 & CODEC_FLAG2_CHUNKS) decode_postinit(h);\n\n\n\n field_end(h, 0);\n\n\n\n if (!h->next_output_pic) {\n\n /* Wait for second field. */\n\n *data_size = 0;\n\n\n\n } else {\n\n *data_size = sizeof(AVFrame);\n\n *pict = *(AVFrame*)h->next_output_pic;\n\n }\n\n }\n\n\n\n assert(pict->data[0] || !*data_size);\n\n ff_print_debug_info(s, pict);\n\n//printf(\"out %d\\n\", (int)pict->data[0]);\n\n\n\n return get_consumed_bytes(s, buf_index, buf_size);\n\n}\n", + "output": "1", + "index": 5712 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int64_t load_kernel (CPUMIPSState *env)\n\n{\n\n int64_t kernel_entry, kernel_low, kernel_high;\n\n int index = 0;\n\n long initrd_size;\n\n ram_addr_t initrd_offset;\n\n uint32_t *prom_buf;\n\n long prom_size;\n\n\n\n if (load_elf(loaderparams.kernel_filename, cpu_mips_kseg0_to_phys, NULL,\n\n (uint64_t *)&kernel_entry, (uint64_t *)&kernel_low,\n\n (uint64_t *)&kernel_high, 0, ELF_MACHINE, 1) < 0) {\n\n fprintf(stderr, \"qemu: could not load kernel '%s'\\n\",\n\n loaderparams.kernel_filename);\n\n exit(1);\n\n }\n\n\n\n /* load initrd */\n\n initrd_size = 0;\n\n initrd_offset = 0;\n\n if (loaderparams.initrd_filename) {\n\n initrd_size = get_image_size (loaderparams.initrd_filename);\n\n if (initrd_size > 0) {\n\n initrd_offset = (kernel_high + ~INITRD_PAGE_MASK) & INITRD_PAGE_MASK;\n\n if (initrd_offset + initrd_size > ram_size) {\n\n fprintf(stderr,\n\n \"qemu: memory too small for initial ram disk '%s'\\n\",\n\n loaderparams.initrd_filename);\n\n exit(1);\n\n }\n\n initrd_size = load_image_targphys(loaderparams.initrd_filename,\n\n initrd_offset, ram_size - initrd_offset);\n\n }\n\n if (initrd_size == (target_ulong) -1) {\n\n fprintf(stderr, \"qemu: could not load initial ram disk '%s'\\n\",\n\n loaderparams.initrd_filename);\n\n exit(1);\n\n }\n\n }\n\n\n\n /* Setup prom parameters. */\n\n prom_size = ENVP_NB_ENTRIES * (sizeof(int32_t) + ENVP_ENTRY_SIZE);\n\n prom_buf = g_malloc(prom_size);\n\n\n\n prom_set(prom_buf, index++, \"%s\", loaderparams.kernel_filename);\n\n if (initrd_size > 0) {\n\n prom_set(prom_buf, index++, \"rd_start=0x%\" PRIx64 \" rd_size=%li %s\",\n\n cpu_mips_phys_to_kseg0(NULL, initrd_offset), initrd_size,\n\n loaderparams.kernel_cmdline);\n\n } else {\n\n prom_set(prom_buf, index++, \"%s\", loaderparams.kernel_cmdline);\n\n }\n\n\n\n /* Setup minimum environment variables */\n\n prom_set(prom_buf, index++, \"busclock=33000000\");\n\n prom_set(prom_buf, index++, \"cpuclock=100000000\");\n\n prom_set(prom_buf, index++, \"memsize=%i\", loaderparams.ram_size/1024/1024);\n\n prom_set(prom_buf, index++, \"modetty0=38400n8r\");\n\n prom_set(prom_buf, index++, NULL);\n\n\n\n rom_add_blob_fixed(\"prom\", prom_buf, prom_size,\n\n cpu_mips_kseg0_to_phys(NULL, ENVP_ADDR));\n\n\n\n\n return kernel_entry;\n\n}", + "output": "1", + "index": 3725 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_h264_decode_ref_pic_list_reordering(H264Context *h)\n\n{\n\n int list, index, pic_structure, i;\n\n\n\n print_short_term(h);\n\n print_long_term(h);\n\n\n\n for (list = 0; list < h->list_count; list++) {\n\n for (i = 0; i < h->ref_count[list]; i++)\n\n COPY_PICTURE(&h->ref_list[list][i], &h->default_ref_list[list][i]);\n\n\n\n if (get_bits1(&h->gb)) {\n\n int pred = h->curr_pic_num;\n\n\n\n for (index = 0; ; index++) {\n\n unsigned int reordering_of_pic_nums_idc = get_ue_golomb_31(&h->gb);\n\n unsigned int pic_id;\n\n int i;\n\n Picture *ref = NULL;\n\n\n\n if (reordering_of_pic_nums_idc == 3)\n\n break;\n\n\n\n if (index >= h->ref_count[list]) {\n\n av_log(h->avctx, AV_LOG_ERROR, \"reference count overflow\\n\");\n\n return -1;\n\n }\n\n\n\n if (reordering_of_pic_nums_idc < 3) {\n\n if (reordering_of_pic_nums_idc < 2) {\n\n const unsigned int abs_diff_pic_num = get_ue_golomb(&h->gb) + 1;\n\n int frame_num;\n\n\n\n if (abs_diff_pic_num > h->max_pic_num) {\n\n av_log(h->avctx, AV_LOG_ERROR, \"abs_diff_pic_num overflow\\n\");\n\n return -1;\n\n }\n\n\n\n if (reordering_of_pic_nums_idc == 0)\n\n pred -= abs_diff_pic_num;\n\n else\n\n pred += abs_diff_pic_num;\n\n pred &= h->max_pic_num - 1;\n\n\n\n frame_num = pic_num_extract(h, pred, &pic_structure);\n\n\n\n for (i = h->short_ref_count - 1; i >= 0; i--) {\n\n ref = h->short_ref[i];\n\n assert(ref->reference);\n\n assert(!ref->long_ref);\n\n if (ref->frame_num == frame_num &&\n\n (ref->reference & pic_structure))\n\n break;\n\n }\n\n if (i >= 0)\n\n ref->pic_id = pred;\n\n } else {\n\n int long_idx;\n\n pic_id = get_ue_golomb(&h->gb); //long_term_pic_idx\n\n\n\n long_idx = pic_num_extract(h, pic_id, &pic_structure);\n\n\n\n if (long_idx > 31) {\n\n av_log(h->avctx, AV_LOG_ERROR, \"long_term_pic_idx overflow\\n\");\n\n return -1;\n\n }\n\n ref = h->long_ref[long_idx];\n\n assert(!(ref && !ref->reference));\n\n if (ref && (ref->reference & pic_structure)) {\n\n ref->pic_id = pic_id;\n\n assert(ref->long_ref);\n\n i = 0;\n\n } else {\n\n i = -1;\n\n }\n\n }\n\n\n\n if (i < 0) {\n\n av_log(h->avctx, AV_LOG_ERROR, \"reference picture missing during reorder\\n\");\n\n memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME\n\n } else {\n\n for (i = index; i + 1 < h->ref_count[list]; i++) {\n\n if (ref->long_ref == h->ref_list[list][i].long_ref &&\n\n ref->pic_id == h->ref_list[list][i].pic_id)\n\n break;\n\n }\n\n for (; i > index; i--) {\n\n COPY_PICTURE(&h->ref_list[list][i], &h->ref_list[list][i - 1]);\n\n }\n\n COPY_PICTURE(&h->ref_list[list][index], ref);\n\n if (FIELD_PICTURE(h)) {\n\n pic_as_field(&h->ref_list[list][index], pic_structure);\n\n }\n\n }\n\n } else {\n\n av_log(h->avctx, AV_LOG_ERROR, \"illegal reordering_of_pic_nums_idc\\n\");\n\n return -1;\n\n }\n\n }\n\n }\n\n }\n\n for (list = 0; list < h->list_count; list++) {\n\n for (index = 0; index < h->ref_count[list]; index++) {\n\n if (!h->ref_list[list][index].f.data[0]) {\n\n av_log(h->avctx, AV_LOG_ERROR, \"Missing reference picture\\n\");\n\n if (h->default_ref_list[list][0].f.data[0])\n\n COPY_PICTURE(&h->ref_list[list][index], &h->default_ref_list[list][0]);\n\n else\n\n return -1;\n\n }\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 8309 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int kvm_arch_get_registers(CPUState *cs)\n\n{\n\n S390CPU *cpu = S390_CPU(cs);\n\n CPUS390XState *env = &cpu->env;\n\n struct kvm_one_reg reg;\n\n struct kvm_sregs sregs;\n\n struct kvm_regs regs;\n\n int i, r;\n\n\n\n /* get the PSW */\n\n env->psw.addr = cs->kvm_run->psw_addr;\n\n env->psw.mask = cs->kvm_run->psw_mask;\n\n\n\n /* the GPRS */\n\n if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_GPRS) {\n\n for (i = 0; i < 16; i++) {\n\n env->regs[i] = cs->kvm_run->s.regs.gprs[i];\n\n }\n\n } else {\n\n r = kvm_vcpu_ioctl(cs, KVM_GET_REGS, ®s);\n\n if (r < 0) {\n\n return r;\n\n }\n\n for (i = 0; i < 16; i++) {\n\n env->regs[i] = regs.gprs[i];\n\n }\n\n }\n\n\n\n /* The ACRS and CRS */\n\n if (cap_sync_regs &&\n\n cs->kvm_run->kvm_valid_regs & KVM_SYNC_ACRS &&\n\n cs->kvm_run->kvm_valid_regs & KVM_SYNC_CRS) {\n\n for (i = 0; i < 16; i++) {\n\n env->aregs[i] = cs->kvm_run->s.regs.acrs[i];\n\n env->cregs[i] = cs->kvm_run->s.regs.crs[i];\n\n }\n\n } else {\n\n r = kvm_vcpu_ioctl(cs, KVM_GET_SREGS, &sregs);\n\n if (r < 0) {\n\n return r;\n\n }\n\n for (i = 0; i < 16; i++) {\n\n env->aregs[i] = sregs.acrs[i];\n\n env->cregs[i] = sregs.crs[i];\n\n }\n\n }\n\n\n\n /* The prefix */\n\n if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_PREFIX) {\n\n env->psa = cs->kvm_run->s.regs.prefix;\n\n }\n\n\n\n /* One Regs */\n\n reg.id = KVM_REG_S390_CPU_TIMER;\n\n reg.addr = (__u64)&(env->cputm);\n\n r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);\n\n if (r < 0) {\n\n return r;\n\n }\n\n\n\n reg.id = KVM_REG_S390_CLOCK_COMP;\n\n reg.addr = (__u64)&(env->ckc);\n\n r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);\n\n if (r < 0) {\n\n return r;\n\n }\n\n\n\n reg.id = KVM_REG_S390_TODPR;\n\n reg.addr = (__u64)&(env->todpr);\n\n r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);\n\n if (r < 0) {\n\n return r;\n\n }\n\n\n\n if (cap_async_pf) {\n\n reg.id = KVM_REG_S390_PFTOKEN;\n\n reg.addr = (__u64)&(env->pfault_token);\n\n r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);\n\n if (r < 0) {\n\n return r;\n\n }\n\n\n\n reg.id = KVM_REG_S390_PFCOMPARE;\n\n reg.addr = (__u64)&(env->pfault_compare);\n\n r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);\n\n if (r < 0) {\n\n return r;\n\n }\n\n\n\n reg.id = KVM_REG_S390_PFSELECT;\n\n reg.addr = (__u64)&(env->pfault_select);\n\n r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);\n\n if (r < 0) {\n\n return r;\n\n }\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 18344 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int vnc_validate_certificate(struct VncState *vs)\n\n{\n\n int ret;\n\n unsigned int status;\n\n const gnutls_datum_t *certs;\n\n unsigned int nCerts, i;\n\n time_t now;\n\n\n\n VNC_DEBUG(\"Validating client certificate\\n\");\n\n if ((ret = gnutls_certificate_verify_peers2 (vs->tls_session, &status)) < 0) {\n\n\tVNC_DEBUG(\"Verify failed %s\\n\", gnutls_strerror(ret));\n\n\treturn -1;\n\n }\n\n\n\n if ((now = time(NULL)) == ((time_t)-1)) {\n\n\treturn -1;\n\n }\n\n\n\n if (status != 0) {\n\n\tif (status & GNUTLS_CERT_INVALID)\n\n\t VNC_DEBUG(\"The certificate is not trusted.\\n\");\n\n\n\n\tif (status & GNUTLS_CERT_SIGNER_NOT_FOUND)\n\n\t VNC_DEBUG(\"The certificate hasn't got a known issuer.\\n\");\n\n\n\n\tif (status & GNUTLS_CERT_REVOKED)\n\n\t VNC_DEBUG(\"The certificate has been revoked.\\n\");\n\n\n\n\tif (status & GNUTLS_CERT_INSECURE_ALGORITHM)\n\n\t VNC_DEBUG(\"The certificate uses an insecure algorithm\\n\");\n\n\n\n\treturn -1;\n\n } else {\n\n\tVNC_DEBUG(\"Certificate is valid!\\n\");\n\n }\n\n\n\n /* Only support x509 for now */\n\n if (gnutls_certificate_type_get(vs->tls_session) != GNUTLS_CRT_X509)\n\n\treturn -1;\n\n\n\n if (!(certs = gnutls_certificate_get_peers(vs->tls_session, &nCerts)))\n\n\treturn -1;\n\n\n\n for (i = 0 ; i < nCerts ; i++) {\n\n\tgnutls_x509_crt_t cert;\n\n\tVNC_DEBUG (\"Checking certificate chain %d\\n\", i);\n\n\tif (gnutls_x509_crt_init (&cert) < 0)\n\n\t return -1;\n\n\n\n\tif (gnutls_x509_crt_import(cert, &certs[i], GNUTLS_X509_FMT_DER) < 0) {\n\n\t gnutls_x509_crt_deinit (cert);\n\n\t return -1;\n\n\t}\n\n\n\n\tif (gnutls_x509_crt_get_expiration_time (cert) < now) {\n\n\t VNC_DEBUG(\"The certificate has expired\\n\");\n\n\t gnutls_x509_crt_deinit (cert);\n\n\t return -1;\n\n\t}\n\n\n\n\tif (gnutls_x509_crt_get_activation_time (cert) > now) {\n\n\t VNC_DEBUG(\"The certificate is not yet activated\\n\");\n\n\t gnutls_x509_crt_deinit (cert);\n\n\t return -1;\n\n\t}\n\n\n\n\tif (gnutls_x509_crt_get_activation_time (cert) > now) {\n\n\t VNC_DEBUG(\"The certificate is not yet activated\\n\");\n\n\t gnutls_x509_crt_deinit (cert);\n\n\t return -1;\n\n\t}\n\n\n\n\tgnutls_x509_crt_deinit (cert);\n\n }\n\n\n\n return 0;\n\n}\n", + "output": "0", + "index": 6243 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void set_pixel_format(VncState *vs,\n\n\t\t\t int bits_per_pixel, int depth,\n\n\t\t\t int big_endian_flag, int true_color_flag,\n\n\t\t\t int red_max, int green_max, int blue_max,\n\n\t\t\t int red_shift, int green_shift, int blue_shift)\n\n{\n\n int host_big_endian_flag;\n\n\n\n#ifdef WORDS_BIGENDIAN\n\n host_big_endian_flag = 1;\n\n#else\n\n host_big_endian_flag = 0;\n\n#endif\n\n if (!true_color_flag) {\n\n fail:\n\n\tvnc_client_error(vs);\n\n return;\n\n }\n\n if (bits_per_pixel == 32 &&\n\n bits_per_pixel == vs->depth * 8 &&\n\n host_big_endian_flag == big_endian_flag &&\n\n red_max == 0xff && green_max == 0xff && blue_max == 0xff &&\n\n red_shift == 16 && green_shift == 8 && blue_shift == 0) {\n\n vs->depth = 4;\n\n vs->write_pixels = vnc_write_pixels_copy;\n\n vs->send_hextile_tile = send_hextile_tile_32;\n\n } else\n\n if (bits_per_pixel == 16 &&\n\n bits_per_pixel == vs->depth * 8 && \n\n host_big_endian_flag == big_endian_flag &&\n\n red_max == 31 && green_max == 63 && blue_max == 31 &&\n\n red_shift == 11 && green_shift == 5 && blue_shift == 0) {\n\n vs->depth = 2;\n\n vs->write_pixels = vnc_write_pixels_copy;\n\n vs->send_hextile_tile = send_hextile_tile_16;\n\n } else\n\n if (bits_per_pixel == 8 &&\n\n bits_per_pixel == vs->depth * 8 &&\n\n red_max == 7 && green_max == 7 && blue_max == 3 &&\n\n red_shift == 5 && green_shift == 2 && blue_shift == 0) {\n\n vs->depth = 1;\n\n vs->write_pixels = vnc_write_pixels_copy;\n\n vs->send_hextile_tile = send_hextile_tile_8;\n\n } else\n\n {\n\n /* generic and slower case */\n\n if (bits_per_pixel != 8 &&\n\n bits_per_pixel != 16 &&\n\n bits_per_pixel != 32)\n\n goto fail;\n\n if (vs->depth == 4) {\n\n vs->send_hextile_tile = send_hextile_tile_generic_32;\n\n } else if (vs->depth == 2) {\n\n vs->send_hextile_tile = send_hextile_tile_generic_16;\n\n } else {\n\n vs->send_hextile_tile = send_hextile_tile_generic_8;\n\n }\n\n\n\n vs->pix_big_endian = big_endian_flag;\n\n vs->write_pixels = vnc_write_pixels_generic;\n\n }\n\n\n\n vs->client_red_shift = red_shift;\n\n vs->client_red_max = red_max;\n\n vs->client_green_shift = green_shift;\n\n vs->client_green_max = green_max;\n\n vs->client_blue_shift = blue_shift;\n\n vs->client_blue_max = blue_max;\n\n vs->pix_bpp = bits_per_pixel / 8;\n\n\n\n vga_hw_invalidate();\n\n vga_hw_update();\n\n}\n", + "output": "1", + "index": 21906 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int sd_create(const char *filename, QEMUOptionParameter *options,\n\n Error **errp)\n\n{\n\n int ret = 0;\n\n uint32_t vid = 0;\n\n char *backing_file = NULL;\n\n BDRVSheepdogState *s;\n\n char tag[SD_MAX_VDI_TAG_LEN];\n\n uint32_t snapid;\n\n bool prealloc = false;\n\n Error *local_err = NULL;\n\n\n\n s = g_malloc0(sizeof(BDRVSheepdogState));\n\n\n\n memset(tag, 0, sizeof(tag));\n\n if (strstr(filename, \"://\")) {\n\n ret = sd_parse_uri(s, filename, s->name, &snapid, tag);\n\n } else {\n\n ret = parse_vdiname(s, filename, s->name, &snapid, tag);\n\n }\n\n if (ret < 0) {\n\n goto out;\n\n }\n\n\n\n while (options && options->name) {\n\n if (!strcmp(options->name, BLOCK_OPT_SIZE)) {\n\n s->inode.vdi_size = options->value.n;\n\n } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {\n\n backing_file = options->value.s;\n\n } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {\n\n if (!options->value.s || !strcmp(options->value.s, \"off\")) {\n\n prealloc = false;\n\n } else if (!strcmp(options->value.s, \"full\")) {\n\n prealloc = true;\n\n } else {\n\n error_report(\"Invalid preallocation mode: '%s'\",\n\n options->value.s);\n\n ret = -EINVAL;\n\n goto out;\n\n }\n\n } else if (!strcmp(options->name, BLOCK_OPT_REDUNDANCY)) {\n\n ret = parse_redundancy(s, options->value.s);\n\n if (ret < 0) {\n\n goto out;\n\n }\n\n }\n\n options++;\n\n }\n\n\n\n if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {\n\n error_report(\"too big image size\");\n\n ret = -EINVAL;\n\n goto out;\n\n }\n\n\n\n if (backing_file) {\n\n BlockDriverState *bs;\n\n BDRVSheepdogState *s;\n\n BlockDriver *drv;\n\n\n\n /* Currently, only Sheepdog backing image is supported. */\n\n drv = bdrv_find_protocol(backing_file, true);\n\n if (!drv || strcmp(drv->protocol_name, \"sheepdog\") != 0) {\n\n error_report(\"backing_file must be a sheepdog image\");\n\n ret = -EINVAL;\n\n goto out;\n\n }\n\n\n\n ret = bdrv_file_open(&bs, backing_file, NULL, 0, &local_err);\n\n if (ret < 0) {\n\n qerror_report_err(local_err);\n\n error_free(local_err);\n\n goto out;\n\n }\n\n\n\n s = bs->opaque;\n\n\n\n if (!is_snapshot(&s->inode)) {\n\n error_report(\"cannot clone from a non snapshot vdi\");\n\n bdrv_unref(bs);\n\n ret = -EINVAL;\n\n goto out;\n\n }\n\n\n\n bdrv_unref(bs);\n\n }\n\n\n\n ret = do_sd_create(s, &vid, 0);\n\n if (!prealloc || ret) {\n\n goto out;\n\n }\n\n\n\n ret = sd_prealloc(filename);\n\nout:\n\n g_free(s);\n\n return ret;\n\n}\n", + "output": "0", + "index": 8394 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static always_inline void fload_invalid_op_excp (int op)\n\n{\n\n int ve;\n\n\n\n ve = fpscr_ve;\n\n if (op & POWERPC_EXCP_FP_VXSNAN) {\n\n /* Operation on signaling NaN */\n\n env->fpscr |= 1 << FPSCR_VXSNAN;\n\n }\n\n if (op & POWERPC_EXCP_FP_VXSOFT) {\n\n /* Software-defined condition */\n\n env->fpscr |= 1 << FPSCR_VXSOFT;\n\n }\n\n switch (op & ~(POWERPC_EXCP_FP_VXSOFT | POWERPC_EXCP_FP_VXSNAN)) {\n\n case POWERPC_EXCP_FP_VXISI:\n\n /* Magnitude subtraction of infinities */\n\n env->fpscr |= 1 << FPSCR_VXISI;\n\n goto update_arith;\n\n case POWERPC_EXCP_FP_VXIDI:\n\n /* Division of infinity by infinity */\n\n env->fpscr |= 1 << FPSCR_VXIDI;\n\n goto update_arith;\n\n case POWERPC_EXCP_FP_VXZDZ:\n\n /* Division of zero by zero */\n\n env->fpscr |= 1 << FPSCR_VXZDZ;\n\n goto update_arith;\n\n case POWERPC_EXCP_FP_VXIMZ:\n\n /* Multiplication of zero by infinity */\n\n env->fpscr |= 1 << FPSCR_VXIMZ;\n\n goto update_arith;\n\n case POWERPC_EXCP_FP_VXVC:\n\n /* Ordered comparison of NaN */\n\n env->fpscr |= 1 << FPSCR_VXVC;\n\n env->fpscr &= ~(0xF << FPSCR_FPCC);\n\n env->fpscr |= 0x11 << FPSCR_FPCC;\n\n /* We must update the target FPR before raising the exception */\n\n if (ve != 0) {\n\n env->exception_index = POWERPC_EXCP_PROGRAM;\n\n env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_VXVC;\n\n /* Update the floating-point enabled exception summary */\n\n env->fpscr |= 1 << FPSCR_FEX;\n\n /* Exception is differed */\n\n ve = 0;\n\n }\n\n break;\n\n case POWERPC_EXCP_FP_VXSQRT:\n\n /* Square root of a negative number */\n\n env->fpscr |= 1 << FPSCR_VXSQRT;\n\n update_arith:\n\n env->fpscr &= ~((1 << FPSCR_FR) | (1 << FPSCR_FI));\n\n if (ve == 0) {\n\n /* Set the result to quiet NaN */\n\n FT0 = (uint64_t)-1;\n\n env->fpscr &= ~(0xF << FPSCR_FPCC);\n\n env->fpscr |= 0x11 << FPSCR_FPCC;\n\n }\n\n break;\n\n case POWERPC_EXCP_FP_VXCVI:\n\n /* Invalid conversion */\n\n env->fpscr |= 1 << FPSCR_VXCVI;\n\n env->fpscr &= ~((1 << FPSCR_FR) | (1 << FPSCR_FI));\n\n if (ve == 0) {\n\n /* Set the result to quiet NaN */\n\n FT0 = (uint64_t)-1;\n\n env->fpscr &= ~(0xF << FPSCR_FPCC);\n\n env->fpscr |= 0x11 << FPSCR_FPCC;\n\n }\n\n break;\n\n }\n\n /* Update the floating-point invalid operation summary */\n\n env->fpscr |= 1 << FPSCR_VX;\n\n /* Update the floating-point exception summary */\n\n env->fpscr |= 1 << FPSCR_FX;\n\n if (ve != 0) {\n\n /* Update the floating-point enabled exception summary */\n\n env->fpscr |= 1 << FPSCR_FEX;\n\n if (msr_fe0 != 0 || msr_fe1 != 0)\n\n do_raise_exception_err(POWERPC_EXCP_PROGRAM, POWERPC_EXCP_FP | op);\n\n }\n\n}\n", + "output": "1", + "index": 6456 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void ppc_tlb_invalidate_one(CPUPPCState *env, target_ulong addr)\n\n{\n\n#if !defined(FLUSH_ALL_TLBS)\n\n PowerPCCPU *cpu = ppc_env_get_cpu(env);\n\n CPUState *cs;\n\n\n\n addr &= TARGET_PAGE_MASK;\n\n switch (env->mmu_model) {\n\n case POWERPC_MMU_SOFT_6xx:\n\n case POWERPC_MMU_SOFT_74xx:\n\n ppc6xx_tlb_invalidate_virt(env, addr, 0);\n\n if (env->id_tlbs == 1) {\n\n ppc6xx_tlb_invalidate_virt(env, addr, 1);\n\n }\n\n break;\n\n case POWERPC_MMU_32B:\n\n case POWERPC_MMU_601:\n\n /* tlbie invalidate TLBs for all segments */\n\n addr &= ~((target_ulong)-1ULL << 28);\n\n cs = CPU(cpu);\n\n /* XXX: this case should be optimized,\n\n * giving a mask to tlb_flush_page\n\n */\n\n /* This is broken, some CPUs invalidate a whole congruence\n\n * class on an even smaller subset of bits and some OSes take\n\n * advantage of this. Just blow the whole thing away.\n\n */\n\n#if 0\n\n tlb_flush_page(cs, addr | (0x0 << 28));\n\n tlb_flush_page(cs, addr | (0x1 << 28));\n\n tlb_flush_page(cs, addr | (0x2 << 28));\n\n tlb_flush_page(cs, addr | (0x3 << 28));\n\n tlb_flush_page(cs, addr | (0x4 << 28));\n\n tlb_flush_page(cs, addr | (0x5 << 28));\n\n tlb_flush_page(cs, addr | (0x6 << 28));\n\n tlb_flush_page(cs, addr | (0x7 << 28));\n\n tlb_flush_page(cs, addr | (0x8 << 28));\n\n tlb_flush_page(cs, addr | (0x9 << 28));\n\n tlb_flush_page(cs, addr | (0xA << 28));\n\n tlb_flush_page(cs, addr | (0xB << 28));\n\n tlb_flush_page(cs, addr | (0xC << 28));\n\n tlb_flush_page(cs, addr | (0xD << 28));\n\n tlb_flush_page(cs, addr | (0xE << 28));\n\n tlb_flush_page(cs, addr | (0xF << 28));\n\n\n\n\n break;\n\n#if defined(TARGET_PPC64)\n\n case POWERPC_MMU_64B:\n\n case POWERPC_MMU_2_03:\n\n case POWERPC_MMU_2_06:\n\n case POWERPC_MMU_2_06a:\n\n case POWERPC_MMU_2_07:\n\n case POWERPC_MMU_2_07a:\n\n /* tlbie invalidate TLBs for all segments */\n\n /* XXX: given the fact that there are too many segments to invalidate,\n\n * and we still don't have a tlb_flush_mask(env, n, mask) in QEMU,\n\n * we just invalidate all TLBs\n\n */\n\n env->tlb_need_flush = 1;\n\n break;\n\n#endif /* defined(TARGET_PPC64) */\n\n default:\n\n /* Should never reach here with other MMU models */\n\n assert(0);\n\n }\n\n\n ppc_tlb_invalidate_all(env);\n\n\n}", + "output": "1", + "index": 24663 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static CCPrepare gen_prepare_cc(DisasContext *s, int b, TCGv reg)\n\n{\n\n int inv, jcc_op, size, cond;\n\n CCPrepare cc;\n\n TCGv t0;\n\n\n\n inv = b & 1;\n\n jcc_op = (b >> 1) & 7;\n\n\n\n switch (s->cc_op) {\n\n case CC_OP_SUBB ... CC_OP_SUBQ:\n\n /* We optimize relational operators for the cmp/jcc case. */\n\n size = s->cc_op - CC_OP_SUBB;\n\n switch (jcc_op) {\n\n case JCC_BE:\n\n tcg_gen_add_tl(cpu_tmp4, cpu_cc_dst, cpu_cc_src);\n\n gen_extu(size, cpu_tmp4);\n\n t0 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, false);\n\n cc = (CCPrepare) { .cond = TCG_COND_LEU, .reg = cpu_tmp4,\n\n .reg2 = t0, .mask = -1, .use_reg2 = true };\n\n break;\n\n\n\n case JCC_L:\n\n cond = TCG_COND_LT;\n\n goto fast_jcc_l;\n\n case JCC_LE:\n\n cond = TCG_COND_LE;\n\n fast_jcc_l:\n\n tcg_gen_add_tl(cpu_tmp4, cpu_cc_dst, cpu_cc_src);\n\n gen_exts(size, cpu_tmp4);\n\n t0 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, true);\n\n cc = (CCPrepare) { .cond = cond, .reg = cpu_tmp4,\n\n .reg2 = t0, .mask = -1, .use_reg2 = true };\n\n break;\n\n\n\n default:\n\n goto slow_jcc;\n\n }\n\n break;\n\n\n\n default:\n\n slow_jcc:\n\n /* This actually generates good code for JC, JZ and JS. */\n\n switch (jcc_op) {\n\n case JCC_O:\n\n cc = gen_prepare_eflags_o(s, reg);\n\n break;\n\n case JCC_B:\n\n cc = gen_prepare_eflags_c(s, reg);\n\n break;\n\n case JCC_Z:\n\n cc = gen_prepare_eflags_z(s, reg);\n\n break;\n\n case JCC_BE:\n\n gen_compute_eflags(s);\n\n cc = (CCPrepare) { .cond = TCG_COND_NE, .reg = cpu_cc_src,\n\n .mask = CC_Z | CC_C };\n\n break;\n\n case JCC_S:\n\n cc = gen_prepare_eflags_s(s, reg);\n\n break;\n\n case JCC_P:\n\n cc = gen_prepare_eflags_p(s, reg);\n\n break;\n\n case JCC_L:\n\n gen_compute_eflags(s);\n\n if (TCGV_EQUAL(reg, cpu_cc_src)) {\n\n reg = cpu_tmp0;\n\n }\n\n tcg_gen_shri_tl(reg, cpu_cc_src, 4); /* CC_O -> CC_S */\n\n tcg_gen_xor_tl(reg, reg, cpu_cc_src);\n\n cc = (CCPrepare) { .cond = TCG_COND_NE, .reg = reg,\n\n .mask = CC_S };\n\n break;\n\n default:\n\n case JCC_LE:\n\n gen_compute_eflags(s);\n\n if (TCGV_EQUAL(reg, cpu_cc_src)) {\n\n reg = cpu_tmp0;\n\n }\n\n tcg_gen_shri_tl(reg, cpu_cc_src, 4); /* CC_O -> CC_S */\n\n tcg_gen_xor_tl(reg, reg, cpu_cc_src);\n\n cc = (CCPrepare) { .cond = TCG_COND_NE, .reg = reg,\n\n .mask = CC_S | CC_Z };\n\n break;\n\n }\n\n break;\n\n }\n\n\n\n if (inv) {\n\n cc.cond = tcg_invert_cond(cc.cond);\n\n }\n\n return cc;\n\n}\n", + "output": "0", + "index": 24053 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0,\n\n const int16_t *ubuf[2], const int16_t *bguf[2],\n\n const int16_t *abuf0, uint8_t *dest,\n\n int dstW, int uvalpha, int y)\n\n{\n\n const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1];\n\n const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1\n\n\n\n if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster\n\n __asm__ volatile(\n\n \"mov %%\"REG_b\", \"ESP_OFFSET\"(%5) \\n\\t\"\n\n \"mov %4, %%\"REG_b\" \\n\\t\"\n\n \"push %%\"REG_BP\" \\n\\t\"\n\n YSCALEYUV2RGB1(%%REGBP, %5)\n\n \"pxor %%mm7, %%mm7 \\n\\t\"\n\n /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\n\n#ifdef DITHER1XBPP\n\n \"paddusb \"BLUE_DITHER\"(%5), %%mm2 \\n\\t\"\n\n \"paddusb \"GREEN_DITHER\"(%5), %%mm4 \\n\\t\"\n\n \"paddusb \"RED_DITHER\"(%5), %%mm5 \\n\\t\"\n\n#endif\n\n WRITERGB15(%%REGb, 8280(%5), %%REGBP)\n\n \"pop %%\"REG_BP\" \\n\\t\"\n\n \"mov \"ESP_OFFSET\"(%5), %%\"REG_b\" \\n\\t\"\n\n :: \"c\" (buf0), \"d\" (buf1), \"S\" (ubuf0), \"D\" (ubuf1), \"m\" (dest),\n\n \"a\" (&c->redDither)\n\n );\n\n } else {\n\n __asm__ volatile(\n\n \"mov %%\"REG_b\", \"ESP_OFFSET\"(%5) \\n\\t\"\n\n \"mov %4, %%\"REG_b\" \\n\\t\"\n\n \"push %%\"REG_BP\" \\n\\t\"\n\n YSCALEYUV2RGB1b(%%REGBP, %5)\n\n \"pxor %%mm7, %%mm7 \\n\\t\"\n\n /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\n\n#ifdef DITHER1XBPP\n\n \"paddusb \"BLUE_DITHER\"(%5), %%mm2 \\n\\t\"\n\n \"paddusb \"GREEN_DITHER\"(%5), %%mm4 \\n\\t\"\n\n \"paddusb \"RED_DITHER\"(%5), %%mm5 \\n\\t\"\n\n#endif\n\n WRITERGB15(%%REGb, 8280(%5), %%REGBP)\n\n \"pop %%\"REG_BP\" \\n\\t\"\n\n \"mov \"ESP_OFFSET\"(%5), %%\"REG_b\" \\n\\t\"\n\n :: \"c\" (buf0), \"d\" (buf1), \"S\" (ubuf0), \"D\" (ubuf1), \"m\" (dest),\n\n \"a\" (&c->redDither)\n\n );\n\n }\n\n}\n", + "output": "1", + "index": 15592 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int process_line(URLContext *h, char *line, int line_count,\n\n int *new_location)\n\n{\n\n HTTPContext *s = h->priv_data;\n\n char *tag, *p, *end;\n\n\n\n /* end of header */\n\n if (line[0] == '\\0')\n\n return 0;\n\n\n\n p = line;\n\n if (line_count == 0) {\n\n while (!isspace(*p) && *p != '\\0')\n\n p++;\n\n while (isspace(*p))\n\n p++;\n\n s->http_code = strtol(p, &end, 10);\n\n\n\n av_dlog(NULL, \"http_code=%d\\n\", s->http_code);\n\n\n\n /* error codes are 4xx and 5xx, but regard 401 as a success, so we\n\n * don't abort until all headers have been parsed. */\n\n if (s->http_code >= 400 && s->http_code < 600 && s->http_code != 401) {\n\n end += strspn(end, SPACE_CHARS);\n\n av_log(h, AV_LOG_WARNING, \"HTTP error %d %s\\n\",\n\n s->http_code, end);\n\n return -1;\n\n }\n\n } else {\n\n while (*p != '\\0' && *p != ':')\n\n p++;\n\n if (*p != ':')\n\n return 1;\n\n\n\n *p = '\\0';\n\n tag = line;\n\n p++;\n\n while (isspace(*p))\n\n p++;\n\n if (!av_strcasecmp(tag, \"Location\")) {\n\n strcpy(s->location, p);\n\n *new_location = 1;\n\n } else if (!av_strcasecmp (tag, \"Content-Length\") && s->filesize == -1) {\n\n s->filesize = atoll(p);\n\n } else if (!av_strcasecmp (tag, \"Content-Range\")) {\n\n /* \"bytes $from-$to/$document_size\" */\n\n const char *slash;\n\n if (!strncmp (p, \"bytes \", 6)) {\n\n p += 6;\n\n s->off = atoll(p);\n\n if ((slash = strchr(p, '/')) && strlen(slash) > 0)\n\n s->filesize = atoll(slash+1);\n\n }\n\n h->is_streamed = 0; /* we _can_ in fact seek */\n\n } else if (!av_strcasecmp(tag, \"Accept-Ranges\") && !strncmp(p, \"bytes\", 5)) {\n\n h->is_streamed = 0;\n\n } else if (!av_strcasecmp (tag, \"Transfer-Encoding\") && !av_strncasecmp(p, \"chunked\", 7)) {\n\n s->filesize = -1;\n\n s->chunksize = 0;\n\n } else if (!av_strcasecmp (tag, \"WWW-Authenticate\")) {\n\n ff_http_auth_handle_header(&s->auth_state, tag, p);\n\n } else if (!av_strcasecmp (tag, \"Authentication-Info\")) {\n\n ff_http_auth_handle_header(&s->auth_state, tag, p);\n\n } else if (!av_strcasecmp (tag, \"Connection\")) {\n\n if (!strcmp(p, \"close\"))\n\n s->willclose = 1;\n\n }\n\n }\n\n return 1;\n\n}\n", + "output": "1", + "index": 16130 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "ivshmem_server_handle_new_conn(IvshmemServer *server)\n\n{\n\n IvshmemServerPeer *peer, *other_peer;\n\n struct sockaddr_un unaddr;\n\n socklen_t unaddr_len;\n\n int newfd;\n\n unsigned i;\n\n\n\n /* accept the incoming connection */\n\n unaddr_len = sizeof(unaddr);\n\n newfd = qemu_accept(server->sock_fd,\n\n (struct sockaddr *)&unaddr, &unaddr_len);\n\n\n\n if (newfd < 0) {\n\n IVSHMEM_SERVER_DEBUG(server, \"cannot accept() %s\\n\", strerror(errno));\n\n return -1;\n\n }\n\n\n\n qemu_set_nonblock(newfd);\n\n IVSHMEM_SERVER_DEBUG(server, \"accept()=%d\\n\", newfd);\n\n\n\n /* allocate new structure for this peer */\n\n peer = g_malloc0(sizeof(*peer));\n\n peer->sock_fd = newfd;\n\n\n\n /* get an unused peer id */\n\n /* XXX: this could use id allocation such as Linux IDA, or simply\n\n * a free-list */\n\n for (i = 0; i < G_MAXUINT16; i++) {\n\n if (ivshmem_server_search_peer(server, server->cur_id) == NULL) {\n\n break;\n\n }\n\n server->cur_id++;\n\n }\n\n if (i == G_MAXUINT16) {\n\n IVSHMEM_SERVER_DEBUG(server, \"cannot allocate new client id\\n\");\n\n goto fail;\n\n }\n\n peer->id = server->cur_id++;\n\n\n\n /* create eventfd, one per vector */\n\n peer->vectors_count = server->n_vectors;\n\n for (i = 0; i < peer->vectors_count; i++) {\n\n if (event_notifier_init(&peer->vectors[i], FALSE) < 0) {\n\n IVSHMEM_SERVER_DEBUG(server, \"cannot create eventfd\\n\");\n\n goto fail;\n\n }\n\n }\n\n\n\n /* send peer id and shm fd */\n\n if (ivshmem_server_send_initial_info(server, peer) < 0) {\n\n IVSHMEM_SERVER_DEBUG(server, \"cannot send initial info\\n\");\n\n goto fail;\n\n }\n\n\n\n /* advertise the new peer to others */\n\n QTAILQ_FOREACH(other_peer, &server->peer_list, next) {\n\n for (i = 0; i < peer->vectors_count; i++) {\n\n ivshmem_server_send_one_msg(other_peer->sock_fd, peer->id,\n\n peer->vectors[i].wfd);\n\n }\n\n }\n\n\n\n /* advertise the other peers to the new one */\n\n QTAILQ_FOREACH(other_peer, &server->peer_list, next) {\n\n for (i = 0; i < peer->vectors_count; i++) {\n\n ivshmem_server_send_one_msg(peer->sock_fd, other_peer->id,\n\n other_peer->vectors[i].wfd);\n\n }\n\n }\n\n\n\n /* advertise the new peer to itself */\n\n for (i = 0; i < peer->vectors_count; i++) {\n\n ivshmem_server_send_one_msg(peer->sock_fd, peer->id,\n\n event_notifier_get_fd(&peer->vectors[i]));\n\n }\n\n\n\n QTAILQ_INSERT_TAIL(&server->peer_list, peer, next);\n\n IVSHMEM_SERVER_DEBUG(server, \"new peer id = %\" PRId64 \"\\n\",\n\n peer->id);\n\n return 0;\n\n\n\nfail:\n\n while (i--) {\n\n event_notifier_cleanup(&peer->vectors[i]);\n\n }\n\n close(newfd);\n\n g_free(peer);\n\n return -1;\n\n}\n", + "output": "1", + "index": 24355 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)\n{\n const uint8_t* as_pack;\n int freq, stype, smpls, quant, i, ach;\n as_pack = dv_extract_pack(frame, dv_audio_source);\n if (!as_pack || !c->sys) { /* No audio ? */\n c->ach = 0;\n smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */\n freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */\n stype = (as_pack[3] & 0x1f); /* 0 - 2CH, 2 - 4CH, 3 - 8CH */\n quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */\n if (stype > 3) {\n av_log(c->fctx, AV_LOG_ERROR, \"stype %d is invalid\\n\", stype);\n c->ach = 0;\n /* note: ach counts PAIRS of channels (i.e. stereo channels) */\n ach = ((int[4]){ 1, 0, 2, 4})[stype];\n if (ach == 1 && quant && freq == 2)\n ach = 2;\n /* Dynamic handling of the audio streams in DV */\n for (i = 0; i < ach; i++) {\n if (!c->ast[i]) {\n c->ast[i] = avformat_new_stream(c->fctx, NULL);\n if (!c->ast[i])\n break;\n avpriv_set_pts_info(c->ast[i], 64, 1, 30000);\n c->ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n c->ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;\n av_init_packet(&c->audio_pkt[i]);\n c->audio_pkt[i].size = 0;\n c->audio_pkt[i].data = c->audio_buf[i];\n c->audio_pkt[i].stream_index = c->ast[i]->index;\n c->audio_pkt[i].flags |= AV_PKT_FLAG_KEY;\n c->ast[i]->codec->sample_rate = dv_audio_frequency[freq];\n c->ast[i]->codec->channels = 2;\n c->ast[i]->codec->bit_rate = 2 * dv_audio_frequency[freq] * 16;\n c->ast[i]->start_time = 0;\n c->ach = i;\n return (c->sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */;", + "output": "1", + "index": 8347 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void compute_exp_strategy(AC3EncodeContext *s)\n\n{\n\n int ch, blk, blk1;\n\n\n\n for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++) {\n\n uint8_t *exp_strategy = s->exp_strategy[ch];\n\n uint8_t *exp = s->blocks[0].exp[ch];\n\n int exp_diff;\n\n\n\n /* estimate if the exponent variation & decide if they should be\n\n reused in the next frame */\n\n exp_strategy[0] = EXP_NEW;\n\n exp += AC3_MAX_COEFS;\n\n for (blk = 1; blk < AC3_MAX_BLOCKS; blk++, exp += AC3_MAX_COEFS) {\n\n if ((ch == CPL_CH && (!s->blocks[blk].cpl_in_use || !s->blocks[blk-1].cpl_in_use)) ||\n\n (ch > CPL_CH && (s->blocks[blk].channel_in_cpl[ch] != s->blocks[blk-1].channel_in_cpl[ch]))) {\n\n exp_strategy[blk] = EXP_NEW;\n\n continue;\n\n }\n\n exp_diff = s->dsp.sad[0](NULL, exp, exp - AC3_MAX_COEFS, 16, 16);\n\n exp_strategy[blk] = EXP_REUSE;\n\n if (ch == CPL_CH && exp_diff > (EXP_DIFF_THRESHOLD * (s->blocks[blk].end_freq[ch] - s->start_freq[ch]) / AC3_MAX_COEFS))\n\n exp_strategy[blk] = EXP_NEW;\n\n else if (ch > CPL_CH && exp_diff > EXP_DIFF_THRESHOLD)\n\n exp_strategy[blk] = EXP_NEW;\n\n }\n\n\n\n /* now select the encoding strategy type : if exponents are often\n\n recoded, we use a coarse encoding */\n\n blk = 0;\n\n while (blk < AC3_MAX_BLOCKS) {\n\n blk1 = blk + 1;\n\n while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE)\n\n blk1++;\n\n switch (blk1 - blk) {\n\n case 1: exp_strategy[blk] = EXP_D45; break;\n\n case 2:\n\n case 3: exp_strategy[blk] = EXP_D25; break;\n\n default: exp_strategy[blk] = EXP_D15; break;\n\n }\n\n blk = blk1;\n\n }\n\n }\n\n if (s->lfe_on) {\n\n ch = s->lfe_channel;\n\n s->exp_strategy[ch][0] = EXP_D15;\n\n for (blk = 1; blk < AC3_MAX_BLOCKS; blk++)\n\n s->exp_strategy[ch][blk] = EXP_REUSE;\n\n }\n\n}\n", + "output": "0", + "index": 12988 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void gen_intermediate_code(CPUSH4State * env, struct TranslationBlock *tb)\n\n{\n\n SuperHCPU *cpu = sh_env_get_cpu(env);\n\n CPUState *cs = CPU(cpu);\n\n DisasContext ctx;\n\n target_ulong pc_start;\n\n int num_insns;\n\n int max_insns;\n\n\n\n pc_start = tb->pc;\n\n ctx.pc = pc_start;\n\n ctx.tbflags = (uint32_t)tb->flags;\n\n ctx.envflags = tb->flags & DELAY_SLOT_MASK;\n\n ctx.bstate = BS_NONE;\n\n ctx.memidx = (ctx.tbflags & (1u << SR_MD)) == 0 ? 1 : 0;\n\n /* We don't know if the delayed pc came from a dynamic or static branch,\n\n so assume it is a dynamic branch. */\n\n ctx.delayed_pc = -1; /* use delayed pc from env pointer */\n\n ctx.tb = tb;\n\n ctx.singlestep_enabled = cs->singlestep_enabled;\n\n ctx.features = env->features;\n\n ctx.has_movcal = (ctx.tbflags & TB_FLAG_PENDING_MOVCA);\n\n\n\n num_insns = 0;\n\n max_insns = tb->cflags & CF_COUNT_MASK;\n\n if (max_insns == 0) {\n\n max_insns = CF_COUNT_MASK;\n\n }\n\n if (max_insns > TCG_MAX_INSNS) {\n\n max_insns = TCG_MAX_INSNS;\n\n }\n\n\n\n gen_tb_start(tb);\n\n while (ctx.bstate == BS_NONE && !tcg_op_buf_full()) {\n\n tcg_gen_insn_start(ctx.pc, ctx.envflags);\n\n num_insns++;\n\n\n\n if (unlikely(cpu_breakpoint_test(cs, ctx.pc, BP_ANY))) {\n\n /* We have hit a breakpoint - make sure PC is up-to-date */\n\n gen_save_cpu_state(&ctx, true);\n\n gen_helper_debug(cpu_env);\n\n ctx.bstate = BS_EXCP;\n\n /* The address covered by the breakpoint must be included in\n\n [tb->pc, tb->pc + tb->size) in order to for it to be\n\n properly cleared -- thus we increment the PC here so that\n\n the logic setting tb->size below does the right thing. */\n\n ctx.pc += 2;\n\n break;\n\n }\n\n\n\n if (num_insns == max_insns && (tb->cflags & CF_LAST_IO)) {\n\n gen_io_start();\n\n }\n\n\n\n ctx.opcode = cpu_lduw_code(env, ctx.pc);\n\n\tdecode_opc(&ctx);\n\n\tctx.pc += 2;\n\n\tif ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)\n\n\t break;\n\n if (cs->singlestep_enabled) {\n\n\t break;\n\n }\n\n if (num_insns >= max_insns)\n\n break;\n\n if (singlestep)\n\n break;\n\n }\n\n if (tb->cflags & CF_LAST_IO)\n\n gen_io_end();\n\n if (cs->singlestep_enabled) {\n\n gen_save_cpu_state(&ctx, true);\n\n gen_helper_debug(cpu_env);\n\n } else {\n\n\tswitch (ctx.bstate) {\n\n case BS_STOP:\n\n gen_save_cpu_state(&ctx, true);\n\n tcg_gen_exit_tb(0);\n\n break;\n\n case BS_NONE:\n\n gen_save_cpu_state(&ctx, false);\n\n gen_goto_tb(&ctx, 0, ctx.pc);\n\n break;\n\n case BS_EXCP:\n\n /* fall through */\n\n case BS_BRANCH:\n\n default:\n\n break;\n\n\t}\n\n }\n\n\n\n gen_tb_end(tb, num_insns);\n\n\n\n tb->size = ctx.pc - pc_start;\n\n tb->icount = num_insns;\n\n\n\n#ifdef DEBUG_DISAS\n\n if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)\n\n && qemu_log_in_addr_range(pc_start)) {\n\n qemu_log_lock();\n\n\tqemu_log(\"IN:\\n\");\t/* , lookup_symbol(pc_start)); */\n\n log_target_disas(cs, pc_start, ctx.pc - pc_start, 0);\n\n\tqemu_log(\"\\n\");\n\n qemu_log_unlock();\n\n }\n\n#endif\n\n}\n", + "output": "0", + "index": 12889 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, unsigned src_size)\n\n{\n\n\tconst uint8_t *s = src;\n\n\tconst uint8_t *end;\n\n#ifdef HAVE_MMX\n\n\tconst uint8_t *mm_end;\n\n#endif\n\n\tuint16_t *d = (uint16_t *)dst;\n\n\tend = s + src_size;\n\n#ifdef HAVE_MMX\n\n\t__asm __volatile(PREFETCH\"\t%0\"::\"m\"(*src):\"memory\");\n\n\t__asm __volatile(\n\n\t \"movq\t%0, %%mm7\\n\\t\"\n\n\t \"movq\t%1, %%mm6\\n\\t\"\n\n\t ::\"m\"(red_16mask),\"m\"(green_16mask));\n\n\tmm_end = end - 11;\n\n\twhile(s < mm_end)\n\n\t{\n\n\t __asm __volatile(\n\n\t\tPREFETCH\" 32%1\\n\\t\"\n\n\t\t\"movd\t%1, %%mm0\\n\\t\"\n\n\t\t\"movd\t3%1, %%mm3\\n\\t\"\n\n\t\t\"punpckldq 6%1, %%mm0\\n\\t\"\n\n\t\t\"punpckldq 9%1, %%mm3\\n\\t\"\n\n\t\t\"movq\t%%mm0, %%mm1\\n\\t\"\n\n\t\t\"movq\t%%mm0, %%mm2\\n\\t\"\n\n\t\t\"movq\t%%mm3, %%mm4\\n\\t\"\n\n\t\t\"movq\t%%mm3, %%mm5\\n\\t\"\n\n\t\t\"psrlq\t$3, %%mm0\\n\\t\"\n\n\t\t\"psrlq\t$3, %%mm3\\n\\t\"\n\n\t\t\"pand\t%2, %%mm0\\n\\t\"\n\n\t\t\"pand\t%2, %%mm3\\n\\t\"\n\n\t\t\"psrlq\t$5, %%mm1\\n\\t\"\n\n\t\t\"psrlq\t$5, %%mm4\\n\\t\"\n\n\t\t\"pand\t%%mm6, %%mm1\\n\\t\"\n\n\t\t\"pand\t%%mm6, %%mm4\\n\\t\"\n\n\t\t\"psrlq\t$8, %%mm2\\n\\t\"\n\n\t\t\"psrlq\t$8, %%mm5\\n\\t\"\n\n\t\t\"pand\t%%mm7, %%mm2\\n\\t\"\n\n\t\t\"pand\t%%mm7, %%mm5\\n\\t\"\n\n\t\t\"por\t%%mm1, %%mm0\\n\\t\"\n\n\t\t\"por\t%%mm4, %%mm3\\n\\t\"\n\n\t\t\"por\t%%mm2, %%mm0\\n\\t\"\n\n\t\t\"por\t%%mm5, %%mm3\\n\\t\"\n\n\t\t\"psllq\t$16, %%mm3\\n\\t\"\n\n\t\t\"por\t%%mm3, %%mm0\\n\\t\"\n\n\t\tMOVNTQ\"\t%%mm0, %0\\n\\t\"\n\n\t\t:\"=m\"(*d):\"m\"(*s),\"m\"(blue_16mask):\"memory\");\n\n\t\td += 4;\n\n\t\ts += 12;\n\n\t}\n\n\t__asm __volatile(SFENCE:::\"memory\");\n\n\t__asm __volatile(EMMS:::\"memory\");\n\n#endif\n\n\twhile(s < end)\n\n\t{\n\n\t\tconst int b= *s++;\n\n\t\tconst int g= *s++;\n\n\t\tconst int r= *s++;\n\n\t\t*d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8);\n\n\t}\n\n}\n", + "output": "1", + "index": 17543 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct,\n\n float *out, float X[2][38][64],\n\n float mdct_buf[2][64],\n\n float *v0, int *v_off, const unsigned int div)\n\n{\n\n int i, n;\n\n const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us;\n\n float *v;\n\n for (i = 0; i < 32; i++) {\n\n if (*v_off == 0) {\n\n int saved_samples = (1280 - 128) >> div;\n\n memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float));\n\n *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - (128 >> div);\n\n } else {\n\n *v_off -= 128 >> div;\n\n }\n\n v = v0 + *v_off;\n\n if (div) {\n\n for (n = 0; n < 32; n++) {\n\n X[0][i][ n] = -X[0][i][n];\n\n X[0][i][32+n] = X[1][i][31-n];\n\n }\n\n mdct->imdct_half(mdct, mdct_buf[0], X[0][i]);\n\n for (n = 0; n < 32; n++) {\n\n v[ n] = mdct_buf[0][63 - 2*n];\n\n v[63 - n] = -mdct_buf[0][62 - 2*n];\n\n }\n\n } else {\n\n for (n = 1; n < 64; n+=2) {\n\n X[1][i][n] = -X[1][i][n];\n\n }\n\n mdct->imdct_half(mdct, mdct_buf[0], X[0][i]);\n\n mdct->imdct_half(mdct, mdct_buf[1], X[1][i]);\n\n for (n = 0; n < 64; n++) {\n\n v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ];\n\n v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ];\n\n }\n\n }\n\n dsp->vector_fmul_add(out, v , sbr_qmf_window , zero64, 64 >> div);\n\n dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div);\n\n dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div);\n\n dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div);\n\n dsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div);\n\n dsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div);\n\n dsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div);\n\n dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div);\n\n dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div);\n\n dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div);\n\n out += 64 >> div;\n\n }\n\n}\n", + "output": "1", + "index": 21014 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int mmu40x_get_physical_address (CPUState *env, mmu_ctx_t *ctx,\n\n target_ulong address, int rw, int access_type)\n\n{\n\n ppcemb_tlb_t *tlb;\n\n target_phys_addr_t raddr;\n\n int i, ret, zsel, zpr;\n\n\n\n ret = -1;\n\n raddr = -1;\n\n for (i = 0; i < env->nb_tlb; i++) {\n\n tlb = &env->tlb[i].tlbe;\n\n if (ppcemb_tlb_check(env, tlb, &raddr, address,\n\n env->spr[SPR_40x_PID], 0, i) < 0)\n\n continue;\n\n zsel = (tlb->attr >> 4) & 0xF;\n\n zpr = (env->spr[SPR_40x_ZPR] >> (28 - (2 * zsel))) & 0x3;\n\n#if defined (DEBUG_SOFTWARE_TLB)\n\n if (loglevel != 0) {\n\n fprintf(logfile, \"%s: TLB %d zsel %d zpr %d rw %d attr %08x\\n\",\n\n __func__, i, zsel, zpr, rw, tlb->attr);\n\n }\n\n#endif\n\n if (access_type == ACCESS_CODE) {\n\n /* Check execute enable bit */\n\n switch (zpr) {\n\n case 0x2:\n\n if (msr_pr)\n\n goto check_exec_perm;\n\n goto exec_granted;\n\n case 0x0:\n\n if (msr_pr) {\n\n ctx->prot = 0;\n\n ret = -3;\n\n break;\n\n }\n\n /* No break here */\n\n case 0x1:\n\n check_exec_perm:\n\n /* Check from TLB entry */\n\n if (!(tlb->prot & PAGE_EXEC)) {\n\n ret = -3;\n\n } else {\n\n if (tlb->prot & PAGE_WRITE) {\n\n ctx->prot = PAGE_READ | PAGE_WRITE;\n\n } else {\n\n ctx->prot = PAGE_READ;\n\n }\n\n ret = 0;\n\n }\n\n break;\n\n case 0x3:\n\n exec_granted:\n\n /* All accesses granted */\n\n ctx->prot = PAGE_READ | PAGE_WRITE;\n\n ret = 0;\n\n break;\n\n }\n\n } else {\n\n switch (zpr) {\n\n case 0x2:\n\n if (msr_pr)\n\n goto check_rw_perm;\n\n goto rw_granted;\n\n case 0x0:\n\n if (msr_pr) {\n\n ctx->prot = 0;\n\n ret = -2;\n\n break;\n\n }\n\n /* No break here */\n\n case 0x1:\n\n check_rw_perm:\n\n /* Check from TLB entry */\n\n /* Check write protection bit */\n\n if (tlb->prot & PAGE_WRITE) {\n\n ctx->prot = PAGE_READ | PAGE_WRITE;\n\n ret = 0;\n\n } else {\n\n ctx->prot = PAGE_READ;\n\n if (rw)\n\n ret = -2;\n\n else\n\n ret = 0;\n\n }\n\n break;\n\n case 0x3:\n\n rw_granted:\n\n /* All accesses granted */\n\n ctx->prot = PAGE_READ | PAGE_WRITE;\n\n ret = 0;\n\n break;\n\n }\n\n }\n\n if (ret >= 0) {\n\n ctx->raddr = raddr;\n\n#if defined (DEBUG_SOFTWARE_TLB)\n\n if (loglevel != 0) {\n\n fprintf(logfile, \"%s: access granted \" ADDRX \" => \" REGX\n\n \" %d %d\\n\", __func__, address, ctx->raddr, ctx->prot,\n\n ret);\n\n }\n\n#endif\n\n return 0;\n\n }\n\n }\n\n#if defined (DEBUG_SOFTWARE_TLB)\n\n if (loglevel != 0) {\n\n fprintf(logfile, \"%s: access refused \" ADDRX \" => \" REGX\n\n \" %d %d\\n\", __func__, address, raddr, ctx->prot,\n\n ret);\n\n }\n\n#endif\n\n\n\n return ret;\n\n}\n", + "output": "0", + "index": 24883 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "CharDriverState *text_console_init(DisplayState *ds, const char *p)\n\n{\n\n CharDriverState *chr;\n\n TextConsole *s;\n\n unsigned width;\n\n unsigned height;\n\n static int color_inited;\n\n\n\n chr = qemu_mallocz(sizeof(CharDriverState));\n\n if (!chr)\n\n return NULL;\n\n s = new_console(ds, TEXT_CONSOLE);\n\n if (!s) {\n\n free(chr);\n\n return NULL;\n\n }\n\n if (!p)\n\n p = DEFAULT_MONITOR_SIZE;\n\n\n\n chr->opaque = s;\n\n chr->chr_write = console_puts;\n\n chr->chr_send_event = console_send_event;\n\n\n\n s->chr = chr;\n\n s->out_fifo.buf = s->out_fifo_buf;\n\n s->out_fifo.buf_size = sizeof(s->out_fifo_buf);\n\n s->kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s);\n\n\n\n if (!color_inited) {\n\n color_inited = 1;\n\n console_color_init(s->ds);\n\n }\n\n s->y_displayed = 0;\n\n s->y_base = 0;\n\n s->total_height = DEFAULT_BACKSCROLL;\n\n s->x = 0;\n\n s->y = 0;\n\n width = s->ds->width;\n\n height = s->ds->height;\n\n if (p != 0) {\n\n width = strtoul(p, (char **)&p, 10);\n\n if (*p == 'C') {\n\n p++;\n\n width *= FONT_WIDTH;\n\n }\n\n if (*p == 'x') {\n\n p++;\n\n height = strtoul(p, (char **)&p, 10);\n\n if (*p == 'C') {\n\n p++;\n\n height *= FONT_HEIGHT;\n\n }\n\n }\n\n }\n\n s->g_width = width;\n\n s->g_height = height;\n\n\n\n s->hw_invalidate = text_console_invalidate;\n\n s->hw_text_update = text_console_update;\n\n s->hw = s;\n\n\n\n /* Set text attribute defaults */\n\n s->t_attrib_default.bold = 0;\n\n s->t_attrib_default.uline = 0;\n\n s->t_attrib_default.blink = 0;\n\n s->t_attrib_default.invers = 0;\n\n s->t_attrib_default.unvisible = 0;\n\n s->t_attrib_default.fgcol = COLOR_WHITE;\n\n s->t_attrib_default.bgcol = COLOR_BLACK;\n\n\n\n /* set current text attributes to default */\n\n s->t_attrib = s->t_attrib_default;\n\n text_console_resize(s);\n\n\n\n qemu_chr_reset(chr);\n\n\n\n return chr;\n\n}\n", + "output": "0", + "index": 300 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s)\n\n{\n\n AVCodecContext *VideoCodec = s->streams[0]->codec;\n\n AVCodecContext *AudioCodec = s->streams[1]->codec;\n\n int AudioRate = AudioCodec->sample_rate;\n\n int FrameRate = ((VideoCodec->time_base.den) * (0x10000))/ (VideoCodec->time_base.num);\n\n int audio_kbitrate= AudioCodec->bit_rate / 1000;\n\n int video_kbitrate= FFMIN(VideoCodec->bit_rate / 1000, 800 - audio_kbitrate);\n\n\n\n put_be32(pb, 0x94 ); /* size */\n\n put_tag(pb, \"uuid\");\n\n put_tag(pb, \"PROF\");\n\n\n\n put_be32(pb, 0x21d24fce ); /* 96 bit UUID */\n\n put_be32(pb, 0xbb88695c );\n\n put_be32(pb, 0xfac9c740 );\n\n\n\n put_be32(pb, 0x0 ); /* ? */\n\n put_be32(pb, 0x3 ); /* 3 sections ? */\n\n\n\n put_be32(pb, 0x14 ); /* size */\n\n put_tag(pb, \"FPRF\");\n\n put_be32(pb, 0x0 ); /* ? */\n\n put_be32(pb, 0x0 ); /* ? */\n\n put_be32(pb, 0x0 ); /* ? */\n\n\n\n put_be32(pb, 0x2c ); /* size */\n\n put_tag(pb, \"APRF\"); /* audio */\n\n put_be32(pb, 0x0 );\n\n put_be32(pb, 0x2 ); /* TrackID */\n\n put_tag(pb, \"mp4a\");\n\n put_be32(pb, 0x20f );\n\n put_be32(pb, 0x0 );\n\n put_be32(pb, audio_kbitrate);\n\n put_be32(pb, audio_kbitrate);\n\n put_be32(pb, AudioRate );\n\n put_be32(pb, AudioCodec->channels );\n\n\n\n put_be32(pb, 0x34 ); /* size */\n\n put_tag(pb, \"VPRF\"); /* video */\n\n put_be32(pb, 0x0 );\n\n put_be32(pb, 0x1 ); /* TrackID */\n\n put_tag(pb, \"mp4v\");\n\n put_be32(pb, 0x103 );\n\n put_be32(pb, 0x0 );\n\n put_be32(pb, video_kbitrate);\n\n put_be32(pb, video_kbitrate);\n\n put_be32(pb, FrameRate);\n\n put_be32(pb, FrameRate);\n\n put_be16(pb, VideoCodec->width);\n\n put_be16(pb, VideoCodec->height);\n\n put_be32(pb, 0x010001); /* ? */\n\n}\n", + "output": "0", + "index": 18128 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)\n\n{\n\n VocDecContext *voc = s->priv_data;\n\n AVCodecParameters *par = st->codecpar;\n\n AVIOContext *pb = s->pb;\n\n VocType type;\n\n int size, tmp_codec=-1;\n\n int sample_rate = 0;\n\n int channels = 1;\n\n int64_t duration;\n\n int ret;\n\n\n\n av_add_index_entry(st,\n\n avio_tell(pb),\n\n voc->pts,\n\n voc->remaining_size,\n\n 0,\n\n AVINDEX_KEYFRAME);\n\n\n\n while (!voc->remaining_size) {\n\n type = avio_r8(pb);\n\n if (type == VOC_TYPE_EOF)\n\n return AVERROR_EOF;\n\n voc->remaining_size = avio_rl24(pb);\n\n if (!voc->remaining_size) {\n\n if (!s->pb->seekable)\n\n return AVERROR(EIO);\n\n voc->remaining_size = avio_size(pb) - avio_tell(pb);\n\n }\n\n max_size -= 4;\n\n\n\n switch (type) {\n\n case VOC_TYPE_VOICE_DATA:\n\n if (!par->sample_rate) {\n\n par->sample_rate = 1000000 / (256 - avio_r8(pb));\n\n if (sample_rate)\n\n par->sample_rate = sample_rate;\n\n avpriv_set_pts_info(st, 64, 1, par->sample_rate);\n\n par->channels = channels;\n\n par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id);\n\n } else\n\n avio_skip(pb, 1);\n\n tmp_codec = avio_r8(pb);\n\n voc->remaining_size -= 2;\n\n max_size -= 2;\n\n channels = 1;\n\n break;\n\n\n\n case VOC_TYPE_VOICE_DATA_CONT:\n\n break;\n\n\n\n case VOC_TYPE_EXTENDED:\n\n sample_rate = avio_rl16(pb);\n\n avio_r8(pb);\n\n channels = avio_r8(pb) + 1;\n\n sample_rate = 256000000 / (channels * (65536 - sample_rate));\n\n voc->remaining_size = 0;\n\n max_size -= 4;\n\n break;\n\n\n\n case VOC_TYPE_NEW_VOICE_DATA:\n\n if (!par->sample_rate) {\n\n par->sample_rate = avio_rl32(pb);\n\n avpriv_set_pts_info(st, 64, 1, par->sample_rate);\n\n par->bits_per_coded_sample = avio_r8(pb);\n\n par->channels = avio_r8(pb);\n\n } else\n\n avio_skip(pb, 6);\n\n tmp_codec = avio_rl16(pb);\n\n avio_skip(pb, 4);\n\n voc->remaining_size -= 12;\n\n max_size -= 12;\n\n break;\n\n\n\n default:\n\n avio_skip(pb, voc->remaining_size);\n\n max_size -= voc->remaining_size;\n\n voc->remaining_size = 0;\n\n break;\n\n }\n\n }\n\n\n\n if (par->sample_rate <= 0) {\n\n av_log(s, AV_LOG_ERROR, \"Invalid sample rate %d\\n\", par->sample_rate);\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n if (tmp_codec >= 0) {\n\n tmp_codec = ff_codec_get_id(ff_voc_codec_tags, tmp_codec);\n\n if (par->codec_id == AV_CODEC_ID_NONE)\n\n par->codec_id = tmp_codec;\n\n else if (par->codec_id != tmp_codec)\n\n av_log(s, AV_LOG_WARNING, \"Ignoring mid-stream change in audio codec\\n\");\n\n if (par->codec_id == AV_CODEC_ID_NONE) {\n\n if (s->audio_codec_id == AV_CODEC_ID_NONE) {\n\n av_log(s, AV_LOG_ERROR, \"unknown codec tag\\n\");\n\n return AVERROR(EINVAL);\n\n }\n\n av_log(s, AV_LOG_WARNING, \"unknown codec tag\\n\");\n\n }\n\n }\n\n\n\n par->bit_rate = par->sample_rate * par->channels * par->bits_per_coded_sample;\n\n\n\n if (max_size <= 0)\n\n max_size = 2048;\n\n size = FFMIN(voc->remaining_size, max_size);\n\n voc->remaining_size -= size;\n\n\n\n ret = av_get_packet(pb, pkt, size);\n\n pkt->dts = pkt->pts = voc->pts;\n\n\n\n duration = av_get_audio_frame_duration2(st->codecpar, size);\n\n if (duration > 0 && voc->pts != AV_NOPTS_VALUE)\n\n voc->pts += duration;\n\n else\n\n voc->pts = AV_NOPTS_VALUE;\n\n\n\n return ret;\n\n}\n", + "output": "1", + "index": 12974 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void setup_rt_frame(int sig, struct target_sigaction *ka,\n\n target_siginfo_t *info,\n\n target_sigset_t *set, CPUAlphaState *env)\n\n{\n\n abi_ulong frame_addr, r26;\n\n struct target_rt_sigframe *frame;\n\n int i, err = 0;\n\n\n\n frame_addr = get_sigframe(ka, env, sizeof(*frame));\n\n if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {\n\n goto give_sigsegv;\n\n }\n\n\n\n err |= copy_siginfo_to_user(&frame->info, info);\n\n\n\n __put_user(0, &frame->uc.tuc_flags);\n\n __put_user(0, &frame->uc.tuc_link);\n\n __put_user(set->sig[0], &frame->uc.tuc_osf_sigmask);\n\n __put_user(target_sigaltstack_used.ss_sp,\n\n &frame->uc.tuc_stack.ss_sp);\n\n __put_user(sas_ss_flags(env->ir[IR_SP]),\n\n &frame->uc.tuc_stack.ss_flags);\n\n __put_user(target_sigaltstack_used.ss_size,\n\n &frame->uc.tuc_stack.ss_size);\n\n err |= setup_sigcontext(&frame->uc.tuc_mcontext, env, frame_addr, set);\n\n for (i = 0; i < TARGET_NSIG_WORDS; ++i) {\n\n __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);\n\n }\n\n\n\n if (ka->sa_restorer) {\n\n r26 = ka->sa_restorer;\n\n } else {\n\n __put_user(INSN_MOV_R30_R16, &frame->retcode[0]);\n\n __put_user(INSN_LDI_R0 + TARGET_NR_rt_sigreturn,\n\n &frame->retcode[1]);\n\n __put_user(INSN_CALLSYS, &frame->retcode[2]);\n\n /* imb(); */\n\n r26 = frame_addr;\n\n }\n\n\n\n if (err) {\n\n give_sigsegv:\n\n if (sig == TARGET_SIGSEGV) {\n\n ka->_sa_handler = TARGET_SIG_DFL;\n\n }\n\n force_sig(TARGET_SIGSEGV);\n\n }\n\n\n\n env->ir[IR_RA] = r26;\n\n env->ir[IR_PV] = env->pc = ka->_sa_handler;\n\n env->ir[IR_A0] = sig;\n\n env->ir[IR_A1] = frame_addr + offsetof(struct target_rt_sigframe, info);\n\n env->ir[IR_A2] = frame_addr + offsetof(struct target_rt_sigframe, uc);\n\n env->ir[IR_SP] = frame_addr;\n\n}\n", + "output": "0", + "index": 23933 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section,\n\n int section_len)\n\n{\n\n MpegTSContext *ts = filter->u.section_filter.opaque;\n\n MpegTSSectionFilter *tssf = &filter->u.section_filter;\n\n SectionHeader h;\n\n const uint8_t *p, *p_end;\n\n AVIOContext pb;\n\n int mp4_descr_count = 0;\n\n Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = { { 0 } };\n\n int i, pid;\n\n AVFormatContext *s = ts->stream;\n\n\n\n p_end = section + section_len - 4;\n\n p = section;\n\n if (parse_section_header(&h, &p, p_end) < 0)\n\n return;\n\n if (h.tid != M4OD_TID)\n\n return;\n\n if (h.version == tssf->last_ver)\n\n return;\n\n tssf->last_ver = h.version;\n\n\n\n mp4_read_od(s, p, (unsigned) (p_end - p), mp4_descr, &mp4_descr_count,\n\n MAX_MP4_DESCR_COUNT);\n\n\n\n for (pid = 0; pid < NB_PID_MAX; pid++) {\n\n if (!ts->pids[pid])\n\n continue;\n\n for (i = 0; i < mp4_descr_count; i++) {\n\n PESContext *pes;\n\n AVStream *st;\n\n if (ts->pids[pid]->es_id != mp4_descr[i].es_id)\n\n continue;\n\n if (ts->pids[pid]->type != MPEGTS_PES) {\n\n av_log(s, AV_LOG_ERROR, \"pid %x is not PES\\n\", pid);\n\n continue;\n\n }\n\n pes = ts->pids[pid]->u.pes_filter.opaque;\n\n st = pes->st;\n\n if (!st)\n\n continue;\n\n\n\n pes->sl = mp4_descr[i].sl;\n\n\n\n ffio_init_context(&pb, mp4_descr[i].dec_config_descr,\n\n mp4_descr[i].dec_config_descr_len, 0,\n\n NULL, NULL, NULL, NULL);\n\n ff_mp4_read_dec_config_descr(s, st, &pb);\n\n if (st->codec->codec_id == AV_CODEC_ID_AAC &&\n\n st->codec->extradata_size > 0)\n\n st->need_parsing = 0;\n\n if (st->codec->codec_id == AV_CODEC_ID_H264 &&\n\n st->codec->extradata_size > 0)\n\n st->need_parsing = 0;\n\n\n\n if (st->codec->codec_id <= AV_CODEC_ID_NONE) {\n\n // do nothing\n\n } else if (st->codec->codec_id < AV_CODEC_ID_FIRST_AUDIO)\n\n st->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n\n else if (st->codec->codec_id < AV_CODEC_ID_FIRST_SUBTITLE)\n\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n else if (st->codec->codec_id < AV_CODEC_ID_FIRST_UNKNOWN)\n\n st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;\n\n }\n\n }\n\n for (i = 0; i < mp4_descr_count; i++)\n\n av_free(mp4_descr[i].dec_config_descr);\n\n}\n", + "output": "0", + "index": 1833 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void RENAME(rgb16to15)(const uint8_t *src, uint8_t *dst, long src_size)\n\n{\n\n register const uint8_t* s=src;\n\n register uint8_t* d=dst;\n\n register const uint8_t *end;\n\n const uint8_t *mm_end;\n\n end = s + src_size;\n\n#if COMPILE_TEMPLATE_MMX\n\n __asm__ volatile(PREFETCH\" %0\"::\"m\"(*s));\n\n __asm__ volatile(\"movq %0, %%mm7\"::\"m\"(mask15rg));\n\n __asm__ volatile(\"movq %0, %%mm6\"::\"m\"(mask15b));\n\n mm_end = end - 15;\n\n while (s>1)&0x7FE07FE0) | (x&0x001F001F);\n\n s+=4;\n\n d+=4;\n\n }\n\n if (s < end) {\n\n register uint16_t x= *((const uint16_t*)s);\n\n *((uint16_t *)d) = ((x>>1)&0x7FE0) | (x&0x001F);\n\n }\n\n}\n", + "output": "0", + "index": 26801 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int vhost_dev_init(struct vhost_dev *hdev, void *opaque,\n\n VhostBackendType backend_type)\n\n{\n\n uint64_t features;\n\n int i, r;\n\n\n\n if (vhost_set_backend_type(hdev, backend_type) < 0) {\n\n close((uintptr_t)opaque);\n\n return -1;\n\n }\n\n\n\n if (hdev->vhost_ops->vhost_backend_init(hdev, opaque) < 0) {\n\n close((uintptr_t)opaque);\n\n return -errno;\n\n }\n\n\n\n r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_OWNER, NULL);\n\n if (r < 0) {\n\n goto fail;\n\n }\n\n\n\n r = hdev->vhost_ops->vhost_call(hdev, VHOST_GET_FEATURES, &features);\n\n if (r < 0) {\n\n goto fail;\n\n }\n\n\n\n for (i = 0; i < hdev->nvqs; ++i) {\n\n r = vhost_virtqueue_init(hdev, hdev->vqs + i, i);\n\n if (r < 0) {\n\n goto fail_vq;\n\n }\n\n }\n\n hdev->features = features;\n\n\n\n hdev->memory_listener = (MemoryListener) {\n\n .begin = vhost_begin,\n\n .commit = vhost_commit,\n\n .region_add = vhost_region_add,\n\n .region_del = vhost_region_del,\n\n .region_nop = vhost_region_nop,\n\n .log_start = vhost_log_start,\n\n .log_stop = vhost_log_stop,\n\n .log_sync = vhost_log_sync,\n\n .log_global_start = vhost_log_global_start,\n\n .log_global_stop = vhost_log_global_stop,\n\n .eventfd_add = vhost_eventfd_add,\n\n .eventfd_del = vhost_eventfd_del,\n\n .priority = 10\n\n };\n\n hdev->migration_blocker = NULL;\n\n if (!(hdev->features & (0x1ULL << VHOST_F_LOG_ALL))) {\n\n error_setg(&hdev->migration_blocker,\n\n \"Migration disabled: vhost lacks VHOST_F_LOG_ALL feature.\");\n\n migrate_add_blocker(hdev->migration_blocker);\n\n }\n\n hdev->mem = g_malloc0(offsetof(struct vhost_memory, regions));\n\n hdev->n_mem_sections = 0;\n\n hdev->mem_sections = NULL;\n\n hdev->log = NULL;\n\n hdev->log_size = 0;\n\n hdev->log_enabled = false;\n\n hdev->started = false;\n\n hdev->memory_changed = false;\n\n memory_listener_register(&hdev->memory_listener, &address_space_memory);\n\n return 0;\n\nfail_vq:\n\n while (--i >= 0) {\n\n vhost_virtqueue_cleanup(hdev->vqs + i);\n\n }\n\nfail:\n\n r = -errno;\n\n hdev->vhost_ops->vhost_backend_cleanup(hdev);\n\n return r;\n\n}\n", + "output": "0", + "index": 1488 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl)\n\n{\n\n int i, len;\n\n\n\n if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {\n\n H264Picture *sorted[32];\n\n int cur_poc, list;\n\n int lens[2];\n\n\n\n if (FIELD_PICTURE(h))\n\n cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD];\n\n else\n\n cur_poc = h->cur_pic_ptr->poc;\n\n\n\n for (list = 0; list < 2; list++) {\n\n len = add_sorted(sorted, h->short_ref, h->short_ref_count, cur_poc, 1 ^ list);\n\n len += add_sorted(sorted + len, h->short_ref, h->short_ref_count, cur_poc, 0 ^ list);\n\n av_assert0(len <= 32);\n\n\n\n len = build_def_list(h->default_ref_list[list], FF_ARRAY_ELEMS(h->default_ref_list[0]),\n\n sorted, len, 0, h->picture_structure);\n\n len += build_def_list(h->default_ref_list[list] + len,\n\n FF_ARRAY_ELEMS(h->default_ref_list[0]) - len,\n\n h->long_ref, 16, 1, h->picture_structure);\n\n av_assert0(len <= 32);\n\n\n\n if (len < sl->ref_count[list])\n\n memset(&h->default_ref_list[list][len], 0, sizeof(H264Ref) * (sl->ref_count[list] - len));\n\n lens[list] = len;\n\n }\n\n\n\n if (lens[0] == lens[1] && lens[1] > 1) {\n\n for (i = 0; i < lens[0] &&\n\n h->default_ref_list[0][i].parent->f.buf[0]->buffer ==\n\n h->default_ref_list[1][i].parent->f.buf[0]->buffer; i++);\n\n if (i == lens[0]) {\n\n FFSWAP(H264Ref, h->default_ref_list[1][0], h->default_ref_list[1][1]);\n\n }\n\n }\n\n } else {\n\n len = build_def_list(h->default_ref_list[0], FF_ARRAY_ELEMS(h->default_ref_list[0]),\n\n h->short_ref, h->short_ref_count, 0, h->picture_structure);\n\n len += build_def_list(h->default_ref_list[0] + len,\n\n FF_ARRAY_ELEMS(h->default_ref_list[0]) - len,\n\n h-> long_ref, 16, 1, h->picture_structure);\n\n av_assert0(len <= 32);\n\n\n\n if (len < sl->ref_count[0])\n\n memset(&h->default_ref_list[0][len], 0, sizeof(H264Ref) * (sl->ref_count[0] - len));\n\n }\n\n#ifdef TRACE\n\n for (i = 0; i < sl->ref_count[0]; i++) {\n\n tprintf(h->avctx, \"List0: %s fn:%d 0x%p\\n\",\n\n (h->default_ref_list[0][i].parent->long_ref ? \"LT\" : \"ST\"),\n\n h->default_ref_list[0][i].pic_id,\n\n h->default_ref_list[0][i].parent->f.data[0]);\n\n }\n\n if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {\n\n for (i = 0; i < sl->ref_count[1]; i++) {\n\n tprintf(h->avctx, \"List1: %s fn:%d 0x%p\\n\",\n\n (h->default_ref_list[1][i].parent->long_ref ? \"LT\" : \"ST\"),\n\n h->default_ref_list[1][i].pic_id,\n\n h->default_ref_list[1][i].parent->f.data[0]);\n\n }\n\n }\n\n#endif\n\n return 0;\n\n}\n", + "output": "1", + "index": 24818 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame)\n\n{\n\n AVFilterContext *ctx = inlink->dst;\n\n TrimContext *s = ctx->priv;\n\n int64_t start_sample, end_sample = frame->nb_samples;\n\n int64_t pts;\n\n int drop;\n\n\n\n /* drop everything if EOF has already been returned */\n\n if (s->eof) {\n\n av_frame_free(&frame);\n\n return 0;\n\n }\n\n\n\n if (frame->pts != AV_NOPTS_VALUE)\n\n pts = av_rescale_q(frame->pts, inlink->time_base,\n\n (AVRational){ 1, inlink->sample_rate });\n\n else\n\n pts = s->next_pts;\n\n s->next_pts = pts + frame->nb_samples;\n\n\n\n /* check if at least a part of the frame is after the start time */\n\n if (s->start_sample < 0 && s->start_pts == AV_NOPTS_VALUE) {\n\n start_sample = 0;\n\n } else {\n\n drop = 1;\n\n start_sample = frame->nb_samples;\n\n\n\n if (s->start_sample >= 0 &&\n\n s->nb_samples + frame->nb_samples > s->start_sample) {\n\n drop = 0;\n\n start_sample = FFMIN(start_sample, s->start_sample - s->nb_samples);\n\n }\n\n\n\n if (s->start_pts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE &&\n\n pts + frame->nb_samples > s->start_pts) {\n\n drop = 0;\n\n start_sample = FFMIN(start_sample, s->start_pts - pts);\n\n }\n\n\n\n if (drop)\n\n goto drop;\n\n }\n\n\n\n if (s->first_pts == AV_NOPTS_VALUE)\n\n s->first_pts = pts + start_sample;\n\n\n\n /* check if at least a part of the frame is before the end time */\n\n if (s->end_sample == INT64_MAX && s->end_pts == AV_NOPTS_VALUE && !s->duration_tb) {\n\n end_sample = frame->nb_samples;\n\n } else {\n\n drop = 1;\n\n end_sample = 0;\n\n\n\n if (s->end_sample != INT64_MAX &&\n\n s->nb_samples < s->end_sample) {\n\n drop = 0;\n\n end_sample = FFMAX(end_sample, s->end_sample - s->nb_samples);\n\n }\n\n\n\n if (s->end_pts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE &&\n\n pts < s->end_pts) {\n\n drop = 0;\n\n end_sample = FFMAX(end_sample, s->end_pts - pts);\n\n }\n\n\n\n if (s->duration_tb && pts - s->first_pts < s->duration_tb) {\n\n drop = 0;\n\n end_sample = FFMAX(end_sample, s->first_pts + s->duration_tb - pts);\n\n }\n\n\n\n if (drop) {\n\n s->eof = 1;\n\n goto drop;\n\n }\n\n }\n\n\n\n s->nb_samples += frame->nb_samples;\n\n start_sample = FFMAX(0, start_sample);\n\n end_sample = FFMIN(frame->nb_samples, end_sample);\n\n av_assert0(start_sample < end_sample);\n\n\n\n if (start_sample) {\n\n AVFrame *out = ff_get_audio_buffer(ctx->outputs[0], end_sample - start_sample);\n\n if (!out) {\n\n av_frame_free(&frame);\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n av_frame_copy_props(out, frame);\n\n av_samples_copy(out->extended_data, frame->extended_data, 0, start_sample,\n\n out->nb_samples, av_get_channel_layout_nb_channels(frame->channel_layout),\n\n frame->format);\n\n if (out->pts != AV_NOPTS_VALUE)\n\n out->pts += av_rescale_q(start_sample, (AVRational){ 1, out->sample_rate },\n\n inlink->time_base);\n\n\n\n av_frame_free(&frame);\n\n frame = out;\n\n } else\n\n frame->nb_samples = end_sample;\n\n\n\n s->got_output = 1;\n\n return ff_filter_frame(ctx->outputs[0], frame);\n\n\n\ndrop:\n\n s->nb_samples += frame->nb_samples;\n\n av_frame_free(&frame);\n\n return 0;\n\n}\n", + "output": "0", + "index": 2157 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void x86_cpu_common_class_init(ObjectClass *oc, void *data)\n{\n X86CPUClass *xcc = X86_CPU_CLASS(oc);\n CPUClass *cc = CPU_CLASS(oc);\n DeviceClass *dc = DEVICE_CLASS(oc);\n xcc->parent_realize = dc->realize;\n dc->realize = x86_cpu_realizefn;\n dc->props = x86_cpu_properties;\n xcc->parent_reset = cc->reset;\n cc->reset = x86_cpu_reset;\n cc->reset_dump_flags = CPU_DUMP_FPU | CPU_DUMP_CCOP;\n cc->class_by_name = x86_cpu_class_by_name;\n cc->parse_features = x86_cpu_parse_featurestr;\n cc->has_work = x86_cpu_has_work;\n cc->do_interrupt = x86_cpu_do_interrupt;\n cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;\n cc->dump_state = x86_cpu_dump_state;\n cc->set_pc = x86_cpu_set_pc;\n cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;\n cc->gdb_read_register = x86_cpu_gdb_read_register;\n cc->gdb_write_register = x86_cpu_gdb_write_register;\n cc->get_arch_id = x86_cpu_get_arch_id;\n cc->get_paging_enabled = x86_cpu_get_paging_enabled;\n#ifdef CONFIG_USER_ONLY\n cc->handle_mmu_fault = x86_cpu_handle_mmu_fault;\n#else\n cc->get_memory_mapping = x86_cpu_get_memory_mapping;\n cc->get_phys_page_debug = x86_cpu_get_phys_page_debug;\n cc->write_elf64_note = x86_cpu_write_elf64_note;\n cc->write_elf64_qemunote = x86_cpu_write_elf64_qemunote;\n cc->write_elf32_note = x86_cpu_write_elf32_note;\n cc->write_elf32_qemunote = x86_cpu_write_elf32_qemunote;\n cc->vmsd = &vmstate_x86_cpu;\n#endif\n cc->gdb_num_core_regs = CPU_NB_REGS * 2 + 25;\n#ifndef CONFIG_USER_ONLY\n cc->debug_excp_handler = breakpoint_handler;\n#endif\n cc->cpu_exec_enter = x86_cpu_exec_enter;\n cc->cpu_exec_exit = x86_cpu_exec_exit;\n}", + "output": "1", + "index": 13791 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int mmsh_open(URLContext *h, const char *uri, int flags)\n\n{\n\n int i, port, err;\n\n char httpname[256], path[256], host[128], location[1024];\n\n char *stream_selection;\n\n char headers[1024];\n\n MMSHContext *mmsh;\n\n MMSContext *mms;\n\n\n\n mmsh = h->priv_data = av_mallocz(sizeof(MMSHContext));\n\n if (!h->priv_data)\n\n return AVERROR(ENOMEM);\n\n mmsh->request_seq = h->is_streamed = 1;\n\n mms = &mmsh->mms;\n\n av_strlcpy(location, uri, sizeof(location));\n\n\n\n av_url_split(NULL, 0, NULL, 0,\n\n host, sizeof(host), &port, path, sizeof(path), location);\n\n if (port<0)\n\n port = 80; // default mmsh protocol port\n\n ff_url_join(httpname, sizeof(httpname), \"http\", NULL, host, port, path);\n\n\n\n if (url_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) {\n\n return AVERROR(EIO);\n\n }\n\n\n\n snprintf(headers, sizeof(headers),\n\n \"Accept: */*\\r\\n\"\n\n USERAGENT\n\n \"Host: %s:%d\\r\\n\"\n\n \"Pragma: no-cache,rate=1.000000,stream-time=0,\"\n\n \"stream-offset=0:0,request-context=%u,max-duration=0\\r\\n\"\n\n CLIENTGUID\n\n \"Connection: Close\\r\\n\\r\\n\",\n\n host, port, mmsh->request_seq++);\n\n ff_http_set_headers(mms->mms_hd, headers);\n\n\n\n err = url_connect(mms->mms_hd);\n\n if (err) {\n\n goto fail;\n\n }\n\n err = get_http_header_data(mmsh);\n\n if (err) {\n\n av_log(NULL, AV_LOG_ERROR, \"Get http header data failed!\\n\");\n\n goto fail;\n\n }\n\n\n\n // close the socket and then reopen it for sending the second play request.\n\n url_close(mms->mms_hd);\n\n memset(headers, 0, sizeof(headers));\n\n if (url_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) {\n\n return AVERROR(EIO);\n\n }\n\n stream_selection = av_mallocz(mms->stream_num * 19 + 1);\n\n if (!stream_selection)\n\n return AVERROR(ENOMEM);\n\n for (i = 0; i < mms->stream_num; i++) {\n\n char tmp[20];\n\n err = snprintf(tmp, sizeof(tmp), \"ffff:%d:0 \", mms->streams[i].id);\n\n if (err < 0)\n\n goto fail;\n\n av_strlcat(stream_selection, tmp, mms->stream_num * 19 + 1);\n\n }\n\n // send play request\n\n err = snprintf(headers, sizeof(headers),\n\n \"Accept: */*\\r\\n\"\n\n USERAGENT\n\n \"Host: %s:%d\\r\\n\"\n\n \"Pragma: no-cache,rate=1.000000,request-context=%u\\r\\n\"\n\n \"Pragma: xPlayStrm=1\\r\\n\"\n\n CLIENTGUID\n\n \"Pragma: stream-switch-count=%d\\r\\n\"\n\n \"Pragma: stream-switch-entry=%s\\r\\n\"\n\n \"Connection: Close\\r\\n\\r\\n\",\n\n host, port, mmsh->request_seq++, mms->stream_num, stream_selection);\n\n av_freep(&stream_selection);\n\n if (err < 0) {\n\n av_log(NULL, AV_LOG_ERROR, \"Build play request failed!\\n\");\n\n goto fail;\n\n }\n\n dprintf(NULL, \"out_buffer is %s\", headers);\n\n ff_http_set_headers(mms->mms_hd, headers);\n\n\n\n err = url_connect(mms->mms_hd);\n\n if (err) {\n\n goto fail;\n\n }\n\n\n\n err = get_http_header_data(mmsh);\n\n if (err) {\n\n av_log(NULL, AV_LOG_ERROR, \"Get http header data failed!\\n\");\n\n goto fail;\n\n }\n\n\n\n dprintf(NULL, \"Connection successfully open\\n\");\n\n return 0;\n\nfail:\n\n av_freep(&stream_selection);\n\n mmsh_close(h);\n\n dprintf(NULL, \"Connection failed with error %d\\n\", err);\n\n return err;\n\n}\n", + "output": "1", + "index": 8735 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,\n\n TCGMemOpIdx oi, uintptr_t retaddr)\n\n{\n\n size_t mmu_idx = get_mmuidx(oi);\n\n size_t index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);\n\n CPUTLBEntry *tlbe = &env->tlb_table[mmu_idx][index];\n\n target_ulong tlb_addr = tlbe->addr_write;\n\n TCGMemOp mop = get_memop(oi);\n\n int a_bits = get_alignment_bits(mop);\n\n int s_bits = mop & MO_SIZE;\n\n\n\n /* Adjust the given return address. */\n\n retaddr -= GETPC_ADJ;\n\n\n\n /* Enforce guest required alignment. */\n\n if (unlikely(a_bits > 0 && (addr & ((1 << a_bits) - 1)))) {\n\n /* ??? Maybe indicate atomic op to cpu_unaligned_access */\n\n cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE,\n\n mmu_idx, retaddr);\n\n }\n\n\n\n /* Enforce qemu required alignment. */\n\n if (unlikely(addr & ((1 << s_bits) - 1))) {\n\n /* We get here if guest alignment was not requested,\n\n or was not enforced by cpu_unaligned_access above.\n\n We might widen the access and emulate, but for now\n\n mark an exception and exit the cpu loop. */\n\n goto stop_the_world;\n\n }\n\n\n\n /* Check TLB entry and enforce page permissions. */\n\n if ((addr & TARGET_PAGE_MASK)\n\n != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {\n\n if (!VICTIM_TLB_HIT(addr_write, addr)) {\n\n tlb_fill(ENV_GET_CPU(env), addr, MMU_DATA_STORE, mmu_idx, retaddr);\n\n }\n\n tlb_addr = tlbe->addr_write;\n\n }\n\n\n\n /* Check notdirty */\n\n if (unlikely(tlb_addr & TLB_NOTDIRTY)) {\n\n tlb_set_dirty(ENV_GET_CPU(env), addr);\n\n tlb_addr = tlb_addr & ~TLB_NOTDIRTY;\n\n }\n\n\n\n /* Notice an IO access */\n\n if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) {\n\n /* There's really nothing that can be done to\n\n support this apart from stop-the-world. */\n\n goto stop_the_world;\n\n }\n\n\n\n /* Let the guest notice RMW on a write-only page. */\n\n if (unlikely(tlbe->addr_read != tlb_addr)) {\n\n tlb_fill(ENV_GET_CPU(env), addr, MMU_DATA_LOAD, mmu_idx, retaddr);\n\n /* Since we don't support reads and writes to different addresses,\n\n and we do have the proper page loaded for write, this shouldn't\n\n ever return. But just in case, handle via stop-the-world. */\n\n goto stop_the_world;\n\n }\n\n\n\n return (void *)((uintptr_t)addr + tlbe->addend);\n\n\n\n stop_the_world:\n\n cpu_loop_exit_atomic(ENV_GET_CPU(env), retaddr);\n\n}\n", + "output": "0", + "index": 5801 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)\n\n{\n\n const AVCodec *orig_codec = dest->codec;\n\n uint8_t *orig_priv_data = dest->priv_data;\n\n\n\n if (avcodec_is_open(dest)) { // check that the dest context is uninitialized\n\n av_log(dest, AV_LOG_ERROR,\n\n \"Tried to copy AVCodecContext %p into already-initialized %p\\n\",\n\n src, dest);\n\n return AVERROR(EINVAL);\n\n }\n\n\n\n copy_context_reset(dest);\n\n\n\n memcpy(dest, src, sizeof(*dest));\n\n av_opt_copy(dest, src);\n\n\n\n dest->priv_data = orig_priv_data;\n\n dest->codec = orig_codec;\n\n\n\n if (orig_priv_data && src->codec && src->codec->priv_class &&\n\n dest->codec && dest->codec->priv_class)\n\n av_opt_copy(orig_priv_data, src->priv_data);\n\n\n\n\n\n /* set values specific to opened codecs back to their default state */\n\n dest->slice_offset = NULL;\n\n dest->hwaccel = NULL;\n\n dest->internal = NULL;\n\n#if FF_API_CODED_FRAME\n\nFF_DISABLE_DEPRECATION_WARNINGS\n\n dest->coded_frame = NULL;\n\nFF_ENABLE_DEPRECATION_WARNINGS\n\n#endif\n\n\n\n /* reallocate values that should be allocated separately */\n\n dest->extradata = NULL;\n\n\n dest->intra_matrix = NULL;\n\n dest->inter_matrix = NULL;\n\n dest->rc_override = NULL;\n\n dest->subtitle_header = NULL;\n\n dest->hw_frames_ctx = NULL;\n\n\n\n\n\n#define alloc_and_copy_or_fail(obj, size, pad) \\\n\n if (src->obj && size > 0) { \\\n\n dest->obj = av_malloc(size + pad); \\\n\n if (!dest->obj) \\\n\n goto fail; \\\n\n memcpy(dest->obj, src->obj, size); \\\n\n if (pad) \\\n\n memset(((uint8_t *) dest->obj) + size, 0, pad); \\\n\n }\n\n alloc_and_copy_or_fail(extradata, src->extradata_size,\n\n AV_INPUT_BUFFER_PADDING_SIZE);\n\n dest->extradata_size = src->extradata_size;\n\n alloc_and_copy_or_fail(intra_matrix, 64 * sizeof(int16_t), 0);\n\n alloc_and_copy_or_fail(inter_matrix, 64 * sizeof(int16_t), 0);\n\n alloc_and_copy_or_fail(rc_override, src->rc_override_count * sizeof(*src->rc_override), 0);\n\n alloc_and_copy_or_fail(subtitle_header, src->subtitle_header_size, 1);\n\n av_assert0(dest->subtitle_header_size == src->subtitle_header_size);\n\n#undef alloc_and_copy_or_fail\n\n\n\n if (src->hw_frames_ctx) {\n\n dest->hw_frames_ctx = av_buffer_ref(src->hw_frames_ctx);\n\n if (!dest->hw_frames_ctx)\n\n goto fail;\n\n }\n\n\n\n return 0;\n\n\n\nfail:\n\n copy_context_reset(dest);\n\n return AVERROR(ENOMEM);\n\n}", + "output": "1", + "index": 12926 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int cinvideo_decode_frame(AVCodecContext *avctx,\n\n void *data, int *data_size,\n\n AVPacket *avpkt)\n\n{\n\n const uint8_t *buf = avpkt->data;\n\n int buf_size = avpkt->size;\n\n CinVideoContext *cin = avctx->priv_data;\n\n int i, y, palette_type, palette_colors_count, bitmap_frame_type, bitmap_frame_size;\n\n\n\n cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;\n\n if (avctx->reget_buffer(avctx, &cin->frame)) {\n\n av_log(cin->avctx, AV_LOG_ERROR, \"delphinecinvideo: reget_buffer() failed to allocate a frame\\n\");\n\n return -1;\n\n }\n\n\n\n palette_type = buf[0];\n\n palette_colors_count = AV_RL16(buf+1);\n\n bitmap_frame_type = buf[3];\n\n buf += 4;\n\n\n\n bitmap_frame_size = buf_size - 4;\n\n\n\n /* handle palette */\n\n\n\n if (palette_type == 0) {\n\n for (i = 0; i < palette_colors_count; ++i) {\n\n cin->palette[i] = bytestream_get_le24(&buf);\n\n bitmap_frame_size -= 3;\n\n }\n\n } else {\n\n for (i = 0; i < palette_colors_count; ++i) {\n\n cin->palette[buf[0]] = AV_RL24(buf+1);\n\n buf += 4;\n\n bitmap_frame_size -= 4;\n\n }\n\n }\n\n memcpy(cin->frame.data[1], cin->palette, sizeof(cin->palette));\n\n cin->frame.palette_has_changed = 1;\n\n\n\n /* note: the decoding routines below assumes that surface.width = surface.pitch */\n\n switch (bitmap_frame_type) {\n\n case 9:\n\n cin_decode_rle(buf, bitmap_frame_size,\n\n cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);\n\n break;\n\n case 34:\n\n cin_decode_rle(buf, bitmap_frame_size,\n\n cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);\n\n cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],\n\n cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);\n\n break;\n\n case 35:\n\n cin_decode_huffman(buf, bitmap_frame_size,\n\n cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);\n\n cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size,\n\n cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);\n\n break;\n\n case 36:\n\n bitmap_frame_size = cin_decode_huffman(buf, bitmap_frame_size,\n\n cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);\n\n cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size,\n\n cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);\n\n cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],\n\n cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);\n\n break;\n\n case 37:\n\n cin_decode_huffman(buf, bitmap_frame_size,\n\n cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);\n\n break;\n\n case 38:\n\n cin_decode_lzss(buf, bitmap_frame_size,\n\n cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);\n\n break;\n\n case 39:\n\n cin_decode_lzss(buf, bitmap_frame_size,\n\n cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);\n\n cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],\n\n cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);\n\n break;\n\n }\n\n\n\n for (y = 0; y < cin->avctx->height; ++y)\n\n memcpy(cin->frame.data[0] + (cin->avctx->height - 1 - y) * cin->frame.linesize[0],\n\n cin->bitmap_table[CIN_CUR_BMP] + y * cin->avctx->width,\n\n cin->avctx->width);\n\n\n\n FFSWAP(uint8_t *, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_table[CIN_PRE_BMP]);\n\n\n\n *data_size = sizeof(AVFrame);\n\n *(AVFrame *)data = cin->frame;\n\n\n\n return buf_size;\n\n}", + "output": "1", + "index": 22635 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void RENAME(rgb32tobgr32)(const uint8_t *src, uint8_t *dst, unsigned int src_size)\n\n{\n\n#ifdef HAVE_MMX\n\n/* TODO: unroll this loop */\n\n\tasm volatile (\n\n\t\t\"xor %%\"REG_a\", %%\"REG_a\"\t\\n\\t\"\n\n\t\t\".balign 16\t\t\t\\n\\t\"\n\n\t\t\"1:\t\t\t\t\\n\\t\"\n\n\t\tPREFETCH\" 32(%0, %%\"REG_a\")\t\\n\\t\"\n\n\t\t\"movq (%0, %%\"REG_a\"), %%mm0\t\\n\\t\"\n\n\t\t\"movq %%mm0, %%mm1\t\t\\n\\t\"\n\n\t\t\"movq %%mm0, %%mm2\t\t\\n\\t\"\n\n\t\t\"pslld $16, %%mm0\t\t\\n\\t\"\n\n\t\t\"psrld $16, %%mm1\t\t\\n\\t\"\n\n\t\t\"pand \"MANGLE(mask32r)\", %%mm0\t\\n\\t\"\n\n\t\t\"pand \"MANGLE(mask32g)\", %%mm2\t\\n\\t\"\n\n\t\t\"pand \"MANGLE(mask32b)\", %%mm1\t\\n\\t\"\n\n\t\t\"por %%mm0, %%mm2\t\t\\n\\t\"\n\n\t\t\"por %%mm1, %%mm2\t\t\\n\\t\"\n\n\t\tMOVNTQ\" %%mm2, (%1, %%\"REG_a\")\t\\n\\t\"\n\n\t\t\"add $8, %%\"REG_a\"\t\t\\n\\t\"\n\n\t\t\"cmp %2, %%\"REG_a\"\t\t\\n\\t\"\n\n\t\t\" jb 1b\t\t\t\t\\n\\t\"\n\n\t\t:: \"r\" (src), \"r\"(dst), \"r\" ((long)src_size-7)\n\n\t\t: \"%\"REG_a\n\n\t);\n\n\n\n\t__asm __volatile(SFENCE:::\"memory\");\n\n\t__asm __volatile(EMMS:::\"memory\");\n\n#else\n\n\tunsigned i;\n\n\tunsigned num_pixels = src_size >> 2;\n\n\tfor(i=0; is;\n\n\n\n if (s->proto_version == V9FS_PROTO_2000L) {\n\n pdu_unmarshal(pdu, offset, \"dd\", &fid, &mode);\n\n } else {\n\n pdu_unmarshal(pdu, offset, \"db\", &fid, &mode);\n\n }\n\n trace_v9fs_open(pdu->tag, pdu->id, fid, mode);\n\n\n\n fidp = get_fid(pdu, fid);\n\n if (fidp == NULL) {\n\n err = -ENOENT;\n\n goto out_nofid;\n\n }\n\n BUG_ON(fidp->fid_type != P9_FID_NONE);\n\n\n\n err = v9fs_co_lstat(pdu, &fidp->path, &stbuf);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n stat_to_qid(&stbuf, &qid);\n\n if (S_ISDIR(stbuf.st_mode)) {\n\n err = v9fs_co_opendir(pdu, fidp);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n fidp->fid_type = P9_FID_DIR;\n\n offset += pdu_marshal(pdu, offset, \"Qd\", &qid, 0);\n\n err = offset;\n\n } else {\n\n if (s->proto_version == V9FS_PROTO_2000L) {\n\n flags = get_dotl_openflags(s, mode);\n\n } else {\n\n flags = omode_to_uflags(mode);\n\n }\n\n if (is_ro_export(&s->ctx)) {\n\n if (mode & O_WRONLY || mode & O_RDWR ||\n\n mode & O_APPEND || mode & O_TRUNC) {\n\n err = -EROFS;\n\n goto out;\n\n }\n\n flags |= O_NOATIME;\n\n }\n\n err = v9fs_co_open(pdu, fidp, flags);\n\n if (err < 0) {\n\n goto out;\n\n }\n\n fidp->fid_type = P9_FID_FILE;\n\n fidp->open_flags = flags;\n\n if (flags & O_EXCL) {\n\n /*\n\n * We let the host file system do O_EXCL check\n\n * We should not reclaim such fd\n\n */\n\n fidp->flags |= FID_NON_RECLAIMABLE;\n\n }\n\n iounit = get_iounit(pdu, &fidp->path);\n\n offset += pdu_marshal(pdu, offset, \"Qd\", &qid, iounit);\n\n err = offset;\n\n }\n\n trace_v9fs_open_return(pdu->tag, pdu->id,\n\n qid.type, qid.version, qid.path, iounit);\n\nout:\n\n put_fid(pdu, fidp);\n\nout_nofid:\n\n complete_pdu(s, pdu, err);\n\n}\n", + "output": "0", + "index": 7371 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int tls_open(URLContext *h, const char *uri, int flags)\n\n{\n\n TLSContext *c = h->priv_data;\n\n int ret;\n\n int port;\n\n char buf[200], host[200];\n\n int numerichost = 0;\n\n struct addrinfo hints = { 0 }, *ai = NULL;\n\n const char *proxy_path;\n\n int use_proxy;\n\n\n\n ff_tls_init();\n\n\n\n av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0, uri);\n\n ff_url_join(buf, sizeof(buf), \"tcp\", NULL, host, port, NULL);\n\n\n\n hints.ai_flags = AI_NUMERICHOST;\n\n if (!getaddrinfo(host, NULL, &hints, &ai)) {\n\n numerichost = 1;\n\n freeaddrinfo(ai);\n\n }\n\n\n\n proxy_path = getenv(\"http_proxy\");\n\n use_proxy = !ff_http_match_no_proxy(getenv(\"no_proxy\"), host) &&\n\n proxy_path != NULL && av_strstart(proxy_path, \"http://\", NULL);\n\n\n\n if (use_proxy) {\n\n char proxy_host[200], proxy_auth[200], dest[200];\n\n int proxy_port;\n\n av_url_split(NULL, 0, proxy_auth, sizeof(proxy_auth),\n\n proxy_host, sizeof(proxy_host), &proxy_port, NULL, 0,\n\n proxy_path);\n\n ff_url_join(dest, sizeof(dest), NULL, NULL, host, port, NULL);\n\n ff_url_join(buf, sizeof(buf), \"httpproxy\", proxy_auth, proxy_host,\n\n proxy_port, \"/%s\", dest);\n\n }\n\n\n\n ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE,\n\n &h->interrupt_callback, NULL);\n\n if (ret)\n\n goto fail;\n\n c->fd = ffurl_get_file_handle(c->tcp);\n\n\n\n#if CONFIG_GNUTLS\n\n gnutls_init(&c->session, GNUTLS_CLIENT);\n\n if (!numerichost)\n\n gnutls_server_name_set(c->session, GNUTLS_NAME_DNS, host, strlen(host));\n\n gnutls_certificate_allocate_credentials(&c->cred);\n\n gnutls_certificate_set_verify_flags(c->cred, 0);\n\n gnutls_credentials_set(c->session, GNUTLS_CRD_CERTIFICATE, c->cred);\n\n gnutls_transport_set_ptr(c->session, (gnutls_transport_ptr_t)\n\n (intptr_t) c->fd);\n\n gnutls_priority_set_direct(c->session, \"NORMAL\", NULL);\n\n while (1) {\n\n ret = gnutls_handshake(c->session);\n\n if (ret == 0)\n\n break;\n\n if ((ret = do_tls_poll(h, ret)) < 0)\n\n goto fail;\n\n }\n\n#elif CONFIG_OPENSSL\n\n c->ctx = SSL_CTX_new(TLSv1_client_method());\n\n if (!c->ctx) {\n\n av_log(h, AV_LOG_ERROR, \"%s\\n\", ERR_error_string(ERR_get_error(), NULL));\n\n ret = AVERROR(EIO);\n\n goto fail;\n\n }\n\n c->ssl = SSL_new(c->ctx);\n\n if (!c->ssl) {\n\n av_log(h, AV_LOG_ERROR, \"%s\\n\", ERR_error_string(ERR_get_error(), NULL));\n\n ret = AVERROR(EIO);\n\n goto fail;\n\n }\n\n SSL_set_fd(c->ssl, c->fd);\n\n if (!numerichost)\n\n SSL_set_tlsext_host_name(c->ssl, host);\n\n while (1) {\n\n ret = SSL_connect(c->ssl);\n\n if (ret > 0)\n\n break;\n\n if (ret == 0) {\n\n av_log(h, AV_LOG_ERROR, \"Unable to negotiate TLS/SSL session\\n\");\n\n ret = AVERROR(EIO);\n\n goto fail;\n\n }\n\n if ((ret = do_tls_poll(h, ret)) < 0)\n\n goto fail;\n\n }\n\n#endif\n\n return 0;\n\nfail:\n\n TLS_free(c);\n\n if (c->tcp)\n\n ffurl_close(c->tcp);\n\n ff_tls_deinit();\n\n return ret;\n\n}\n", + "output": "1", + "index": 8413 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, unsigned src_size)\n\n{\n\n\tconst uint8_t *s = src;\n\n\tconst uint8_t *end;\n\n#ifdef HAVE_MMX\n\n\tconst uint8_t *mm_end;\n\n#endif\n\n\tuint16_t *d = (uint16_t *)dst;\n\n\tend = s + src_size;\n\n#ifdef HAVE_MMX\n\n\t__asm __volatile(PREFETCH\"\t%0\"::\"m\"(*src):\"memory\");\n\n\t__asm __volatile(\n\n\t \"movq\t%0, %%mm7\\n\\t\"\n\n\t \"movq\t%1, %%mm6\\n\\t\"\n\n\t ::\"m\"(red_15mask),\"m\"(green_15mask));\n\n\tmm_end = end - 15;\n\n\twhile(s < mm_end)\n\n\t{\n\n\t __asm __volatile(\n\n\t\tPREFETCH\" 32%1\\n\\t\"\n\n\t\t\"movd\t%1, %%mm0\\n\\t\"\n\n\t\t\"movd\t4%1, %%mm3\\n\\t\"\n\n\t\t\"punpckldq 8%1, %%mm0\\n\\t\"\n\n\t\t\"punpckldq 12%1, %%mm3\\n\\t\"\n\n\t\t\"movq\t%%mm0, %%mm1\\n\\t\"\n\n\t\t\"movq\t%%mm0, %%mm2\\n\\t\"\n\n\t\t\"movq\t%%mm3, %%mm4\\n\\t\"\n\n\t\t\"movq\t%%mm3, %%mm5\\n\\t\"\n\n\t\t\"psllq\t$7, %%mm0\\n\\t\"\n\n\t\t\"psllq\t$7, %%mm3\\n\\t\"\n\n\t\t\"pand\t%%mm7, %%mm0\\n\\t\"\n\n\t\t\"pand\t%%mm7, %%mm3\\n\\t\"\n\n\t\t\"psrlq\t$6, %%mm1\\n\\t\"\n\n\t\t\"psrlq\t$6, %%mm4\\n\\t\"\n\n\t\t\"pand\t%%mm6, %%mm1\\n\\t\"\n\n\t\t\"pand\t%%mm6, %%mm4\\n\\t\"\n\n\t\t\"psrlq\t$19, %%mm2\\n\\t\"\n\n\t\t\"psrlq\t$19, %%mm5\\n\\t\"\n\n\t\t\"pand\t%2, %%mm2\\n\\t\"\n\n\t\t\"pand\t%2, %%mm5\\n\\t\"\n\n\t\t\"por\t%%mm1, %%mm0\\n\\t\"\n\n\t\t\"por\t%%mm4, %%mm3\\n\\t\"\n\n\t\t\"por\t%%mm2, %%mm0\\n\\t\"\n\n\t\t\"por\t%%mm5, %%mm3\\n\\t\"\n\n\t\t\"psllq\t$16, %%mm3\\n\\t\"\n\n\t\t\"por\t%%mm3, %%mm0\\n\\t\"\n\n\t\tMOVNTQ\"\t%%mm0, %0\\n\\t\"\n\n\t\t:\"=m\"(*d):\"m\"(*s),\"m\"(blue_15mask):\"memory\");\n\n\t\td += 4;\n\n\t\ts += 16;\n\n\t}\n\n\t__asm __volatile(SFENCE:::\"memory\");\n\n\t__asm __volatile(EMMS:::\"memory\");\n\n#endif\n\n\twhile(s < end)\n\n\t{\n\n\t\t// FIXME on bigendian\n\n\t\tconst int src= *s; s += 4;\n\n\t\t*d++ = ((src&0xF8)<<7) + ((src&0xF800)>>6) + ((src&0xF80000)>>19);\n\n\t}\n\n}\n", + "output": "1", + "index": 6474 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void asv2_encode_block(ASV1Context *a, int16_t block[64])\n\n{\n\n int i;\n\n int count = 0;\n\n\n\n for (count = 63; count > 3; count--) {\n\n const int index = ff_asv_scantab[count];\n\n if ((block[index] * a->q_intra_matrix[index] + (1 << 15)) >> 16)\n\n break;\n\n }\n\n\n\n count >>= 2;\n\n\n\n asv2_put_bits(&a->pb, 4, count);\n\n asv2_put_bits(&a->pb, 8, (block[0] + 32) >> 6);\n\n block[0] = 0;\n\n\n\n for (i = 0; i <= count; i++) {\n\n const int index = ff_asv_scantab[4 * i];\n\n int ccp = 0;\n\n\n\n if ((block[index + 0] = (block[index + 0] *\n\n a->q_intra_matrix[index + 0] + (1 << 15)) >> 16))\n\n ccp |= 8;\n\n if ((block[index + 8] = (block[index + 8] *\n\n a->q_intra_matrix[index + 8] + (1 << 15)) >> 16))\n\n ccp |= 4;\n\n if ((block[index + 1] = (block[index + 1] *\n\n a->q_intra_matrix[index + 1] + (1 << 15)) >> 16))\n\n ccp |= 2;\n\n if ((block[index + 9] = (block[index + 9] *\n\n a->q_intra_matrix[index + 9] + (1 << 15)) >> 16))\n\n ccp |= 1;\n\n\n\n av_assert2(i || ccp < 8);\n\n if (i)\n\n put_bits(&a->pb, ff_asv_ac_ccp_tab[ccp][1], ff_asv_ac_ccp_tab[ccp][0]);\n\n else\n\n put_bits(&a->pb, ff_asv_dc_ccp_tab[ccp][1], ff_asv_dc_ccp_tab[ccp][0]);\n\n\n\n if (ccp) {\n\n if (ccp & 8)\n\n asv2_put_level(&a->pb, block[index + 0]);\n\n if (ccp & 4)\n\n asv2_put_level(&a->pb, block[index + 8]);\n\n if (ccp & 2)\n\n asv2_put_level(&a->pb, block[index + 1]);\n\n if (ccp & 1)\n\n asv2_put_level(&a->pb, block[index + 9]);\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 6518 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int filter_frame(AVFilterLink *inlink, AVFrame *buf)\n\n{\n\n AVFilterContext *ctx = inlink->dst;\n\n AVFilterLink *outlink = ctx->outputs[0];\n\n DeflickerContext *s = ctx->priv;\n\n AVDictionary **metadata;\n\n AVFrame *out, *in;\n\n float f;\n\n int y;\n\n\n\n if (s->q.available < s->size && !s->eof) {\n\n s->luminance[s->available] = s->calc_avgy(ctx, buf);\n\n ff_bufqueue_add(ctx, &s->q, buf);\n\n s->available++;\n\n return 0;\n\n }\n\n\n\n in = ff_bufqueue_peek(&s->q, 0);\n\n\n\n out = ff_get_video_buffer(outlink, outlink->w, outlink->h);\n\n if (!out) {\n\n av_frame_free(&buf);\n\n return AVERROR(ENOMEM);\n\n }\n\n\n\n s->get_factor(ctx, &f);\n\n s->deflicker(ctx, in->data[0], in->linesize[0], out->data[0], out->linesize[0],\n\n outlink->w, outlink->h, f);\n\n for (y = 1; y < s->nb_planes; y++) {\n\n av_image_copy_plane(out->data[y], out->linesize[y],\n\n in->data[y], in->linesize[y],\n\n s->planewidth[y] * (1 + (s->depth > 8)), s->planeheight[y]);\n\n }\n\n\n\n av_frame_copy_props(out, in);\n\n metadata = &out->metadata;\n\n if (metadata) {\n\n uint8_t value[128];\n\n\n\n snprintf(value, sizeof(value), \"%f\", s->luminance[0]);\n\n av_dict_set(metadata, \"lavfi.deflicker.luminance\", value, 0);\n\n\n\n snprintf(value, sizeof(value), \"%f\", s->luminance[0] * f);\n\n av_dict_set(metadata, \"lavfi.deflicker.new_luminance\", value, 0);\n\n\n\n snprintf(value, sizeof(value), \"%f\", f - 1.0f);\n\n av_dict_set(metadata, \"lavfi.deflicker.relative_change\", value, 0);\n\n }\n\n\n\n in = ff_bufqueue_get(&s->q);\n\n av_frame_free(&in);\n\n memmove(&s->luminance[0], &s->luminance[1], sizeof(*s->luminance) * (s->size - 1));\n\n s->luminance[s->available - 1] = s->calc_avgy(ctx, buf);\n\n ff_bufqueue_add(ctx, &s->q, buf);\n\n\n\n return ff_filter_frame(outlink, out);\n\n}\n", + "output": "0", + "index": 27104 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int clv_decode_frame(AVCodecContext *avctx, void *data,\n\n int *got_frame, AVPacket *avpkt)\n\n{\n\n const uint8_t *buf = avpkt->data;\n\n int buf_size = avpkt->size;\n\n CLVContext *c = avctx->priv_data;\n\n GetByteContext gb;\n\n uint32_t frame_type;\n\n int i, j;\n\n int ret;\n\n int mb_ret = 0;\n\n\n\n bytestream2_init(&gb, buf, buf_size);\n\n if (avctx->codec_tag == MKTAG('C','L','V','1')) {\n\n int skip = bytestream2_get_byte(&gb);\n\n bytestream2_skip(&gb, (skip + 1) * 8);\n\n }\n\n\n\n frame_type = bytestream2_get_byte(&gb);\n\n if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)\n\n return ret;\n\n\n\n c->pic->key_frame = frame_type & 0x20 ? 1 : 0;\n\n c->pic->pict_type = frame_type & 0x20 ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;\n\n\n\n if (frame_type & 0x2) {\n\n if (buf_size < c->mb_width * c->mb_height) {\n\n av_log(avctx, AV_LOG_ERROR, \"Packet too small\\n\");\n\n return AVERROR_INVALIDDATA;\n\n }\n\n\n\n bytestream2_get_be32(&gb); // frame size;\n\n c->ac_quant = bytestream2_get_byte(&gb);\n\n c->luma_dc_quant = 32;\n\n c->chroma_dc_quant = 32;\n\n\n\n if ((ret = init_get_bits8(&c->gb, buf + bytestream2_tell(&gb),\n\n (buf_size - bytestream2_tell(&gb)))) < 0)\n\n return ret;\n\n\n\n for (i = 0; i < 3; i++)\n\n c->top_dc[i] = 32;\n\n for (i = 0; i < 4; i++)\n\n c->left_dc[i] = 32;\n\n\n\n for (j = 0; j < c->mb_height; j++) {\n\n for (i = 0; i < c->mb_width; i++) {\n\n ret = decode_mb(c, i, j);\n\n if (ret < 0)\n\n mb_ret = ret;\n\n }\n\n }\n\n } else {\n\n }\n\n\n\n if ((ret = av_frame_ref(data, c->pic)) < 0)\n\n return ret;\n\n\n\n *got_frame = 1;\n\n\n\n return mb_ret < 0 ? mb_ret : buf_size;\n\n}\n", + "output": "1", + "index": 13938 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void mpcore_priv_map_setup(mpcore_priv_state *s)\n\n{\n\n int i;\n\n SysBusDevice *gicbusdev = sysbus_from_qdev(s->gic);\n\n SysBusDevice *busdev = sysbus_from_qdev(s->mptimer);\n\n memory_region_init(&s->container, \"mpcode-priv-container\", 0x2000);\n\n memory_region_init_io(&s->iomem, &mpcore_scu_ops, s, \"mpcore-scu\", 0x100);\n\n memory_region_add_subregion(&s->container, 0, &s->iomem);\n\n /* GIC CPU interfaces: \"current CPU\" at 0x100, then specific CPUs\n\n * at 0x200, 0x300...\n\n */\n\n for (i = 0; i < (s->num_cpu + 1); i++) {\n\n target_phys_addr_t offset = 0x100 + (i * 0x100);\n\n memory_region_add_subregion(&s->container, offset,\n\n sysbus_mmio_get_region(gicbusdev, i + 1));\n\n }\n\n /* Add the regions for timer and watchdog for \"current CPU\" and\n\n * for each specific CPU.\n\n */\n\n for (i = 0; i < (s->num_cpu + 1) * 2; i++) {\n\n /* Timers at 0x600, 0x700, ...; watchdogs at 0x620, 0x720, ... */\n\n target_phys_addr_t offset = 0x600 + (i >> 1) * 0x100 + (i & 1) * 0x20;\n\n memory_region_add_subregion(&s->container, offset,\n\n sysbus_mmio_get_region(busdev, i));\n\n }\n\n memory_region_add_subregion(&s->container, 0x1000,\n\n sysbus_mmio_get_region(gicbusdev, 0));\n\n /* Wire up the interrupt from each watchdog and timer.\n\n * For each core the timer is PPI 29 and the watchdog PPI 30.\n\n */\n\n for (i = 0; i < s->num_cpu; i++) {\n\n int ppibase = (s->num_irq - 32) + i * 32;\n\n sysbus_connect_irq(busdev, i * 2,\n\n qdev_get_gpio_in(s->gic, ppibase + 29));\n\n sysbus_connect_irq(busdev, i * 2 + 1,\n\n qdev_get_gpio_in(s->gic, ppibase + 30));\n\n }\n\n}\n", + "output": "0", + "index": 21428 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int asf_build_simple_index(AVFormatContext *s, int stream_index)\n{\n ff_asf_guid g;\n ASFContext *asf = s->priv_data;\n int64_t current_pos = avio_tell(s->pb);\n int64_t ret;\n if((ret = avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET)) < 0) {\n return ret;\n if ((ret = ff_get_guid(s->pb, &g)) < 0)\n /* the data object can be followed by other top-level objects,\n * skip them until the simple index object is reached */\n while (ff_guidcmp(&g, &ff_asf_simple_index_header)) {\n int64_t gsize = avio_rl64(s->pb);\n if (gsize < 24 || avio_feof(s->pb)) {\n avio_skip(s->pb, gsize - 24);\n if ((ret = ff_get_guid(s->pb, &g)) < 0)\n {\n int64_t itime, last_pos = -1;\n int pct, ict;\n int i;\n int64_t av_unused gsize = avio_rl64(s->pb);\n if ((ret = ff_get_guid(s->pb, &g)) < 0)\n itime = avio_rl64(s->pb);\n pct = avio_rl32(s->pb);\n ict = avio_rl32(s->pb);\n av_log(s, AV_LOG_DEBUG,\n \"itime:0x%\"PRIx64\", pct:%d, ict:%d\\n\", itime, pct, ict);\n for (i = 0; i < ict; i++) {\n int pktnum = avio_rl32(s->pb);\n int pktct = avio_rl16(s->pb);\n int64_t pos = s->internal->data_offset + s->packet_size * (int64_t)pktnum;\n int64_t index_pts = FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);\n if (pos != last_pos) {\n av_log(s, AV_LOG_DEBUG, \"pktnum:%d, pktct:%d pts: %\"PRId64\"\\n\",\n pktnum, pktct, index_pts);\n av_add_index_entry(s->streams[stream_index], pos, index_pts,\n s->packet_size, 0, AVINDEX_KEYFRAME);\n last_pos = pos;\n asf->index_read = ict > 1;\nend:\n// if (avio_feof(s->pb)) {\n// ret = 0;\n// }\n avio_seek(s->pb, current_pos, SEEK_SET);\n return ret;", + "output": "1", + "index": 1823 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int w, int h)\n\n{\n\n BitBuf bb;\n\n int res, val;\n\n int i, j;\n\n int bx, by;\n\n int l0x, l1x, l0y, l1y;\n\n int mx, my;\n\n\n\n kmvc_init_getbits(bb, src);\n\n\n\n for (by = 0; by < h; by += 8)\n\n for (bx = 0; bx < w; bx += 8) {\n\n kmvc_getbit(bb, src, res);\n\n if (!res) { // fill whole 8x8 block\n\n val = *src++;\n\n for (i = 0; i < 64; i++)\n\n BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val;\n\n } else { // handle four 4x4 subblocks\n\n for (i = 0; i < 4; i++) {\n\n l0x = bx + (i & 1) * 4;\n\n l0y = by + (i & 2) * 2;\n\n kmvc_getbit(bb, src, res);\n\n if (!res) {\n\n kmvc_getbit(bb, src, res);\n\n if (!res) { // fill whole 4x4 block\n\n val = *src++;\n\n for (j = 0; j < 16; j++)\n\n BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val;\n\n } else { // copy block from already decoded place\n\n val = *src++;\n\n mx = val & 0xF;\n\n my = val >> 4;\n\n for (j = 0; j < 16; j++)\n\n BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) =\n\n BLK(ctx->cur, l0x + (j & 3) - mx, l0y + (j >> 2) - my);\n\n }\n\n } else { // descend to 2x2 sub-sub-blocks\n\n for (j = 0; j < 4; j++) {\n\n l1x = l0x + (j & 1) * 2;\n\n l1y = l0y + (j & 2);\n\n kmvc_getbit(bb, src, res);\n\n if (!res) {\n\n kmvc_getbit(bb, src, res);\n\n if (!res) { // fill whole 2x2 block\n\n val = *src++;\n\n BLK(ctx->cur, l1x, l1y) = val;\n\n BLK(ctx->cur, l1x + 1, l1y) = val;\n\n BLK(ctx->cur, l1x, l1y + 1) = val;\n\n BLK(ctx->cur, l1x + 1, l1y + 1) = val;\n\n } else { // copy block from already decoded place\n\n val = *src++;\n\n mx = val & 0xF;\n\n my = val >> 4;\n\n BLK(ctx->cur, l1x, l1y) = BLK(ctx->cur, l1x - mx, l1y - my);\n\n BLK(ctx->cur, l1x + 1, l1y) =\n\n BLK(ctx->cur, l1x + 1 - mx, l1y - my);\n\n BLK(ctx->cur, l1x, l1y + 1) =\n\n BLK(ctx->cur, l1x - mx, l1y + 1 - my);\n\n BLK(ctx->cur, l1x + 1, l1y + 1) =\n\n BLK(ctx->cur, l1x + 1 - mx, l1y + 1 - my);\n\n }\n\n } else { // read values for block\n\n BLK(ctx->cur, l1x, l1y) = *src++;\n\n BLK(ctx->cur, l1x + 1, l1y) = *src++;\n\n BLK(ctx->cur, l1x, l1y + 1) = *src++;\n\n BLK(ctx->cur, l1x + 1, l1y + 1) = *src++;\n\n }\n\n }\n\n }\n\n }\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 17774 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)\n\n{\n\n BDRVQcow2State *s = bs->opaque;\n\n QCowSnapshot *new_snapshot_list = NULL;\n\n QCowSnapshot *old_snapshot_list = NULL;\n\n QCowSnapshot sn1, *sn = &sn1;\n\n int i, ret;\n\n uint64_t *l1_table = NULL;\n\n int64_t l1_table_offset;\n\n\n\n if (s->nb_snapshots >= QCOW_MAX_SNAPSHOTS) {\n\n return -EFBIG;\n\n }\n\n\n\n memset(sn, 0, sizeof(*sn));\n\n\n\n /* Generate an ID */\n\n find_new_snapshot_id(bs, sn_info->id_str, sizeof(sn_info->id_str));\n\n\n\n /* Check that the ID is unique */\n\n if (find_snapshot_by_id_and_name(bs, sn_info->id_str, NULL) >= 0) {\n\n return -EEXIST;\n\n }\n\n\n\n /* Populate sn with passed data */\n\n sn->id_str = g_strdup(sn_info->id_str);\n\n sn->name = g_strdup(sn_info->name);\n\n\n\n sn->disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;\n\n sn->vm_state_size = sn_info->vm_state_size;\n\n sn->date_sec = sn_info->date_sec;\n\n sn->date_nsec = sn_info->date_nsec;\n\n sn->vm_clock_nsec = sn_info->vm_clock_nsec;\n\n\n\n /* Allocate the L1 table of the snapshot and copy the current one there. */\n\n l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t));\n\n if (l1_table_offset < 0) {\n\n ret = l1_table_offset;\n\n goto fail;\n\n }\n\n\n\n sn->l1_table_offset = l1_table_offset;\n\n sn->l1_size = s->l1_size;\n\n\n\n l1_table = g_try_new(uint64_t, s->l1_size);\n\n if (s->l1_size && l1_table == NULL) {\n\n ret = -ENOMEM;\n\n goto fail;\n\n }\n\n\n\n for(i = 0; i < s->l1_size; i++) {\n\n l1_table[i] = cpu_to_be64(s->l1_table[i]);\n\n }\n\n\n\n ret = qcow2_pre_write_overlap_check(bs, 0, sn->l1_table_offset,\n\n s->l1_size * sizeof(uint64_t));\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table,\n\n s->l1_size * sizeof(uint64_t));\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n g_free(l1_table);\n\n l1_table = NULL;\n\n\n\n /*\n\n * Increase the refcounts of all clusters and make sure everything is\n\n * stable on disk before updating the snapshot table to contain a pointer\n\n * to the new L1 table.\n\n */\n\n ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1);\n\n if (ret < 0) {\n\n goto fail;\n\n }\n\n\n\n /* Append the new snapshot to the snapshot list */\n\n new_snapshot_list = g_new(QCowSnapshot, s->nb_snapshots + 1);\n\n if (s->snapshots) {\n\n memcpy(new_snapshot_list, s->snapshots,\n\n s->nb_snapshots * sizeof(QCowSnapshot));\n\n old_snapshot_list = s->snapshots;\n\n }\n\n s->snapshots = new_snapshot_list;\n\n s->snapshots[s->nb_snapshots++] = *sn;\n\n\n\n ret = qcow2_write_snapshots(bs);\n\n if (ret < 0) {\n\n g_free(s->snapshots);\n\n s->snapshots = old_snapshot_list;\n\n s->nb_snapshots--;\n\n goto fail;\n\n }\n\n\n\n g_free(old_snapshot_list);\n\n\n\n /* The VM state isn't needed any more in the active L1 table; in fact, it\n\n * hurts by causing expensive COW for the next snapshot. */\n\n qcow2_discard_clusters(bs, qcow2_vm_state_offset(s),\n\n align_offset(sn->vm_state_size, s->cluster_size)\n\n >> BDRV_SECTOR_BITS,\n\n QCOW2_DISCARD_NEVER, false);\n\n\n\n#ifdef DEBUG_ALLOC\n\n {\n\n BdrvCheckResult result = {0};\n\n qcow2_check_refcounts(bs, &result, 0);\n\n }\n\n#endif\n\n return 0;\n\n\n\nfail:\n\n g_free(sn->id_str);\n\n g_free(sn->name);\n\n g_free(l1_table);\n\n\n\n return ret;\n\n}\n", + "output": "0", + "index": 27181 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int read_header(AVFormatContext *s, AVFormatParameters *ap)\n\n{\n\n BinkDemuxContext *bink = s->priv_data;\n\n AVIOContext *pb = s->pb;\n\n uint32_t fps_num, fps_den;\n\n AVStream *vst, *ast;\n\n unsigned int i;\n\n uint32_t pos, next_pos;\n\n uint16_t flags;\n\n int keyframe;\n\n\n\n vst = av_new_stream(s, 0);\n\n if (!vst)\n\n return AVERROR(ENOMEM);\n\n\n\n vst->codec->codec_tag = avio_rl32(pb);\n\n\n\n bink->file_size = avio_rl32(pb) + 8;\n\n vst->duration = avio_rl32(pb);\n\n\n\n if (vst->duration > 1000000) {\n\n av_log(s, AV_LOG_ERROR, \"invalid header: more than 1000000 frames\\n\");\n\n return AVERROR(EIO);\n\n }\n\n\n\n if (avio_rl32(pb) > bink->file_size) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"invalid header: largest frame size greater than file size\\n\");\n\n return AVERROR(EIO);\n\n }\n\n\n\n avio_skip(pb, 4);\n\n\n\n vst->codec->width = avio_rl32(pb);\n\n vst->codec->height = avio_rl32(pb);\n\n\n\n fps_num = avio_rl32(pb);\n\n fps_den = avio_rl32(pb);\n\n if (fps_num == 0 || fps_den == 0) {\n\n av_log(s, AV_LOG_ERROR, \"invalid header: invalid fps (%d/%d)\\n\", fps_num, fps_den);\n\n return AVERROR(EIO);\n\n }\n\n av_set_pts_info(vst, 64, fps_den, fps_num);\n\n\n\n vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;\n\n vst->codec->codec_id = CODEC_ID_BINKVIDEO;\n\n vst->codec->extradata = av_mallocz(4 + FF_INPUT_BUFFER_PADDING_SIZE);\n\n vst->codec->extradata_size = 4;\n\n avio_read(pb, vst->codec->extradata, 4);\n\n\n\n bink->num_audio_tracks = avio_rl32(pb);\n\n\n\n if (bink->num_audio_tracks > BINK_MAX_AUDIO_TRACKS) {\n\n av_log(s, AV_LOG_ERROR,\n\n \"invalid header: more than \"AV_STRINGIFY(BINK_MAX_AUDIO_TRACKS)\" audio tracks (%d)\\n\",\n\n bink->num_audio_tracks);\n\n return AVERROR(EIO);\n\n }\n\n\n\n if (bink->num_audio_tracks) {\n\n avio_skip(pb, 4 * bink->num_audio_tracks);\n\n\n\n for (i = 0; i < bink->num_audio_tracks; i++) {\n\n ast = av_new_stream(s, 1);\n\n if (!ast)\n\n return AVERROR(ENOMEM);\n\n ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n\n ast->codec->codec_tag = vst->codec->codec_tag;\n\n ast->codec->sample_rate = avio_rl16(pb);\n\n av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);\n\n flags = avio_rl16(pb);\n\n ast->codec->codec_id = flags & BINK_AUD_USEDCT ?\n\n CODEC_ID_BINKAUDIO_DCT : CODEC_ID_BINKAUDIO_RDFT;\n\n ast->codec->channels = flags & BINK_AUD_STEREO ? 2 : 1;\n\n }\n\n\n\n for (i = 0; i < bink->num_audio_tracks; i++)\n\n s->streams[i + 1]->id = avio_rl32(pb);\n\n }\n\n\n\n /* frame index table */\n\n next_pos = avio_rl32(pb);\n\n for (i = 0; i < vst->duration; i++) {\n\n pos = next_pos;\n\n if (i == vst->duration - 1) {\n\n next_pos = bink->file_size;\n\n keyframe = 0;\n\n } else {\n\n next_pos = avio_rl32(pb);\n\n keyframe = pos & 1;\n\n }\n\n pos &= ~1;\n\n next_pos &= ~1;\n\n\n\n if (next_pos <= pos) {\n\n av_log(s, AV_LOG_ERROR, \"invalid frame index table\\n\");\n\n return AVERROR(EIO);\n\n }\n\n av_add_index_entry(vst, pos, i, next_pos - pos, 0,\n\n keyframe ? AVINDEX_KEYFRAME : 0);\n\n }\n\n\n\n avio_skip(pb, 4);\n\n\n\n bink->current_track = -1;\n\n return 0;\n\n}\n", + "output": "0", + "index": 4964 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void do_savevm(Monitor *mon, const QDict *qdict)\n\n{\n\n DriveInfo *dinfo;\n\n BlockDriverState *bs, *bs1;\n\n QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;\n\n int must_delete, ret;\n\n QEMUFile *f;\n\n int saved_vm_running;\n\n uint32_t vm_state_size;\n\n#ifdef _WIN32\n\n struct _timeb tb;\n\n#else\n\n struct timeval tv;\n\n#endif\n\n const char *name = qdict_get_try_str(qdict, \"name\");\n\n\n\n bs = get_bs_snapshots();\n\n if (!bs) {\n\n monitor_printf(mon, \"No block device can accept snapshots\\n\");\n\n return;\n\n }\n\n\n\n /* ??? Should this occur after vm_stop? */\n\n qemu_aio_flush();\n\n\n\n saved_vm_running = vm_running;\n\n vm_stop(0);\n\n\n\n must_delete = 0;\n\n if (name) {\n\n ret = bdrv_snapshot_find(bs, old_sn, name);\n\n if (ret >= 0) {\n\n must_delete = 1;\n\n }\n\n }\n\n memset(sn, 0, sizeof(*sn));\n\n if (must_delete) {\n\n pstrcpy(sn->name, sizeof(sn->name), old_sn->name);\n\n pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str);\n\n } else {\n\n if (name)\n\n pstrcpy(sn->name, sizeof(sn->name), name);\n\n }\n\n\n\n /* fill auxiliary fields */\n\n#ifdef _WIN32\n\n _ftime(&tb);\n\n sn->date_sec = tb.time;\n\n sn->date_nsec = tb.millitm * 1000000;\n\n#else\n\n gettimeofday(&tv, NULL);\n\n sn->date_sec = tv.tv_sec;\n\n sn->date_nsec = tv.tv_usec * 1000;\n\n#endif\n\n sn->vm_clock_nsec = qemu_get_clock(vm_clock);\n\n\n\n /* save the VM state */\n\n f = qemu_fopen_bdrv(bs, 1);\n\n if (!f) {\n\n monitor_printf(mon, \"Could not open VM state file\\n\");\n\n goto the_end;\n\n }\n\n ret = qemu_savevm_state(f);\n\n vm_state_size = qemu_ftell(f);\n\n qemu_fclose(f);\n\n if (ret < 0) {\n\n monitor_printf(mon, \"Error %d while writing VM\\n\", ret);\n\n goto the_end;\n\n }\n\n\n\n /* create the snapshots */\n\n\n\n TAILQ_FOREACH(dinfo, &drives, next) {\n\n bs1 = dinfo->bdrv;\n\n if (bdrv_has_snapshot(bs1)) {\n\n if (must_delete) {\n\n ret = bdrv_snapshot_delete(bs1, old_sn->id_str);\n\n if (ret < 0) {\n\n monitor_printf(mon,\n\n \"Error while deleting snapshot on '%s'\\n\",\n\n bdrv_get_device_name(bs1));\n\n }\n\n }\n\n /* Write VM state size only to the image that contains the state */\n\n sn->vm_state_size = (bs == bs1 ? vm_state_size : 0);\n\n ret = bdrv_snapshot_create(bs1, sn);\n\n if (ret < 0) {\n\n monitor_printf(mon, \"Error while creating snapshot on '%s'\\n\",\n\n bdrv_get_device_name(bs1));\n\n }\n\n }\n\n }\n\n\n\n the_end:\n\n if (saved_vm_running)\n\n vm_start();\n\n}\n", + "output": "0", + "index": 16513 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static inline void RENAME(yuv2bgr24_1)(SwsContext *c, const uint16_t *buf0,\n\n const uint16_t *ubuf0, const uint16_t *ubuf1,\n\n const uint16_t *vbuf0, const uint16_t *vbuf1,\n\n const uint16_t *abuf0, uint8_t *dest,\n\n int dstW, int uvalpha, enum PixelFormat dstFormat,\n\n int flags, int y)\n\n{\n\n x86_reg uv_off = c->uv_off << 1;\n\n const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1\n\n\n\n if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster\n\n __asm__ volatile(\n\n \"mov %%\"REG_b\", \"ESP_OFFSET\"(%5) \\n\\t\"\n\n \"mov %4, %%\"REG_b\" \\n\\t\"\n\n \"push %%\"REG_BP\" \\n\\t\"\n\n YSCALEYUV2RGB1(%%REGBP, %5, %6)\n\n \"pxor %%mm7, %%mm7 \\n\\t\"\n\n WRITEBGR24(%%REGb, 8280(%5), %%REGBP)\n\n \"pop %%\"REG_BP\" \\n\\t\"\n\n \"mov \"ESP_OFFSET\"(%5), %%\"REG_b\" \\n\\t\"\n\n :: \"c\" (buf0), \"d\" (buf1), \"S\" (ubuf0), \"D\" (ubuf1), \"m\" (dest),\n\n \"a\" (&c->redDither), \"m\"(uv_off)\n\n );\n\n } else {\n\n __asm__ volatile(\n\n \"mov %%\"REG_b\", \"ESP_OFFSET\"(%5) \\n\\t\"\n\n \"mov %4, %%\"REG_b\" \\n\\t\"\n\n \"push %%\"REG_BP\" \\n\\t\"\n\n YSCALEYUV2RGB1b(%%REGBP, %5, %6)\n\n \"pxor %%mm7, %%mm7 \\n\\t\"\n\n WRITEBGR24(%%REGb, 8280(%5), %%REGBP)\n\n \"pop %%\"REG_BP\" \\n\\t\"\n\n \"mov \"ESP_OFFSET\"(%5), %%\"REG_b\" \\n\\t\"\n\n :: \"c\" (buf0), \"d\" (buf1), \"S\" (ubuf0), \"D\" (ubuf1), \"m\" (dest),\n\n \"a\" (&c->redDither), \"m\"(uv_off)\n\n );\n\n }\n\n}\n", + "output": "1", + "index": 16716 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static uint64_t do_cvttq(CPUAlphaState *env, uint64_t a, int roundmode)\n\n{\n\n uint64_t frac, ret = 0;\n\n uint32_t exp, sign, exc = 0;\n\n int shift;\n\n\n\n sign = (a >> 63);\n\n exp = (uint32_t)(a >> 52) & 0x7ff;\n\n frac = a & 0xfffffffffffffull;\n\n\n\n if (exp == 0) {\n\n if (unlikely(frac != 0)) {\n\n goto do_underflow;\n\n }\n\n } else if (exp == 0x7ff) {\n\n exc = FPCR_INV;\n\n } else {\n\n /* Restore implicit bit. */\n\n frac |= 0x10000000000000ull;\n\n\n\n shift = exp - 1023 - 52;\n\n if (shift >= 0) {\n\n /* In this case the number is so large that we must shift\n\n the fraction left. There is no rounding to do. */\n\n if (shift < 64) {\n\n ret = frac << shift;\n\n }\n\n /* Check for overflow. Note the special case of -0x1p63. */\n\n if (shift >= 11 && a != 0xC3E0000000000000ull) {\n\n exc = FPCR_IOV | FPCR_INE;\n\n }\n\n } else {\n\n uint64_t round;\n\n\n\n /* In this case the number is smaller than the fraction as\n\n represented by the 52 bit number. Here we must think\n\n about rounding the result. Handle this by shifting the\n\n fractional part of the number into the high bits of ROUND.\n\n This will let us efficiently handle round-to-nearest. */\n\n shift = -shift;\n\n if (shift < 63) {\n\n ret = frac >> shift;\n\n round = frac << (64 - shift);\n\n } else {\n\n /* The exponent is so small we shift out everything.\n\n Leave a sticky bit for proper rounding below. */\n\n do_underflow:\n\n round = 1;\n\n }\n\n\n\n if (round) {\n\n exc = FPCR_INE;\n\n switch (roundmode) {\n\n case float_round_nearest_even:\n\n if (round == (1ull << 63)) {\n\n /* Fraction is exactly 0.5; round to even. */\n\n ret += (ret & 1);\n\n } else if (round > (1ull << 63)) {\n\n ret += 1;\n\n }\n\n break;\n\n case float_round_to_zero:\n\n break;\n\n case float_round_up:\n\n ret += 1 - sign;\n\n break;\n\n case float_round_down:\n\n ret += sign;\n\n break;\n\n }\n\n }\n\n }\n\n if (sign) {\n\n ret = -ret;\n\n }\n\n }\n\n env->error_code = exc;\n\n\n\n return ret;\n\n}\n", + "output": "1", + "index": 3243 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static uint32_t hpet_ram_readl(void *opaque, target_phys_addr_t addr)\n\n{\n\n HPETState *s = opaque;\n\n uint64_t cur_tick, index;\n\n\n\n DPRINTF(\"qemu: Enter hpet_ram_readl at %\" PRIx64 \"\\n\", addr);\n\n index = addr;\n\n /*address range of all TN regs*/\n\n if (index >= 0x100 && index <= 0x3ff) {\n\n uint8_t timer_id = (addr - 0x100) / 0x20;\n\n HPETTimer *timer = &s->timer[timer_id];\n\n\n\n if (timer_id > s->num_timers) {\n\n DPRINTF(\"qemu: timer id out of range\\n\");\n\n return 0;\n\n }\n\n\n\n switch ((addr - 0x100) % 0x20) {\n\n case HPET_TN_CFG:\n\n return timer->config;\n\n case HPET_TN_CFG + 4: // Interrupt capabilities\n\n return timer->config >> 32;\n\n case HPET_TN_CMP: // comparator register\n\n return timer->cmp;\n\n case HPET_TN_CMP + 4:\n\n return timer->cmp >> 32;\n\n case HPET_TN_ROUTE:\n\n return timer->fsb;\n\n case HPET_TN_ROUTE + 4:\n\n return timer->fsb >> 32;\n\n default:\n\n DPRINTF(\"qemu: invalid hpet_ram_readl\\n\");\n\n break;\n\n }\n\n } else {\n\n switch (index) {\n\n case HPET_ID:\n\n return s->capability;\n\n case HPET_PERIOD:\n\n return s->capability >> 32;\n\n case HPET_CFG:\n\n return s->config;\n\n case HPET_CFG + 4:\n\n DPRINTF(\"qemu: invalid HPET_CFG + 4 hpet_ram_readl \\n\");\n\n return 0;\n\n case HPET_COUNTER:\n\n if (hpet_enabled(s)) {\n\n cur_tick = hpet_get_ticks(s);\n\n } else {\n\n cur_tick = s->hpet_counter;\n\n }\n\n DPRINTF(\"qemu: reading counter = %\" PRIx64 \"\\n\", cur_tick);\n\n return cur_tick;\n\n case HPET_COUNTER + 4:\n\n if (hpet_enabled(s)) {\n\n cur_tick = hpet_get_ticks(s);\n\n } else {\n\n cur_tick = s->hpet_counter;\n\n }\n\n DPRINTF(\"qemu: reading counter + 4 = %\" PRIx64 \"\\n\", cur_tick);\n\n return cur_tick >> 32;\n\n case HPET_STATUS:\n\n return s->isr;\n\n default:\n\n DPRINTF(\"qemu: invalid hpet_ram_readl\\n\");\n\n break;\n\n }\n\n }\n\n return 0;\n\n}\n", + "output": "0", + "index": 20429 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void pxa2xx_pwrmode_write(CPUARMState *env, const ARMCPRegInfo *ri,\n\n uint64_t value)\n\n{\n\n PXA2xxState *s = (PXA2xxState *)ri->opaque;\n\n static const char *pwrmode[8] = {\n\n \"Normal\", \"Idle\", \"Deep-idle\", \"Standby\",\n\n \"Sleep\", \"reserved (!)\", \"reserved (!)\", \"Deep-sleep\",\n\n };\n\n\n\n if (value & 8) {\n\n printf(\"%s: CPU voltage change attempt\\n\", __func__);\n\n }\n\n switch (value & 7) {\n\n case 0:\n\n /* Do nothing */\n\n break;\n\n\n\n case 1:\n\n /* Idle */\n\n if (!(s->cm_regs[CCCR >> 2] & (1U << 31))) { /* CPDIS */\n\n cpu_interrupt(CPU(s->cpu), CPU_INTERRUPT_HALT);\n\n break;\n\n }\n\n /* Fall through. */\n\n\n\n case 2:\n\n /* Deep-Idle */\n\n cpu_interrupt(CPU(s->cpu), CPU_INTERRUPT_HALT);\n\n s->pm_regs[RCSR >> 2] |= 0x8; /* Set GPR */\n\n goto message;\n\n\n\n case 3:\n\n s->cpu->env.uncached_cpsr = ARM_CPU_MODE_SVC;\n\n s->cpu->env.daif = PSTATE_A | PSTATE_F | PSTATE_I;\n\n s->cpu->env.cp15.sctlr_ns = 0;\n\n s->cpu->env.cp15.c1_coproc = 0;\n\n s->cpu->env.cp15.ttbr0_el[1] = 0;\n\n s->cpu->env.cp15.c3 = 0;\n\n s->pm_regs[PSSR >> 2] |= 0x8; /* Set STS */\n\n s->pm_regs[RCSR >> 2] |= 0x8; /* Set GPR */\n\n\n\n /*\n\n * The scratch-pad register is almost universally used\n\n * for storing the return address on suspend. For the\n\n * lack of a resuming bootloader, perform a jump\n\n * directly to that address.\n\n */\n\n memset(s->cpu->env.regs, 0, 4 * 15);\n\n s->cpu->env.regs[15] = s->pm_regs[PSPR >> 2];\n\n\n\n#if 0\n\n buffer = 0xe59ff000; /* ldr pc, [pc, #0] */\n\n cpu_physical_memory_write(0, &buffer, 4);\n\n buffer = s->pm_regs[PSPR >> 2];\n\n cpu_physical_memory_write(8, &buffer, 4);\n\n#endif\n\n\n\n /* Suspend */\n\n cpu_interrupt(current_cpu, CPU_INTERRUPT_HALT);\n\n\n\n goto message;\n\n\n\n default:\n\n message:\n\n printf(\"%s: machine entered %s mode\\n\", __func__,\n\n pwrmode[value & 7]);\n\n }\n\n}\n", + "output": "0", + "index": 4125 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in)\n\n{\n\n /* Implement DC ZVA, which zeroes a fixed-length block of memory.\n\n * Note that we do not implement the (architecturally mandated)\n\n * alignment fault for attempts to use this on Device memory\n\n * (which matches the usual QEMU behaviour of not implementing either\n\n * alignment faults or any memory attribute handling).\n\n */\n\n\n\n ARMCPU *cpu = arm_env_get_cpu(env);\n\n uint64_t blocklen = 4 << cpu->dcz_blocksize;\n\n uint64_t vaddr = vaddr_in & ~(blocklen - 1);\n\n\n\n#ifndef CONFIG_USER_ONLY\n\n {\n\n /* Slightly awkwardly, QEMU's TARGET_PAGE_SIZE may be less than\n\n * the block size so we might have to do more than one TLB lookup.\n\n * We know that in fact for any v8 CPU the page size is at least 4K\n\n * and the block size must be 2K or less, but TARGET_PAGE_SIZE is only\n\n * 1K as an artefact of legacy v5 subpage support being present in the\n\n * same QEMU executable.\n\n */\n\n int maxidx = DIV_ROUND_UP(blocklen, TARGET_PAGE_SIZE);\n\n void *hostaddr[maxidx];\n\n int try, i;\n\n unsigned mmu_idx = cpu_mmu_index(env, false);\n\n TCGMemOpIdx oi = make_memop_idx(MO_UB, mmu_idx);\n\n\n\n for (try = 0; try < 2; try++) {\n\n\n\n for (i = 0; i < maxidx; i++) {\n\n hostaddr[i] = tlb_vaddr_to_host(env,\n\n vaddr + TARGET_PAGE_SIZE * i,\n\n 1, mmu_idx);\n\n if (!hostaddr[i]) {\n\n break;\n\n }\n\n }\n\n if (i == maxidx) {\n\n /* If it's all in the TLB it's fair game for just writing to;\n\n * we know we don't need to update dirty status, etc.\n\n */\n\n for (i = 0; i < maxidx - 1; i++) {\n\n memset(hostaddr[i], 0, TARGET_PAGE_SIZE);\n\n }\n\n memset(hostaddr[i], 0, blocklen - (i * TARGET_PAGE_SIZE));\n\n return;\n\n }\n\n /* OK, try a store and see if we can populate the tlb. This\n\n * might cause an exception if the memory isn't writable,\n\n * in which case we will longjmp out of here. We must for\n\n * this purpose use the actual register value passed to us\n\n * so that we get the fault address right.\n\n */\n\n helper_ret_stb_mmu(env, vaddr_in, 0, oi, GETRA());\n\n /* Now we can populate the other TLB entries, if any */\n\n for (i = 0; i < maxidx; i++) {\n\n uint64_t va = vaddr + TARGET_PAGE_SIZE * i;\n\n if (va != (vaddr_in & TARGET_PAGE_MASK)) {\n\n helper_ret_stb_mmu(env, va, 0, oi, GETRA());\n\n }\n\n }\n\n }\n\n\n\n /* Slow path (probably attempt to do this to an I/O device or\n\n * similar, or clearing of a block of code we have translations\n\n * cached for). Just do a series of byte writes as the architecture\n\n * demands. It's not worth trying to use a cpu_physical_memory_map(),\n\n * memset(), unmap() sequence here because:\n\n * + we'd need to account for the blocksize being larger than a page\n\n * + the direct-RAM access case is almost always going to be dealt\n\n * with in the fastpath code above, so there's no speed benefit\n\n * + we would have to deal with the map returning NULL because the\n\n * bounce buffer was in use\n\n */\n\n for (i = 0; i < blocklen; i++) {\n\n helper_ret_stb_mmu(env, vaddr + i, 0, oi, GETRA());\n\n }\n\n }\n\n#else\n\n memset(g2h(vaddr), 0, blocklen);\n\n#endif\n\n}\n", + "output": "0", + "index": 8564 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void tcx_initfn(Object *obj)\n\n{\n\n SysBusDevice *sbd = SYS_BUS_DEVICE(obj);\n\n TCXState *s = TCX(obj);\n\n\n\n memory_region_init_ram(&s->rom, NULL, \"tcx.prom\", FCODE_MAX_ROM_SIZE,\n\n &error_abort);\n\n memory_region_set_readonly(&s->rom, true);\n\n sysbus_init_mmio(sbd, &s->rom);\n\n\n\n /* 2/STIP : Stippler */\n\n memory_region_init_io(&s->stip, OBJECT(s), &tcx_stip_ops, s, \"tcx.stip\",\n\n TCX_STIP_NREGS);\n\n sysbus_init_mmio(sbd, &s->stip);\n\n\n\n /* 3/BLIT : Blitter */\n\n memory_region_init_io(&s->blit, OBJECT(s), &tcx_blit_ops, s, \"tcx.blit\",\n\n TCX_BLIT_NREGS);\n\n sysbus_init_mmio(sbd, &s->blit);\n\n\n\n /* 5/RSTIP : Raw Stippler */\n\n memory_region_init_io(&s->rstip, OBJECT(s), &tcx_rstip_ops, s, \"tcx.rstip\",\n\n TCX_RSTIP_NREGS);\n\n sysbus_init_mmio(sbd, &s->rstip);\n\n\n\n /* 6/RBLIT : Raw Blitter */\n\n memory_region_init_io(&s->rblit, OBJECT(s), &tcx_rblit_ops, s, \"tcx.rblit\",\n\n TCX_RBLIT_NREGS);\n\n sysbus_init_mmio(sbd, &s->rblit);\n\n\n\n /* 7/TEC : ??? */\n\n memory_region_init_io(&s->tec, OBJECT(s), &tcx_dummy_ops, s,\n\n \"tcx.tec\", TCX_TEC_NREGS);\n\n sysbus_init_mmio(sbd, &s->tec);\n\n\n\n /* 8/CMAP : DAC */\n\n memory_region_init_io(&s->dac, OBJECT(s), &tcx_dac_ops, s,\n\n \"tcx.dac\", TCX_DAC_NREGS);\n\n sysbus_init_mmio(sbd, &s->dac);\n\n\n\n /* 9/THC : Cursor */\n\n memory_region_init_io(&s->thc, OBJECT(s), &tcx_thc_ops, s, \"tcx.thc\",\n\n TCX_THC_NREGS);\n\n sysbus_init_mmio(sbd, &s->thc);\n\n\n\n /* 11/DHC : ??? */\n\n memory_region_init_io(&s->dhc, OBJECT(s), &tcx_dummy_ops, s, \"tcx.dhc\",\n\n TCX_DHC_NREGS);\n\n sysbus_init_mmio(sbd, &s->dhc);\n\n\n\n /* 12/ALT : ??? */\n\n memory_region_init_io(&s->alt, OBJECT(s), &tcx_dummy_ops, s, \"tcx.alt\",\n\n TCX_ALT_NREGS);\n\n sysbus_init_mmio(sbd, &s->alt);\n\n\n\n return;\n\n}\n", + "output": "1", + "index": 20857 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void bdrv_move_feature_fields(BlockDriverState *bs_dest,\n\n BlockDriverState *bs_src)\n\n{\n\n /* move some fields that need to stay attached to the device */\n\n bs_dest->open_flags = bs_src->open_flags;\n\n\n\n /* dev info */\n\n bs_dest->dev_ops = bs_src->dev_ops;\n\n bs_dest->dev_opaque = bs_src->dev_opaque;\n\n bs_dest->dev = bs_src->dev;\n\n bs_dest->buffer_alignment = bs_src->buffer_alignment;\n\n bs_dest->copy_on_read = bs_src->copy_on_read;\n\n\n\n bs_dest->enable_write_cache = bs_src->enable_write_cache;\n\n\n\n /* i/o timing parameters */\n\n bs_dest->slice_time = bs_src->slice_time;\n\n bs_dest->slice_start = bs_src->slice_start;\n\n bs_dest->slice_end = bs_src->slice_end;\n\n bs_dest->io_limits = bs_src->io_limits;\n\n bs_dest->io_base = bs_src->io_base;\n\n bs_dest->throttled_reqs = bs_src->throttled_reqs;\n\n bs_dest->block_timer = bs_src->block_timer;\n\n bs_dest->io_limits_enabled = bs_src->io_limits_enabled;\n\n\n\n /* geometry */\n\n bs_dest->cyls = bs_src->cyls;\n\n bs_dest->heads = bs_src->heads;\n\n bs_dest->secs = bs_src->secs;\n\n bs_dest->translation = bs_src->translation;\n\n\n\n /* r/w error */\n\n bs_dest->on_read_error = bs_src->on_read_error;\n\n bs_dest->on_write_error = bs_src->on_write_error;\n\n\n\n /* i/o status */\n\n bs_dest->iostatus_enabled = bs_src->iostatus_enabled;\n\n bs_dest->iostatus = bs_src->iostatus;\n\n\n\n /* dirty bitmap */\n\n bs_dest->dirty_count = bs_src->dirty_count;\n\n bs_dest->dirty_bitmap = bs_src->dirty_bitmap;\n\n\n\n /* job */\n\n bs_dest->in_use = bs_src->in_use;\n\n bs_dest->job = bs_src->job;\n\n\n\n /* keep the same entry in bdrv_states */\n\n pstrcpy(bs_dest->device_name, sizeof(bs_dest->device_name),\n\n bs_src->device_name);\n\n bs_dest->list = bs_src->list;\n\n}\n", + "output": "0", + "index": 14724 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int read_header(ShortenContext *s)\n\n{\n\n int i, ret;\n\n int maxnlpc = 0;\n\n /* shorten signature */\n\n if (get_bits_long(&s->gb, 32) != AV_RB32(\"ajkg\")) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"missing shorten magic 'ajkg'\\n\");\n\n\n\n\n\n s->lpcqoffset = 0;\n\n s->blocksize = DEFAULT_BLOCK_SIZE;\n\n s->nmean = -1;\n\n s->version = get_bits(&s->gb, 8);\n\n s->internal_ftype = get_uint(s, TYPESIZE);\n\n\n\n s->channels = get_uint(s, CHANSIZE);\n\n if (!s->channels) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"No channels reported\\n\");\n\n\n\n if (s->channels > MAX_CHANNELS) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"too many channels: %d\\n\", s->channels);\n\n s->channels = 0;\n\n\n\n s->avctx->channels = s->channels;\n\n\n\n /* get blocksize if version > 0 */\n\n if (s->version > 0) {\n\n int skip_bytes;\n\n unsigned blocksize;\n\n\n\n blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));\n\n if (!blocksize || blocksize > MAX_BLOCKSIZE) {\n\n av_log(s->avctx, AV_LOG_ERROR,\n\n \"invalid or unsupported block size: %d\\n\",\n\n blocksize);\n\n return AVERROR(EINVAL);\n\n\n s->blocksize = blocksize;\n\n\n\n maxnlpc = get_uint(s, LPCQSIZE);\n\n\n\n\n\n s->nmean = get_uint(s, 0);\n\n\n\n skip_bytes = get_uint(s, NSKIPSIZE);\n\n if ((unsigned)skip_bytes > get_bits_left(&s->gb)/8) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"invalid skip_bytes: %d\\n\", skip_bytes);\n\n\n\n\n\n for (i = 0; i < skip_bytes; i++)\n\n skip_bits(&s->gb, 8);\n\n\n s->nwrap = FFMAX(NWRAP, maxnlpc);\n\n\n\n if ((ret = allocate_buffers(s)) < 0)\n\n return ret;\n\n\n\n if ((ret = init_offset(s)) < 0)\n\n return ret;\n\n\n\n if (s->version > 1)\n\n s->lpcqoffset = V2LPCQOFFSET;\n\n\n\n if (s->avctx->extradata_size > 0)\n\n goto end;\n\n\n\n if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) {\n\n av_log(s->avctx, AV_LOG_ERROR,\n\n \"missing verbatim section at beginning of stream\\n\");\n\n\n\n\n\n s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);\n\n if (s->header_size >= OUT_BUFFER_SIZE ||\n\n s->header_size < CANONICAL_HEADER_SIZE) {\n\n av_log(s->avctx, AV_LOG_ERROR, \"header is wrong size: %d\\n\",\n\n s->header_size);\n\n\n\n\n\n for (i = 0; i < s->header_size; i++)\n\n s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);\n\n\n\n if (AV_RL32(s->header) == MKTAG('R','I','F','F')) {\n\n if ((ret = decode_wave_header(s->avctx, s->header, s->header_size)) < 0)\n\n return ret;\n\n } else if (AV_RL32(s->header) == MKTAG('F','O','R','M')) {\n\n if ((ret = decode_aiff_header(s->avctx, s->header, s->header_size)) < 0)\n\n return ret;\n\n } else {\n\n avpriv_report_missing_feature(s->avctx, \"unsupported bit packing %\"\n\n PRIX32, AV_RL32(s->header));\n\n return AVERROR_PATCHWELCOME;\n\n\n\n\nend:\n\n s->cur_chan = 0;\n\n s->bitshift = 0;\n\n\n\n s->got_header = 1;\n\n\n\n return 0;\n", + "output": "1", + "index": 4582 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int mc_subpel(DiracContext *s, DiracBlock *block, const uint8_t *src[5],\n\n int x, int y, int ref, int plane)\n\n{\n\n Plane *p = &s->plane[plane];\n\n uint8_t **ref_hpel = s->ref_pics[ref]->hpel[plane];\n\n int motion_x = block->u.mv[ref][0];\n\n int motion_y = block->u.mv[ref][1];\n\n int mx, my, i, epel, nplanes = 0;\n\n\n\n if (plane) {\n\n motion_x >>= s->chroma_x_shift;\n\n motion_y >>= s->chroma_y_shift;\n\n }\n\n\n\n mx = motion_x & ~(-1 << s->mv_precision);\n\n my = motion_y & ~(-1 << s->mv_precision);\n\n motion_x >>= s->mv_precision;\n\n motion_y >>= s->mv_precision;\n\n /* normalize subpel coordinates to epel */\n\n /* TODO: template this function? */\n\n mx <<= 3 - s->mv_precision;\n\n my <<= 3 - s->mv_precision;\n\n\n\n x += motion_x;\n\n y += motion_y;\n\n epel = (mx|my)&1;\n\n\n\n /* hpel position */\n\n if (!((mx|my)&3)) {\n\n nplanes = 1;\n\n src[0] = ref_hpel[(my>>1)+(mx>>2)] + y*p->stride + x;\n\n } else {\n\n /* qpel or epel */\n\n nplanes = 4;\n\n for (i = 0; i < 4; i++)\n\n src[i] = ref_hpel[i] + y*p->stride + x;\n\n\n\n /* if we're interpolating in the right/bottom halves, adjust the planes as needed\n\n we increment x/y because the edge changes for half of the pixels */\n\n if (mx > 4) {\n\n src[0] += 1;\n\n src[2] += 1;\n\n x++;\n\n }\n\n if (my > 4) {\n\n src[0] += p->stride;\n\n src[1] += p->stride;\n\n y++;\n\n }\n\n\n\n /* hpel planes are:\n\n [0]: F [1]: H\n\n [2]: V [3]: C */\n\n if (!epel) {\n\n /* check if we really only need 2 planes since either mx or my is\n\n a hpel position. (epel weights of 0 handle this there) */\n\n if (!(mx&3)) {\n\n /* mx == 0: average [0] and [2]\n\n mx == 4: average [1] and [3] */\n\n src[!mx] = src[2 + !!mx];\n\n nplanes = 2;\n\n } else if (!(my&3)) {\n\n src[0] = src[(my>>1) ];\n\n src[1] = src[(my>>1)+1];\n\n nplanes = 2;\n\n }\n\n } else {\n\n /* adjust the ordering if needed so the weights work */\n\n if (mx > 4) {\n\n FFSWAP(const uint8_t *, src[0], src[1]);\n\n FFSWAP(const uint8_t *, src[2], src[3]);\n\n }\n\n if (my > 4) {\n\n FFSWAP(const uint8_t *, src[0], src[2]);\n\n FFSWAP(const uint8_t *, src[1], src[3]);\n\n }\n\n src[4] = epel_weights[my&3][mx&3];\n\n }\n\n }\n\n\n\n /* fixme: v/h _edge_pos */\n\n if (x + p->xblen > p->width +EDGE_WIDTH/2 ||\n\n y + p->yblen > p->height+EDGE_WIDTH/2 ||\n\n x < 0 || y < 0) {\n\n for (i = 0; i < nplanes; i++) {\n\n ff_emulated_edge_mc(s->edge_emu_buffer[i], src[i],\n\n p->stride, p->stride,\n\n p->xblen, p->yblen, x, y,\n\n p->width+EDGE_WIDTH/2, p->height+EDGE_WIDTH/2);\n\n src[i] = s->edge_emu_buffer[i];\n\n }\n\n }\n\n return (nplanes>>1) + epel;\n\n}\n", + "output": "1", + "index": 27070 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static int qemu_gluster_create(const char *filename,\n\n QemuOpts *opts, Error **errp)\n\n{\n\n BlockdevOptionsGluster *gconf;\n\n struct glfs *glfs;\n\n struct glfs_fd *fd;\n\n int ret = 0;\n\n int prealloc = 0;\n\n int64_t total_size = 0;\n\n char *tmp = NULL;\n\n\n\n gconf = g_new0(BlockdevOptionsGluster, 1);\n\n gconf->debug = qemu_opt_get_number_del(opts, GLUSTER_OPT_DEBUG,\n\n GLUSTER_DEBUG_DEFAULT);\n\n if (gconf->debug < 0) {\n\n gconf->debug = 0;\n\n } else if (gconf->debug > GLUSTER_DEBUG_MAX) {\n\n gconf->debug = GLUSTER_DEBUG_MAX;\n\n }\n\n gconf->has_debug = true;\n\n\n\n gconf->logfile = qemu_opt_get_del(opts, GLUSTER_OPT_LOGFILE);\n\n if (!gconf->logfile) {\n\n gconf->logfile = g_strdup(GLUSTER_LOGFILE_DEFAULT);\n\n }\n\n gconf->has_logfile = true;\n\n\n\n glfs = qemu_gluster_init(gconf, filename, NULL, errp);\n\n if (!glfs) {\n\n ret = -errno;\n\n goto out;\n\n }\n\n\n\n total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),\n\n BDRV_SECTOR_SIZE);\n\n\n\n tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);\n\n if (!tmp || !strcmp(tmp, \"off\")) {\n\n prealloc = 0;\n\n } else if (!strcmp(tmp, \"full\") && gluster_supports_zerofill()) {\n\n prealloc = 1;\n\n } else {\n\n error_setg(errp, \"Invalid preallocation mode: '%s'\"\n\n \" or GlusterFS doesn't support zerofill API\", tmp);\n\n ret = -EINVAL;\n\n goto out;\n\n }\n\n\n\n fd = glfs_creat(glfs, gconf->path,\n\n O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR | S_IWUSR);\n\n if (!fd) {\n\n ret = -errno;\n\n } else {\n\n if (!glfs_ftruncate(fd, total_size)) {\n\n if (prealloc && qemu_gluster_zerofill(fd, 0, total_size)) {\n\n ret = -errno;\n\n }\n\n } else {\n\n ret = -errno;\n\n }\n\n\n\n if (glfs_close(fd) != 0) {\n\n ret = -errno;\n\n }\n\n }\n\nout:\n\n g_free(tmp);\n\n qapi_free_BlockdevOptionsGluster(gconf);\n\n glfs_clear_preopened(glfs);\n\n return ret;\n\n}\n", + "output": "0", + "index": 8857 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "int ff_dxva2_commit_buffer(AVCodecContext *avctx,\n\n AVDXVAContext *ctx,\n\n DECODER_BUFFER_DESC *dsc,\n\n unsigned type, const void *data, unsigned size,\n\n unsigned mb_count)\n\n{\n\n void *dxva_data;\n\n unsigned dxva_size;\n\n int result;\n\n HRESULT hr;\n\n\n\n#if CONFIG_D3D11VA\n\n if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)\n\n hr = ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,\n\n D3D11VA_CONTEXT(ctx)->decoder,\n\n type,\n\n &dxva_size, &dxva_data);\n\n#endif\n\n#if CONFIG_DXVA2\n\n if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)\n\n hr = IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->decoder, type,\n\n &dxva_data, &dxva_size);\n\n#endif\n\n if (FAILED(hr)) {\n\n av_log(avctx, AV_LOG_ERROR, \"Failed to get a buffer for %u: 0x%lx\\n\",\n\n type, hr);\n\n return -1;\n\n }\n\n if (size <= dxva_size) {\n\n memcpy(dxva_data, data, size);\n\n\n\n#if CONFIG_D3D11VA\n\n if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {\n\n D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = dsc;\n\n memset(dsc11, 0, sizeof(*dsc11));\n\n dsc11->BufferType = type;\n\n dsc11->DataSize = size;\n\n dsc11->NumMBsInBuffer = mb_count;\n\n }\n\n#endif\n\n#if CONFIG_DXVA2\n\n if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {\n\n DXVA2_DecodeBufferDesc *dsc2 = dsc;\n\n memset(dsc2, 0, sizeof(*dsc2));\n\n dsc2->CompressedBufferType = type;\n\n dsc2->DataSize = size;\n\n dsc2->NumMBsInBuffer = mb_count;\n\n }\n\n#endif\n\n\n\n result = 0;\n\n } else {\n\n av_log(avctx, AV_LOG_ERROR, \"Buffer for type %u was too small\\n\", type);\n\n result = -1;\n\n }\n\n\n\n#if CONFIG_D3D11VA\n\n if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)\n\n hr = ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type);\n\n#endif\n\n#if CONFIG_DXVA2\n\n if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)\n\n hr = IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->decoder, type);\n\n#endif\n\n if (FAILED(hr)) {\n\n av_log(avctx, AV_LOG_ERROR,\n\n \"Failed to release buffer type %u: 0x%lx\\n\",\n\n type, hr);\n\n result = -1;\n\n }\n\n return result;\n\n}\n", + "output": "1", + "index": 26692 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "void qmp_drive_mirror(const char *device, const char *target,\n\n bool has_format, const char *format,\n\n enum MirrorSyncMode sync,\n\n bool has_mode, enum NewImageMode mode,\n\n bool has_speed, int64_t speed,\n\n bool has_granularity, uint32_t granularity,\n\n bool has_buf_size, int64_t buf_size,\n\n bool has_on_source_error, BlockdevOnError on_source_error,\n\n bool has_on_target_error, BlockdevOnError on_target_error,\n\n Error **errp)\n\n{\n\n BlockDriverState *bs;\n\n BlockDriverState *source, *target_bs;\n\n BlockDriver *proto_drv;\n\n BlockDriver *drv = NULL;\n\n Error *local_err = NULL;\n\n int flags;\n\n uint64_t size;\n\n int ret;\n\n\n\n if (!has_speed) {\n\n speed = 0;\n\n }\n\n if (!has_on_source_error) {\n\n on_source_error = BLOCKDEV_ON_ERROR_REPORT;\n\n }\n\n if (!has_on_target_error) {\n\n on_target_error = BLOCKDEV_ON_ERROR_REPORT;\n\n }\n\n if (!has_mode) {\n\n mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;\n\n }\n\n if (!has_granularity) {\n\n granularity = 0;\n\n }\n\n if (!has_buf_size) {\n\n buf_size = DEFAULT_MIRROR_BUF_SIZE;\n\n }\n\n\n\n if (granularity != 0 && (granularity < 512 || granularity > 1048576 * 64)) {\n\n error_set(errp, QERR_INVALID_PARAMETER, device);\n\n return;\n\n }\n\n if (granularity & (granularity - 1)) {\n\n error_set(errp, QERR_INVALID_PARAMETER, device);\n\n return;\n\n }\n\n\n\n bs = bdrv_find(device);\n\n if (!bs) {\n\n error_set(errp, QERR_DEVICE_NOT_FOUND, device);\n\n return;\n\n }\n\n\n\n if (!bdrv_is_inserted(bs)) {\n\n error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);\n\n return;\n\n }\n\n\n\n if (!has_format) {\n\n format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;\n\n }\n\n if (format) {\n\n drv = bdrv_find_format(format);\n\n if (!drv) {\n\n error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);\n\n return;\n\n }\n\n }\n\n\n\n if (bdrv_in_use(bs)) {\n\n error_set(errp, QERR_DEVICE_IN_USE, device);\n\n return;\n\n }\n\n\n\n flags = bs->open_flags | BDRV_O_RDWR;\n\n source = bs->backing_hd;\n\n if (!source && sync == MIRROR_SYNC_MODE_TOP) {\n\n sync = MIRROR_SYNC_MODE_FULL;\n\n }\n\n\n\n proto_drv = bdrv_find_protocol(target);\n\n if (!proto_drv) {\n\n error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);\n\n return;\n\n }\n\n\n\n bdrv_get_geometry(bs, &size);\n\n size *= 512;\n\n if (sync == MIRROR_SYNC_MODE_FULL && mode != NEW_IMAGE_MODE_EXISTING) {\n\n /* create new image w/o backing file */\n\n assert(format && drv);\n\n bdrv_img_create(target, format,\n\n NULL, NULL, NULL, size, flags, &local_err, false);\n\n } else {\n\n switch (mode) {\n\n case NEW_IMAGE_MODE_EXISTING:\n\n ret = 0;\n\n break;\n\n case NEW_IMAGE_MODE_ABSOLUTE_PATHS:\n\n /* create new image with backing file */\n\n bdrv_img_create(target, format,\n\n source->filename,\n\n source->drv->format_name,\n\n NULL, size, flags, &local_err, false);\n\n break;\n\n default:\n\n abort();\n\n }\n\n }\n\n\n\n if (error_is_set(&local_err)) {\n\n error_propagate(errp, local_err);\n\n return;\n\n }\n\n\n\n /* Mirroring takes care of copy-on-write using the source's backing\n\n * file.\n\n */\n\n target_bs = bdrv_new(\"\");\n\n ret = bdrv_open(target_bs, target, NULL, flags | BDRV_O_NO_BACKING, drv);\n\n\n\n if (ret < 0) {\n\n bdrv_delete(target_bs);\n\n error_setg_file_open(errp, -ret, target);\n\n return;\n\n }\n\n\n\n mirror_start(bs, target_bs, speed, granularity, buf_size, sync,\n\n on_source_error, on_target_error,\n\n block_job_cb, bs, &local_err);\n\n if (local_err != NULL) {\n\n bdrv_delete(target_bs);\n\n error_propagate(errp, local_err);\n\n return;\n\n }\n\n\n\n /* Grab a reference so hotplug does not delete the BlockDriverState from\n\n * underneath us.\n\n */\n\n drive_get_ref(drive_get_by_blockdev(bs));\n\n}\n", + "output": "0", + "index": 18900 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void escc_mem_write(void *opaque, hwaddr addr,\n\n uint64_t val, unsigned size)\n\n{\n\n ESCCState *serial = opaque;\n\n ChannelState *s;\n\n uint32_t saddr;\n\n int newreg, channel;\n\n\n\n val &= 0xff;\n\n saddr = (addr >> serial->it_shift) & 1;\n\n channel = (addr >> (serial->it_shift + 1)) & 1;\n\n s = &serial->chn[channel];\n\n switch (saddr) {\n\n case SERIAL_CTRL:\n\n trace_escc_mem_writeb_ctrl(CHN_C(s), s->reg, val & 0xff);\n\n newreg = 0;\n\n switch (s->reg) {\n\n case W_CMD:\n\n newreg = val & CMD_PTR_MASK;\n\n val &= CMD_CMD_MASK;\n\n switch (val) {\n\n case CMD_HI:\n\n newreg |= CMD_HI;\n\n break;\n\n case CMD_CLR_TXINT:\n\n clr_txint(s);\n\n break;\n\n case CMD_CLR_IUS:\n\n if (s->rxint_under_svc) {\n\n s->rxint_under_svc = 0;\n\n if (s->txint) {\n\n set_txint(s);\n\n }\n\n } else if (s->txint_under_svc) {\n\n s->txint_under_svc = 0;\n\n }\n\n escc_update_irq(s);\n\n break;\n\n default:\n\n break;\n\n }\n\n break;\n\n case W_INTR ... W_RXCTRL:\n\n case W_SYNC1 ... W_TXBUF:\n\n case W_MISC1 ... W_CLOCK:\n\n case W_MISC2 ... W_EXTINT:\n\n s->wregs[s->reg] = val;\n\n break;\n\n case W_TXCTRL1:\n\n case W_TXCTRL2:\n\n s->wregs[s->reg] = val;\n\n escc_update_parameters(s);\n\n break;\n\n case W_BRGLO:\n\n case W_BRGHI:\n\n s->wregs[s->reg] = val;\n\n s->rregs[s->reg] = val;\n\n escc_update_parameters(s);\n\n break;\n\n case W_MINTR:\n\n switch (val & MINTR_RST_MASK) {\n\n case 0:\n\n default:\n\n break;\n\n case MINTR_RST_B:\n\n escc_reset_chn(&serial->chn[0]);\n\n return;\n\n case MINTR_RST_A:\n\n escc_reset_chn(&serial->chn[1]);\n\n return;\n\n case MINTR_RST_ALL:\n\n escc_reset(DEVICE(serial));\n\n return;\n\n }\n\n break;\n\n default:\n\n break;\n\n }\n\n if (s->reg == 0)\n\n s->reg = newreg;\n\n else\n\n s->reg = 0;\n\n break;\n\n case SERIAL_DATA:\n\n trace_escc_mem_writeb_data(CHN_C(s), val);\n\n s->tx = val;\n\n if (s->wregs[W_TXCTRL2] & TXCTRL2_TXEN) { // tx enabled\n\n if (s->chr)\n\n qemu_chr_fe_write(s->chr, &s->tx, 1);\n\n else if (s->type == kbd && !s->disabled) {\n\n handle_kbd_command(s, val);\n\n }\n\n }\n\n s->rregs[R_STATUS] |= STATUS_TXEMPTY; // Tx buffer empty\n\n s->rregs[R_SPEC] |= SPEC_ALLSENT; // All sent\n\n set_txint(s);\n\n break;\n\n default:\n\n break;\n\n }\n\n}\n", + "output": "1", + "index": 19875 + }, + { + "instruction": "Detect whether the following code contains vulnerabilities.", + "input": "static void gen_branch(DisasContext *ctx, int insn_bytes)\n\n{\n\n if (ctx->hflags & MIPS_HFLAG_BMASK) {\n\n int proc_hflags = ctx->hflags & MIPS_HFLAG_BMASK;\n\n /* Branches completion */\n\n ctx->hflags &= ~MIPS_HFLAG_BMASK;\n\n ctx->bstate = BS_BRANCH;\n\n save_cpu_state(ctx, 0);\n\n /* FIXME: Need to clear can_do_io. */\n\n switch (proc_hflags & MIPS_HFLAG_BMASK_BASE) {\n\n case MIPS_HFLAG_FBNSLOT:\n\n MIPS_DEBUG(\"forbidden slot\");\n\n gen_goto_tb(ctx, 0, ctx->pc + insn_bytes);\n\n break;\n\n case MIPS_HFLAG_B:\n\n /* unconditional branch */\n\n MIPS_DEBUG(\"unconditional branch\");\n\n if (proc_hflags & MIPS_HFLAG_BX) {\n\n tcg_gen_xori_i32(hflags, hflags, MIPS_HFLAG_M16);\n\n }\n\n gen_goto_tb(ctx, 0, ctx->btarget);\n\n break;\n\n case MIPS_HFLAG_BL:\n\n /* blikely taken case */\n\n MIPS_DEBUG(\"blikely branch taken\");\n\n gen_goto_tb(ctx, 0, ctx->btarget);\n\n break;\n\n case MIPS_HFLAG_BC:\n\n /* Conditional branch */\n\n MIPS_DEBUG(\"conditional branch\");\n\n {\n\n TCGLabel *l1 = gen_new_label();\n\n\n\n tcg_gen_brcondi_tl(TCG_COND_NE, bcond, 0, l1);\n\n gen_goto_tb(ctx, 1, ctx->pc + insn_bytes);\n\n gen_set_label(l1);\n\n gen_goto_tb(ctx, 0, ctx->btarget);\n\n }\n\n break;\n\n case MIPS_HFLAG_BR:\n\n /* unconditional branch to register */\n\n MIPS_DEBUG(\"branch to register\");\n\n if (ctx->insn_flags & (ASE_MIPS16 | ASE_MICROMIPS)) {\n\n TCGv t0 = tcg_temp_new();\n\n TCGv_i32 t1 = tcg_temp_new_i32();\n\n\n\n tcg_gen_andi_tl(t0, btarget, 0x1);\n\n tcg_gen_trunc_tl_i32(t1, t0);\n\n tcg_temp_free(t0);\n\n tcg_gen_andi_i32(hflags, hflags, ~(uint32_t)MIPS_HFLAG_M16);\n\n tcg_gen_shli_i32(t1, t1, MIPS_HFLAG_M16_SHIFT);\n\n tcg_gen_or_i32(hflags, hflags, t1);\n\n tcg_temp_free_i32(t1);\n\n\n\n tcg_gen_andi_tl(cpu_PC, btarget, ~(target_ulong)0x1);\n\n } else {\n\n tcg_gen_mov_tl(cpu_PC, btarget);\n\n }\n\n if (ctx->singlestep_enabled) {\n\n save_cpu_state(ctx, 0);\n\n gen_helper_0e0i(raise_exception, EXCP_DEBUG);\n\n }\n\n tcg_gen_exit_tb(0);\n\n break;\n\n default:\n\n MIPS_DEBUG(\"unknown branch\");\n\n break;\n\n }\n\n }\n\n}\n", + "output": "1", + "index": 27215 + } +] \ No newline at end of file