]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Fail early on invalid sample rate or sample count.
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 27 Aug 2021 17:06:11 +0000 (19:06 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 27 Jun 2022 14:45:56 +0000 (16:45 +0200)
If the sample rate or the sample count happen to be zero, we should
fail the open rather than return success and let the caller deal with
it. This patch moves the corresponding sanity checks from aac_afh.c
to mp4_open_read() of mp4.c. The sample rate is always read while
sample count is skipped for metadata-only opens. So the first check
belongs to the common open_file() while the second check needs to go
to mp4_open_read().

aac_afh.c
mp4.c

index 0f7f3fa925d24e6e4a39b80aac1aa78ec4cc89a1..cc3bf415c82f05ce7f529610a01dc25586597fc8 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -123,7 +123,6 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd,
                struct afh_info *afhi)
 {
        int ret;
-       int32_t rv;
        struct aac_afh_context *c;
        uint64_t milliseconds;
        const char *buf;
@@ -133,20 +132,13 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd,
        if (ret < 0)
                return ret;
 
-       ret = -E_MP4_BAD_SAMPLERATE;
-       rv = mp4_get_sample_rate(c->mp4);
-       if (rv <= 0)
-               goto close;
-       afhi->frequency = rv;
-
+       afhi->frequency = mp4_get_sample_rate(c->mp4);
+       assert(afhi->frequency > 0);
        afhi->channels = mp4_get_channel_count(c->mp4);
        assert(afhi->channels > 0);
+       afhi->chunks_total = mp4_num_samples(c->mp4);
+       assert(afhi->chunks_total > 0);
 
-       ret = -E_MP4_BAD_SAMPLE_COUNT;
-       rv = mp4_num_samples(c->mp4);
-       if (rv <= 0)
-               goto close;
-       afhi->chunks_total = rv;
        afhi->max_chunk_size = 0;
        for (n = 0; n < afhi->chunks_total; n++) {
                if (aac_afh_get_chunk(n, c, &buf, &len) < 0)
@@ -161,7 +153,6 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd,
        afhi->bitrate = 8 * numbytes / afhi->seconds_total / 1000;
        aac_afh_get_taginfo(c->mp4, &afhi->tags);
        ret = 1;
-close:
        aac_afh_close(c);
        return ret;
 }
diff --git a/mp4.c b/mp4.c
index 18f43925aef377ae620643a886df8502988fa509..b12cbbf48c121c83c8b1bf40c92196fa5d051841 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -592,6 +592,9 @@ static int open_file(const struct mp4_callback *cb, bool meta_only, struct mp4 *
        ret = -E_MP4_TRACK;
        if (f->track.channel_count == 0)
                goto fail;
+       ret = -E_MP4_BAD_SAMPLERATE;
+       if (f->track.sample_rate == 0)
+               goto fail;
        *result = f;
        return 1;
 fail:
@@ -602,7 +605,21 @@ fail:
 
 int mp4_open_read(const struct mp4_callback *cb, struct mp4 **result)
 {
-       return open_file(cb, false, result);
+       struct mp4 *f;
+       int ret;
+
+       *result = NULL;
+       ret = open_file(cb, false, &f);
+       if (ret < 0)
+               return ret;
+       ret = -E_MP4_BAD_SAMPLE_COUNT;
+       if (f->track.stsz_sample_count == 0)
+               goto fail;
+       *result = f;
+       return 1;
+fail:
+       mp4_close(f);
+       return ret;
 }
 
 void mp4_close(struct mp4 *f)