]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mp4.c
mp4: Fail early on invalid sample rate or sample count.
[paraslash.git] / mp4.c
diff --git a/mp4.c b/mp4.c
index 869b80fa966dbcef2d039935a4a44053d21f963b..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)
@@ -680,13 +697,17 @@ int mp4_set_sample_position(struct mp4 *f, uint32_t sample)
        return 1;
 }
 
-int32_t mp4_get_sample_size(const struct mp4 *f, int sample)
+int mp4_get_sample_size(const struct mp4 *f, uint32_t sample, uint32_t *result)
 {
        const struct mp4_track *t = &f->track;
 
+       if (sample >= t->stsz_sample_count)
+               return -ERRNO_TO_PARA_ERROR(EINVAL);
        if (t->stsz_sample_size != 0)
-               return t->stsz_sample_size;
-       return t->stsz_table[sample];
+               *result = t->stsz_sample_size;
+       else
+               *result = t->stsz_table[sample];
+       return 1;
 }
 
 uint32_t mp4_get_sample_rate(const struct mp4 *f)
@@ -694,7 +715,7 @@ uint32_t mp4_get_sample_rate(const struct mp4 *f)
        return f->track.sample_rate;
 }
 
-uint32_t mp4_get_channel_count(const struct mp4 *f)
+uint16_t mp4_get_channel_count(const struct mp4 *f)
 {
        return f->track.channel_count;
 }