/** Read packet table chunk */ static int read_pakt_chunk(AVFormatContext *s, int64_t size) { ByteIOContext *pb = s->pb; AVStream *st = s->streams[0]; CaffContext *caf = s->priv_data; int64_t pos = 0, ccount; int num_packets, i; ccount = url_ftell(pb); num_packets = get_be64(pb); if (num_packets < 0 || INT32_MAX / sizeof(AVIndexEntry) < num_packets) return AVERROR_INVALIDDATA; st->nb_frames = get_be64(pb); /* valid frames */ st->nb_frames += get_be32(pb); /* priming frames */ st->nb_frames += get_be32(pb); /* remainder frames */ st->duration = 0; for (i = 0; i < num_packets; i++) { av_add_index_entry(s->streams[0], pos, st->duration, 0, 0, AVINDEX_KEYFRAME); pos += caf->bytes_per_packet ? caf->bytes_per_packet : ff_mp4_read_descr_len(pb); st->duration += caf->frames_per_packet ? caf->frames_per_packet : ff_mp4_read_descr_len(pb); } if (url_ftell(pb) - ccount != size) { av_log(s, AV_LOG_ERROR, "error reading packet table\n"); return -1; } caf->num_bytes = pos; return 0; }
int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz) { const char *index = data; uint32_t hdr_version; uint32_t ewah_size; struct ewah_bitmap *fsmonitor_dirty; int ret; if (sz < sizeof(uint32_t) + sizeof(uint64_t) + sizeof(uint32_t)) return error("corrupt fsmonitor extension (too short)"); hdr_version = get_be32(index); index += sizeof(uint32_t); if (hdr_version != INDEX_EXTENSION_VERSION) return error("bad fsmonitor version %d", hdr_version); istate->fsmonitor_last_update = get_be64(index); index += sizeof(uint64_t); ewah_size = get_be32(index); index += sizeof(uint32_t); fsmonitor_dirty = ewah_new(); ret = ewah_read_mmap(fsmonitor_dirty, index, ewah_size); if (ret != ewah_size) { ewah_free(fsmonitor_dirty); return error("failed to parse ewah bitmap reading fsmonitor index extension"); } istate->fsmonitor_dirty = fsmonitor_dirty; trace_printf_key(&trace_fsmonitor, "read fsmonitor extension successful"); return 0; }
static void avrcp_cid_hook_cb(const void *data, uint16_t len, void *user_data) { struct step *step; uint8_t pdu, event; util_hexdump('>', data, len, print_avrcp, NULL); pdu = ((uint8_t *) data)[9]; switch (pdu) { case AVRCP_GET_PLAY_STATUS: step = g_new0(struct step, 1); step->callback = CB_AVRCP_PLAY_STATUS_RSP; step->callback_result.song_length = get_be32(data + 13); step->callback_result.song_position = get_be32(data + 17); step->callback_result.play_status = ((uint8_t *) data)[21]; schedule_callback_verification(step); break; case AVRCP_REGISTER_NOTIFICATION: event = ((uint8_t *) data)[13]; switch (event) { case 0x01: step = g_new0(struct step, 1); step->callback = CB_AVRCP_REG_NOTIF_RSP; step->callback_result.play_status = ((uint8_t *) data)[14]; schedule_callback_verification(step); break; case 0x02: step = g_new0(struct step, 1); step->callback = CB_AVRCP_REG_NOTIF_RSP; step->callback_result.rc_index = get_be64(data + 14); schedule_callback_verification(step); break; case 0x05: step = g_new0(struct step, 1); step->callback = CB_AVRCP_REG_NOTIF_RSP; step->callback_result.song_position = get_be32(data + 14); schedule_callback_verification(step); break; } break; case AVRCP_GET_ELEMENT_ATTRIBUTES: step = g_new0(struct step, 1); step->callback = CB_AVRCP_GET_ATTR_RSP; step->callback_result.num_of_attrs = ((uint8_t *) data)[13]; memset(exp_attrs, 0, 2 * sizeof(btrc_element_attr_val_t)); exp_attrs[0].attr_id = get_be16(data + 16); memcpy(exp_attrs[0].text, data + 22, 19); exp_attrs[1].attr_id = get_be16(data + 43); memcpy(exp_attrs[1].text, data + 49, 6); step->callback_result.attrs = exp_attrs; schedule_callback_verification(step); break; } }
static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***argvp) { int id_ok = 0, dst_ok = 0, tos_ok = 0, ttl_ok = 0; char **argv = *argvp; int argc = *argcp; while (argc > 0) { if (strcmp(*argv, "id") == 0) { __u64 id; NEXT_ARG(); if (id_ok++) duparg2("id", *argv); if (get_be64(&id, *argv, 0)) invarg("\"id\" value is invalid\n", *argv); rta_addattr64(rta, len, LWTUNNEL_IP6_ID, id); } else if (strcmp(*argv, "dst") == 0) { inet_prefix addr; NEXT_ARG(); if (dst_ok++) duparg2("dst", *argv); get_addr(&addr, *argv, AF_INET6); rta_addattr_l(rta, len, LWTUNNEL_IP6_DST, &addr.data, addr.bytelen); } else if (strcmp(*argv, "tc") == 0) { __u32 tc; NEXT_ARG(); if (tos_ok++) duparg2("tc", *argv); if (rtnl_dsfield_a2n(&tc, *argv)) invarg("\"tc\" value is invalid\n", *argv); rta_addattr8(rta, len, LWTUNNEL_IP6_TC, tc); } else if (strcmp(*argv, "hoplimit") == 0) { __u8 hoplimit; NEXT_ARG(); if (ttl_ok++) duparg2("hoplimit", *argv); if (get_u8(&hoplimit, *argv, 0)) invarg("\"hoplimit\" value is invalid\n", *argv); rta_addattr8(rta, len, LWTUNNEL_IP6_HOPLIMIT, hoplimit); } else { break; } argc--; argv++; } /* argv is currently the first unparsed argument, * but the lwt_parse_encap() caller will move to the next, * so step back */ *argcp = argc + 1; *argvp = argv - 1; return 0; }
static data_check_t psb_skip_image_resources(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size && file_recovery->calculated_file_size + 16 < file_recovery->file_size + buffer_size/2) { const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2; const unsigned int l=get_be64(buffer, i)+8; #ifdef DEBUG_PSD log_info("Layer info at 0x%lx\n", (long unsigned)(l + file_recovery->calculated_file_size)); #endif if(l<4) return DC_STOP; file_recovery->calculated_file_size+=l; file_recovery->data_check=&psb_skip_layer_info; return psb_skip_layer_info(buffer, buffer_size, file_recovery); } return DC_CONTINUE; }
static void print_uint(uint8_t indent, const uint8_t *data, uint32_t size) { switch (size) { case 1: print_field("%*c0x%2.2x", indent, ' ', data[0]); break; case 2: print_field("%*c0x%4.4x", indent, ' ', get_be16(data)); break; case 4: print_field("%*c0x%8.8x", indent, ' ', get_be32(data)); break; case 8: print_field("%*c0x%16.16" PRIx64, indent, ' ', get_be64(data)); break; default: packet_hexdump(data, size); break; } }
/** Read audio description chunk */ static int read_desc_chunk(AVFormatContext *s) { ByteIOContext *pb = s->pb; CaffContext *caf = s->priv_data; AVStream *st; int flags; /* new audio stream */ st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); /* parse format description */ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->sample_rate = av_int2dbl(get_be64(pb)); st->codec->codec_tag = get_be32(pb); flags = get_be32(pb); caf->bytes_per_packet = get_be32(pb); st->codec->block_align = caf->bytes_per_packet; caf->frames_per_packet = get_be32(pb); st->codec->channels = get_be32(pb); st->codec->bits_per_coded_sample = get_be32(pb); /* calculate bit rate for constant size packets */ if (caf->frames_per_packet > 0 && caf->bytes_per_packet > 0) { st->codec->bit_rate = (uint64_t)st->codec->sample_rate * (uint64_t)caf->bytes_per_packet * 8 / (uint64_t)caf->frames_per_packet; } else { st->codec->bit_rate = 0; } /* determine codec */ if (st->codec->codec_tag == MKBETAG('l','p','c','m')) st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, (flags ^ 0x2) | 0x4); else st->codec->codec_id = ff_codec_get_id(ff_codec_caf_tags, st->codec->codec_tag); return 0; }
static data_check_t psb_skip_color_mode(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery) { const struct psb_file_header *psb=(const struct psb_file_header *)&buffer[buffer_size/2]; psb_image_data_size_max=(uint64_t)be16(psb->channels) * be32(psb->height) * be32(psb->width) * be16(psb->depth) / 8; #ifdef DEBUG_PSD log_info("psb_image_data_size_max %lu\n", (long unsigned)psb_image_data_size_max); #endif while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size && file_recovery->calculated_file_size + 16 < file_recovery->file_size + buffer_size/2) { const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2; const unsigned int l=get_be64(buffer, i)+8; #ifdef DEBUG_PSD log_info("Color mode at 0x%lx\n", (long unsigned)(l + file_recovery->calculated_file_size)); #endif if(l<4) return DC_STOP; file_recovery->calculated_file_size+=l; file_recovery->data_check=&psb_skip_image_resources; return psb_skip_image_resources(buffer, buffer_size, file_recovery); } return DC_CONTINUE; }
static int read_header(AVFormatContext *s, AVFormatParameters *ap) { ByteIOContext *pb = s->pb; CaffContext *caf = s->priv_data; AVStream *st; uint32_t tag = 0; int found_data, ret; int64_t size; url_fskip(pb, 8); /* magic, version, file flags */ /* audio description chunk */ if (get_be32(pb) != MKBETAG('d','e','s','c')) { av_log(s, AV_LOG_ERROR, "desc chunk not present\n"); return AVERROR_INVALIDDATA; } size = get_be64(pb); if (size != 32) return AVERROR_INVALIDDATA; ret = read_desc_chunk(s); if (ret) return ret; st = s->streams[0]; /* parse each chunk */ found_data = 0; while (!url_feof(pb)) { /* stop at data chunk if seeking is not supported or data chunk size is unknown */ if (found_data && (caf->data_size < 0 || url_is_streamed(pb))) break; tag = get_be32(pb); size = get_be64(pb); if (url_feof(pb)) break; switch (tag) { case MKBETAG('d','a','t','a'): url_fskip(pb, 4); /* edit count */ caf->data_start = url_ftell(pb); caf->data_size = size < 0 ? -1 : size - 4; if (caf->data_size > 0 && !url_is_streamed(pb)) url_fskip(pb, caf->data_size); found_data = 1; break; /* magic cookie chunk */ case MKBETAG('k','u','k','i'): if (read_kuki_chunk(s, size)) return AVERROR_INVALIDDATA; break; /* packet table chunk */ case MKBETAG('p','a','k','t'): if (read_pakt_chunk(s, size)) return AVERROR_INVALIDDATA; break; case MKBETAG('i','n','f','o'): read_info_chunk(s, size); break; default: #define _(x) ((x) >= ' ' ? (x) : ' ') av_log(s, AV_LOG_WARNING, "skipping CAF chunk: %08X (%c%c%c%c)\n", tag, _(tag>>24), _((tag>>16)&0xFF), _((tag>>8)&0xFF), _(tag&0xFF)); #undef _ case MKBETAG('f','r','e','e'): if (size < 0) return AVERROR_INVALIDDATA; url_fskip(pb, size); break; } } if (!found_data) return AVERROR_INVALIDDATA; if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) { if (caf->data_size > 0) st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet; } else if (st->nb_index_entries) { st->codec->bit_rate = st->codec->sample_rate * caf->data_size * 8 / st->duration; } else { av_log(s, AV_LOG_ERROR, "Missing packet table. It is required when " "block size or frame size are variable.\n"); return AVERROR_INVALIDDATA; } s->file_size = url_fsize(pb); s->file_size = FFMAX(0, s->file_size); av_set_pts_info(st, 64, 1, st->codec->sample_rate); st->start_time = 0; /* position the stream at the start of data */ if (caf->data_size >= 0) url_fseek(pb, caf->data_start, SEEK_SET); return 0; }
int __acc_cdecl_qsort be64_compare(const void *e1, const void *e2) { const upx_uint64_t d1 = get_be64(e1); const upx_uint64_t d2 = get_be64(e2); return (d1 < d2) ? -1 : ((d1 > d2) ? 1 : 0); }
static int get_sci(__u64 *sci, const char *arg) { return get_be64(sci, arg, 16); }
static int sox_read_header(AVFormatContext *s, AVFormatParameters *ap) { ByteIOContext *pb = s->pb; unsigned header_size, comment_size; double sample_rate, sample_rate_frac; AVStream *st; st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; if (get_le32(pb) == SOX_TAG) { st->codec->codec_id = CODEC_ID_PCM_S32LE; header_size = get_le32(pb); url_fskip(pb, 8); /* sample count */ sample_rate = av_int2dbl(get_le64(pb)); st->codec->channels = get_le32(pb); comment_size = get_le32(pb); } else { st->codec->codec_id = CODEC_ID_PCM_S32BE; header_size = get_be32(pb); url_fskip(pb, 8); /* sample count */ sample_rate = av_int2dbl(get_be64(pb)); st->codec->channels = get_be32(pb); comment_size = get_be32(pb); } if (comment_size > 0xFFFFFFFFU - SOX_FIXED_HDR - 4U) { av_log(s, AV_LOG_ERROR, "invalid comment size (%u)\n", comment_size); return -1; } if (sample_rate <= 0 || sample_rate > INT_MAX) { av_log(s, AV_LOG_ERROR, "invalid sample rate (%f)\n", sample_rate); return -1; } sample_rate_frac = sample_rate - floor(sample_rate); if (sample_rate_frac) av_log(s, AV_LOG_WARNING, "truncating fractional part of sample rate (%f)\n", sample_rate_frac); if ((header_size + 4) & 7 || header_size < SOX_FIXED_HDR + comment_size || st->codec->channels > 65535) /* Reserve top 16 bits */ { av_log(s, AV_LOG_ERROR, "invalid header\n"); return -1; } if (comment_size && comment_size + FF_INPUT_BUFFER_PADDING_SIZE >= comment_size) { char *comment = av_mallocz(comment_size + FF_INPUT_BUFFER_PADDING_SIZE); if (get_buffer(pb, comment, comment_size) != comment_size) { av_freep(&comment); return AVERROR_IO; } av_metadata_set(&s->metadata, "comment", comment); av_freep(&comment); } url_fskip(pb, header_size - SOX_FIXED_HDR - comment_size); st->codec->sample_rate = sample_rate; st->codec->bits_per_coded_sample = 32; st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_coded_sample * st->codec->channels; st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8; av_set_pts_info(st, 64, 1, st->codec->sample_rate); return 0; }