History

avformat/mov: Factorize sanity check out

Michael Niedermayer committed 1 year ago

Commit 16b3d3e1 parent 858acd81 file · +21 −13Browse files

Unified · Split

libavformat/mov.c+21−13
@@ -5081,6 +5081,24 @@ static int mov_update_iamf_streams(MOVContext *c, const AVStream *st) · 5080 unmodified lines
50815081 }
50825082 #endif
50835083
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+
50845102 static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
50855103 {
50865104 AVStream *st;
@@ -5113,19 +5131,9 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 26 unmodified lines
51135131 av_freep(&sc->stsc_data);
51145132 }
51155133
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;
51295137
51305138 fix_timescale(c, sc);
51315139

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t