]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Improve mp4_get_sample_size().
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 27 Aug 2021 13:38:25 +0000 (15:38 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 6 Jun 2022 18:46:37 +0000 (20:46 +0200)
Use an unsigned type for the sample number and check that the passed
number is within range. Since the function can fail now, let it return
int and return the sample size via an additional pointer argument.

aac_afh.c
mp4.c
mp4.h

index b45db477e0e80ddbe1f170446c92e2df99cdc9e1..de99613d2df6adfa506940d454b61e1b893b7c73 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -90,7 +90,7 @@ static int aac_afh_get_chunk(uint32_t chunk_num, void *afh_context,
                const char **buf, uint32_t *len)
 {
        struct aac_afh_context *c = afh_context;
-       int32_t ss;
+       uint32_t ss;
        size_t offset;
        int ret;
 
@@ -98,9 +98,9 @@ static int aac_afh_get_chunk(uint32_t chunk_num, void *afh_context,
        if (ret < 0)
                return ret;
        offset = c->fpos;
-       ss = mp4_get_sample_size(c->mp4, chunk_num);
-       if (ss <= 0)
-               return -E_MP4_BAD_SAMPLE;
+       ret = mp4_get_sample_size(c->mp4, chunk_num, &ss);
+       if (ret < 0)
+               return ret;
        assert(ss + offset <= c->mapsize);
        *buf = c->map + offset;
        *len = ss;
diff --git a/mp4.c b/mp4.c
index 869b80fa966dbcef2d039935a4a44053d21f963b..205286a24de7498717a6a5ee4c7d0ed3f71577d3 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -680,13 +680,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)
diff --git a/mp4.h b/mp4.h
index ceb8dde29e84b48661734303fa09759821dd6565..15cc6af9e31d74c88a075703fd8c32683e59e2d1 100644 (file)
--- a/mp4.h
+++ b/mp4.h
@@ -22,7 +22,7 @@ struct mp4; /* opaque */
 int mp4_set_sample_position(struct mp4 *f, uint32_t sample);
 int mp4_open_read(const struct mp4_callback *cb, struct mp4 **result);
 void mp4_close(struct mp4 *f);
-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);
 uint32_t mp4_get_sample_rate(const struct mp4 *f);
 uint32_t mp4_get_channel_count(const struct mp4 * f);
 int32_t mp4_num_samples(const struct mp4 *f);