Unified · Split
| @@ -5081,6 +5081,24 @@ static int mov_update_iamf_streams(MOVContext *c, const AVStream *st) · 5080 unmodified lines | ||
| 5081 | 5081 | } |
| 5082 | 5082 | #endif |
| 5083 | 5083 | |
| 5084 | +static int sanity_checks(void *log_obj, MOVStreamContext *sc, int index) | |
| 5085 | +{ | |
| 5086 | + if ((sc->chunk_count && (!sc->stts_count || !sc->stsc_count || | |
| 5087 | + (!sc->sample_size && !sc->sample_count))) || | |
| 5088 | + (!sc->chunk_count && sc->sample_count)) { | |
| 5089 | + av_log(log_obj, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n", | |
| 5090 | + index); | |
| 5091 | + return 1; | |
| 5092 | + } | |
| 5093 | + | |
| 5094 | + if (sc->stsc_count && sc->stsc_data[ sc->stsc_count - 1 ].first > sc->chunk_count) { | |
| 5095 | + av_log(log_obj, AV_LOG_ERROR, "stream %d, contradictionary STSC and STCO\n", | |
| 5096 | + index); | |
| 5097 | + return 2; | |
| 5098 | + } | |
| 5099 | + return 0; | |
| 5100 | +} | |
| 5101 | + | |
| 5084 | 5102 | static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) |
| 5085 | 5103 | { |
| 5086 | 5104 | AVStream *st; |
| @@ -5113,19 +5131,9 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 26 unmodified lines | ||
| 5113 | 5131 | av_freep(&sc->stsc_data); |
| 5114 | 5132 | } |
| 5115 | 5133 | |
| 5116 | − /* sanity checks */ | |
| 5117 | − if ((sc->chunk_count && (!sc->stts_count || !sc->stsc_count || | |
| 5118 | − (!sc->sample_size && !sc->sample_count))) || | |
| 5119 | − (!sc->chunk_count && sc->sample_count)) { | |
| 5120 | − av_log(c->fc, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n", | |
| 5121 | − st->index); | |
| 5122 | − return 0; | |
| 5123 | − } | |
| 5124 | − if (sc->stsc_count && sc->stsc_data[ sc->stsc_count - 1 ].first > sc->chunk_count) { | |
| 5125 | − av_log(c->fc, AV_LOG_ERROR, "stream %d, contradictionary STSC and STCO\n", | |
| 5126 | − st->index); | |
| 5127 | − return AVERROR_INVALIDDATA; | |
| 5128 | − } | |
| 5134 | + ret = sanity_checks(c->fc, sc, st->index); | |
| 5135 | + if (ret) | |
| 5136 | + return ret > 1 ? AVERROR_INVALIDDATA : 0; | |
| 5129 | 5137 | |
| 5130 | 5138 | fix_timescale(c, sc); |
| 5131 | 5139 | |