if (!key)
return 0;
if (atom.size < 0)
- return -1;
+ return AVERROR_INVALIDDATA;
str_size = FFMIN3(sizeof(str)-1, str_size, atom.size);
avio_rb32(pb); // version + flags
entries = avio_rb32(pb);
if (entries >= UINT_MAX / sizeof(*sc->drefs))
- return -1;
+ return AVERROR_INVALIDDATA;
sc->drefs = av_mallocz(entries * sizeof(*sc->drefs));
if (!sc->drefs)
return AVERROR(ENOMEM);
int64_t next = avio_tell(pb) + size - 4;
if (size < 12)
- return -1;
+ return AVERROR_INVALIDDATA;
dref->type = avio_rl32(pb);
avio_rb32(pb); // version + flags
comp_brand_size = atom.size - 8;
if (comp_brand_size < 0)
- return -1;
+ return AVERROR_INVALIDDATA;
comp_brands_str = av_malloc(comp_brand_size + 1); /* Add null terminator */
if (!comp_brands_str)
return AVERROR(ENOMEM);
/* this atom should contain all header atoms */
static int mov_read_moov(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
- if (mov_read_default(c, pb, atom) < 0)
- return -1;
+ int ret;
+
+ if ((ret = mov_read_default(c, pb, atom)) < 0)
+ return ret;
/* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */
/* so we don't parse the whole file if over a network */
c->found_moov=1;
sc = st->priv_data;
version = avio_r8(pb);
- if (version > 1)
- return -1; /* unsupported */
-
+ if (version > 1) {
+ av_log_ask_for_sample(c, "unsupported version %d\n", version);
+ return AVERROR_PATCHWELCOME;
+ }
avio_rb24(pb); /* flags */
if (version == 1) {
creation_time = avio_rb64(pb);
st = c->fc->streams[c->fc->nb_streams-1];
if ((uint64_t)atom.size > (1<<30))
- return -1;
+ return AVERROR_INVALIDDATA;
// currently SVQ3 decoder expect full STSD header - so let's fake it
// this should be fixed and just SMI header should be passed
st= c->fc->streams[c->fc->nb_streams-1];
size= (uint64_t)st->codec->extradata_size + atom.size + 8 + FF_INPUT_BUFFER_PADDING_SIZE;
if (size > INT_MAX || (uint64_t)atom.size > INT_MAX)
- return -1;
+ return AVERROR_INVALIDDATA;
buf= av_realloc(st->codec->extradata, size);
if (!buf)
- return -1;
+ return AVERROR(ENOMEM);
st->codec->extradata= buf;
buf+= st->codec->extradata_size;
st->codec->extradata_size= size - FF_INPUT_BUFFER_PADDING_SIZE;
st = c->fc->streams[c->fc->nb_streams-1];
if ((uint64_t)atom.size > (1<<30))
- return -1;
+ return AVERROR_INVALIDDATA;
if (st->codec->codec_id == CODEC_ID_QDM2 || st->codec->codec_id == CODEC_ID_QDMC) {
// pass all frma atom to codec, needed at least for QDMC and QDM2
st->codec->extradata_size = atom.size;
avio_read(pb, st->codec->extradata, atom.size);
} else if (atom.size > 8) { /* to read frma, esds atoms */
- if (mov_read_default(c, pb, atom) < 0)
- return -1;
+ int ret;
+ if ((ret = mov_read_default(c, pb, atom)) < 0)
+ return ret;
} else
avio_skip(pb, atom.size);
return 0;
st = c->fc->streams[c->fc->nb_streams-1];
if ((uint64_t)atom.size > (1<<30))
- return -1;
+ return AVERROR_INVALIDDATA;
if (atom.size >= 10) {
// Broken files created by legacy versions of Libav and FFmpeg will
st = c->fc->streams[c->fc->nb_streams-1];
if ((uint64_t)atom.size > (1<<30))
- return -1;
+ return AVERROR_INVALIDDATA;
av_free(st->codec->extradata);
st->codec->extradata = av_mallocz(atom.size - 40 + FF_INPUT_BUFFER_PADDING_SIZE);
if (!entries)
return 0;
if (entries >= UINT_MAX/sizeof(int64_t))
- return -1;
+ return AVERROR_INVALIDDATA;
sc->chunk_offsets = av_malloc(entries * sizeof(int64_t));
if (!sc->chunk_offsets)
for (i=0; i<entries; i++)
sc->chunk_offsets[i] = avio_rb64(pb);
else
- return -1;
+ return AVERROR_INVALIDDATA;
return 0;
}
/* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */
a.size = size - (avio_tell(pb) - start_pos);
if (a.size > 8) {
- if (mov_read_default(c, pb, a) < 0)
- return -1;
+ int ret;
+ if ((ret = mov_read_default(c, pb, a)) < 0)
+ return ret;
} else if (a.size > 0)
avio_skip(pb, a.size);
}
c->dv_demux = avpriv_dv_init_demux(c->dv_fctx);
if (!c->dv_demux) {
av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n");
- return -1;
+ return AVERROR(ENOMEM);
}
sc->dv_audio_container = 1;
st->codec->codec_id = CODEC_ID_PCM_S16LE;
if (!entries)
return 0;
if (entries >= UINT_MAX / sizeof(*sc->stsc_data))
- return -1;
+ return AVERROR_INVALIDDATA;
sc->stsc_data = av_malloc(entries * sizeof(*sc->stsc_data));
if (!sc->stsc_data)
return AVERROR(ENOMEM);
entries = avio_rb32(pb);
if (entries >= UINT_MAX / sizeof(*sc->stps_data))
- return -1;
+ return AVERROR_INVALIDDATA;
sc->stps_data = av_malloc(entries * sizeof(*sc->stps_data));
if (!sc->stps_data)
return AVERROR(ENOMEM);
av_dlog(c->fc, "keyframe_count = %d\n", entries);
if (entries >= UINT_MAX / sizeof(int))
- return -1;
+ return AVERROR_INVALIDDATA;
sc->keyframes = av_malloc(entries * sizeof(int));
if (!sc->keyframes)
return AVERROR(ENOMEM);
if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
av_log(c->fc, AV_LOG_ERROR, "Invalid sample field size %d\n", field_size);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (!entries)
return 0;
if (entries >= UINT_MAX / sizeof(int) || entries >= (UINT_MAX - 4) / field_size)
- return -1;
+ return AVERROR_INVALIDDATA;
sc->sample_sizes = av_malloc(entries * sizeof(int));
if (!sc->sample_sizes)
return AVERROR(ENOMEM);
if (avio_read(pb, buf, num_bytes) < num_bytes) {
av_freep(&sc->sample_sizes);
av_free(buf);
- return -1;
+ return AVERROR_INVALIDDATA;
}
init_get_bits(&gb, buf, 8*num_bytes);
if (!entries)
return 0;
if (entries >= UINT_MAX / sizeof(*sc->ctts_data))
- return -1;
+ return AVERROR_INVALIDDATA;
sc->ctts_data = av_malloc(entries * sizeof(*sc->ctts_data));
if (!sc->ctts_data)
return AVERROR(ENOMEM);
track_id = avio_rb32(pb);
if (!track_id)
- return -1;
+ return AVERROR_INVALIDDATA;
frag->track_id = track_id;
for (i = 0; i < c->trex_count; i++)
if (c->trex_data[i].track_id == frag->track_id) {
}
if (!trex) {
av_log(c->fc, AV_LOG_ERROR, "could not find corresponding trex\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (flags & 0x01) frag->base_data_offset = avio_rb64(pb);
MOVTrackExt *trex;
if ((uint64_t)c->trex_count+1 >= UINT_MAX / sizeof(*c->trex_data))
- return -1;
+ return AVERROR_INVALIDDATA;
trex = av_realloc(c->trex_data, (c->trex_count+1)*sizeof(*c->trex_data));
if (!trex)
return AVERROR(ENOMEM);
}
if (!st) {
av_log(c->fc, AV_LOG_ERROR, "could not find corresponding track id %d\n", frag->track_id);
- return -1;
+ return AVERROR_INVALIDDATA;
}
sc = st->priv_data;
if (sc->pseudo_stream_id+1 != frag->stsd_id)
sc->ctts_count++;
}
if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data))
- return -1;
+ return AVERROR_INVALIDDATA;
ctts_data = av_realloc(sc->ctts_data,
(entries+sc->ctts_count)*sizeof(*sc->ctts_data));
if (!ctts_data)
avio_rb32(pb); /* dcom atom */
if (avio_rl32(pb) != MKTAG('d','c','o','m'))
- return -1;
+ return AVERROR_INVALIDDATA;
if (avio_rl32(pb) != MKTAG('z','l','i','b')) {
av_log(c->fc, AV_LOG_ERROR, "unknown compression for cmov atom !");
- return -1;
+ return AVERROR_INVALIDDATA;
}
avio_rb32(pb); /* cmvd atom */
if (avio_rl32(pb) != MKTAG('c','m','v','d'))
- return -1;
+ return AVERROR_INVALIDDATA;
moov_len = avio_rb32(pb); /* uncompressed size */
cmov_len = atom.size - 6 * 4;
return ret;
#else
av_log(c->fc, AV_LOG_ERROR, "this file requires zlib support compiled in\n");
- return -1;
+ return AVERROR(ENOSYS);
#endif
}
edit_count = avio_rb32(pb); /* entries */
if ((uint64_t)edit_count*12+8 > atom.size)
- return -1;
+ return AVERROR_INVALIDDATA;
for (i=0; i<edit_count; i++){
int64_t time;
}
if (!mov->found_moov) {
av_log(s, AV_LOG_ERROR, "moov atom not found\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
av_dlog(mov->fc, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb));
if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n",
sc->ffindex, sample->pos);
- return -1;
+ return AVERROR_INVALIDDATA;
}
ret = av_get_packet(sc->pb, pkt, sample->size);
if (ret < 0)
if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp)
sample = 0;
if (sample < 0) /* not sure what to do */
- return -1;
+ return AVERROR_INVALIDDATA;
sc->current_sample = sample;
av_dlog(s, "stream %d, found sample %d\n", st->index, sc->current_sample);
/* adjust ctts index */
int i;
if (stream_index >= s->nb_streams)
- return -1;
+ return AVERROR_INVALIDDATA;
if (sample_time < 0)
sample_time = 0;
st = s->streams[stream_index];
sample = mov_seek_stream(s, st, sample_time, flags);
if (sample < 0)
- return -1;
+ return sample;
/* adjust seek timestamp to found sample timestamp */
seek_timestamp = st->index_entries[sample].timestamp;
int bytes_num = size & 0x7f;
/* SMPTE 379M 5.3.4 guarantee that bytes_num must not exceed 8 bytes */
if (bytes_num > 8)
- return -1;
+ return AVERROR_INVALIDDATA;
size = 0;
while (bytes_num--)
size = size << 8 | avio_r8(pb);
static int klv_read_packet(KLVPacket *klv, AVIOContext *pb)
{
if (!mxf_read_sync(pb, mxf_klv_key, 4))
- return -1;
+ return AVERROR_INVALIDDATA;
klv->offset = avio_tell(pb) - 4;
memcpy(klv->key, mxf_klv_key, 4);
avio_read(pb, klv->key + 4, 12);
int i;
if (length > 61444) /* worst case PAL 1920 samples 8 channels */
- return -1;
+ return AVERROR_INVALIDDATA;
length = av_get_packet(pb, pkt, length);
if (length < 0)
return length;
if (!mxf->aesc && s->key && s->keylen == 16) {
mxf->aesc = av_malloc(av_aes_size);
if (!mxf->aesc)
- return -1;
+ return AVERROR(ENOMEM);
av_aes_init(mxf->aesc, s->key, 128, 1);
}
// crypto context
klv_decode_ber_length(pb);
avio_read(pb, klv->key, 16);
if (!IS_KLV_KEY(klv, mxf_essence_element_key))
- return -1;
+ return AVERROR_INVALIDDATA;
index = mxf_get_stream_index(s, klv);
if (index < 0)
- return -1;
+ return AVERROR_INVALIDDATA;
// source size
klv_decode_ber_length(pb);
orig_size = avio_rb64(pb);
if (orig_size < plaintext_size)
- return -1;
+ return AVERROR_INVALIDDATA;
// enc. code
size = klv_decode_ber_length(pb);
if (size < 32 || size - 32 < orig_size)
- return -1;
+ return AVERROR_INVALIDDATA;
avio_read(pb, ivec, 16);
avio_read(pb, tmpbuf, 16);
if (mxf->aesc)
KLVPacket klv;
while (!s->pb->eof_reached) {
+ int ret;
if (klv_read_packet(&klv, s->pb) < 0)
return -1;
PRINT_KEY(s, "read packet", klv.key);
av_dlog(s, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset);
if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) {
- int res = mxf_decrypt_triplet(s, pkt, &klv);
- if (res < 0) {
+ ret = mxf_decrypt_triplet(s, pkt, &klv);
+ if (ret < 0) {
av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
return 0;
}
if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) {
if (mxf_get_d10_aes3_packet(s->pb, s->streams[index], pkt, klv.length) < 0) {
av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
} else {
- int ret = av_get_packet(s->pb, pkt, klv.length);
+ ret = av_get_packet(s->pb, pkt, klv.length);
if (ret < 0)
return ret;
}
int item_len = avio_rb32(pb);
if (item_len != 18) {
- av_log(mxf->fc, AV_LOG_ERROR, "unsupported primer pack item length\n");
- return -1;
+ av_log_ask_for_sample(pb, "unsupported primer pack item length %d\n",
+ item_len);
+ return AVERROR_PATCHWELCOME;
}
if (item_num > UINT_MAX / item_len)
- return -1;
+ return AVERROR_INVALIDDATA;
mxf->local_tags_count = item_num;
mxf->local_tags = av_malloc(item_num*item_len);
if (!mxf->local_tags)
- return -1;
+ return AVERROR(ENOMEM);
avio_read(pb, mxf->local_tags, item_num*item_len);
return 0;
}
return AVERROR(ENOMEM);
mxf->metadata_sets = av_realloc(mxf->metadata_sets, (mxf->metadata_sets_count + 1) * sizeof(*mxf->metadata_sets));
if (!mxf->metadata_sets)
- return -1;
+ return AVERROR(ENOMEM);
mxf->metadata_sets[mxf->metadata_sets_count] = metadata_set;
mxf->metadata_sets_count++;
return 0;
{
MXFCryptoContext *cryptocontext = arg;
if (size != 16)
- return -1;
+ return AVERROR_INVALIDDATA;
if (IS_KLV_KEY(uid, mxf_crypto_source_container_ul))
avio_read(pb, cryptocontext->source_container_ul, 16);
return 0;
case 0x1901:
mxf->packages_count = avio_rb32(pb);
if (mxf->packages_count >= UINT_MAX / sizeof(UID))
- return -1;
+ return AVERROR_INVALIDDATA;
mxf->packages_refs = av_malloc(mxf->packages_count * sizeof(UID));
if (!mxf->packages_refs)
- return -1;
+ return AVERROR(ENOMEM);
avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
avio_read(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID));
break;
case 0x4403:
package->tracks_count = avio_rb32(pb);
if (package->tracks_count >= UINT_MAX / sizeof(UID))
- return -1;
+ return AVERROR_INVALIDDATA;
package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
if (!package->tracks_refs)
- return -1;
+ return AVERROR(ENOMEM);
avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
break;
case 0x1001:
sequence->structural_components_count = avio_rb32(pb);
if (sequence->structural_components_count >= UINT_MAX / sizeof(UID))
- return -1;
+ return AVERROR_INVALIDDATA;
sequence->structural_components_refs = av_malloc(sequence->structural_components_count * sizeof(UID));
if (!sequence->structural_components_refs)
- return -1;
+ return AVERROR(ENOMEM);
avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
avio_read(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID));
break;
case 0x4403:
package->tracks_count = avio_rb32(pb);
if (package->tracks_count >= UINT_MAX / sizeof(UID))
- return -1;
+ return AVERROR_INVALIDDATA;
package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
if (!package->tracks_refs)
- return -1;
+ return AVERROR(ENOMEM);
avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
break;
case 0x3F01:
descriptor->sub_descriptors_count = avio_rb32(pb);
if (descriptor->sub_descriptors_count >= UINT_MAX / sizeof(UID))
- return -1;
+ return AVERROR_INVALIDDATA;
descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID));
if (!descriptor->sub_descriptors_refs)
- return -1;
+ return AVERROR(ENOMEM);
avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */
avio_read(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID));
break;
if (IS_KLV_KEY(uid, mxf_sony_mpeg4_extradata)) {
descriptor->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
if (!descriptor->extradata)
- return -1;
+ return AVERROR(ENOMEM);
descriptor->extradata_size = size;
avio_read(pb, descriptor->extradata, size);
}
}
if (!material_package) {
av_log(mxf->fc, AV_LOG_ERROR, "no material package found\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
for (i = 0; i < material_package->tracks_count; i++) {
for (k = 0; k < source_package->tracks_count; k++) {
if (!(temp_track = mxf_resolve_strong_ref(mxf, &source_package->tracks_refs[k], Track))) {
av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track strong ref\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (temp_track->track_id == component->source_track_id) {
source_track = temp_track;
st = avformat_new_stream(mxf->fc, NULL);
if (!st) {
av_log(mxf->fc, AV_LOG_ERROR, "could not allocate stream\n");
- return -1;
+ return AVERROR(ENOMEM);
}
st->id = source_track->track_id;
st->priv_data = source_track;
if (!(source_track->sequence = mxf_resolve_strong_ref(mxf, &source_track->sequence_ref, Sequence))) {
av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track sequence strong ref\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
PRINT_KEY(mxf->fc, "data definition ul", source_track->sequence->data_definition_ul);
uint64_t klv_end = avio_tell(pb) + klv->length;
if (!ctx)
- return -1;
+ return AVERROR(ENOMEM);
while (avio_tell(pb) + 4 < klv_end) {
+ int ret;
int tag = avio_rb16(pb);
int size = avio_rb16(pb); /* KLV specified by 0x53 */
uint64_t next = avio_tell(pb) + size;
}
if (ctx_size && tag == 0x3C0A)
avio_read(pb, ctx->uid, 16);
- else if (read_child(ctx, pb, tag, size, uid) < 0)
- return -1;
+ else if ((ret = read_child(ctx, pb, tag, size, uid)) < 0)
+ return ret;
avio_seek(pb, next, SEEK_SET);
}
if (!mxf_read_sync(s->pb, mxf_header_partition_pack_key, 14)) {
av_log(s, AV_LOG_ERROR, "could not find header partition pack key\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
avio_seek(s->pb, -14, SEEK_CUR);
mxf->fc = s;
while (!s->pb->eof_reached) {
+ int ret;
const MXFMetadataReadTableEntry *metadata;
- if (klv_read_packet(&klv, s->pb) < 0)
- return -1;
+ if ((ret = klv_read_packet(&klv, s->pb)) < 0)
+ return ret;
PRINT_KEY(s, "read header", klv.key);
av_dlog(s, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset);
if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key) ||
res = metadata->read(mxf, s->pb, 0, 0, NULL);
if (res < 0) {
av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
- return -1;
+ return res;
}
break;
}
int64_t seconds;
if (!s->bit_rate)
- return -1;
+ return AVERROR_INVALIDDATA;
if (sample_time < 0)
sample_time = 0;
seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den);