]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
afh: Limit chunk numbers to 32 bit.
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 27 Aug 2021 13:12:34 +0000 (15:12 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 28 Mar 2022 20:28:20 +0000 (22:28 +0200)
The number of chunks and the chunk offsets are stored in the audio
file table as 32 bit unsigned integers. Thus, chunk numbers and
sizes cannot exceed 2^32 - 1. Make this fact obvious by changing
the corresponding parameters of aac_afh_get_chunk() from size_t or
unsigned long to uint32_t.

aac_afh.c
afh.c
afh.h
afh_common.c
afh_recv.c
vss.c

index 026df50f00c43bff16294d3ec26a869517f7e3c1..5c1225b62b2e179026dadf7638d4f44f041345cb 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -35,13 +35,13 @@ struct aac_afh_context {
 static uint32_t aac_afh_read_cb(void *user_data, void *dest, uint32_t want)
 {
        struct aac_afh_context *c = user_data;
-       uint32_t have, rv;
+       size_t have, rv;
 
        if (want == 0 || c->fpos >= c->mapsize)
                return 0;
        have = c->mapsize - c->fpos;
-       rv = PARA_MIN(have, want);
-       PARA_DEBUG_LOG("reading %u bytes @%zu\n", rv, c->fpos);
+       rv = PARA_MIN(have, (size_t)want);
+       PARA_DEBUG_LOG("reading %zu bytes @%zu\n", rv, c->fpos);
        memcpy(dest, c->map + c->fpos, rv);
        c->fpos += rv;
        return rv;
@@ -126,8 +126,8 @@ static void aac_afh_close(void *afh_context)
  */
 int32_t mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, const int32_t sample);
 
-static int aac_afh_get_chunk(long unsigned chunk_num, void *afh_context,
-               const char **buf, size_t *len)
+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;
@@ -166,8 +166,7 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd,
        struct aac_afh_context *c;
        int64_t tmp;
        const char *buf;
-       size_t sz;
-       uint32_t n;
+       uint32_t n, len;
 
        ret = aac_afh_open(map, numbytes, (void **)&c);
        if (ret < 0)
@@ -192,16 +191,16 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd,
        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, &sz) < 0)
+               if (aac_afh_get_chunk(n, c, &buf, &len) < 0)
                        break;
-               afhi->max_chunk_size = PARA_MAX((size_t)afhi->max_chunk_size, sz);
+               afhi->max_chunk_size = PARA_MAX(afhi->max_chunk_size, len);
        }
 
        tmp = c->masc.sbr_present_flag == 1? 2048 : 1024;
        afhi->seconds_total = tmp * afhi->chunks_total / afhi->frequency;
        ms2tv(1000 * tmp / afhi->frequency, &afhi->chunk_tv);
 
-       if (aac_afh_get_chunk(0, c, &buf, &sz) >= 0)
+       if (aac_afh_get_chunk(0, c, &buf, &len) >= 0)
                numbytes -= buf - map;
        afhi->bitrate = 8 * numbytes / afhi->seconds_total / 1000;
        _aac_afh_get_taginfo(c->mp4ff, &afhi->tags);
diff --git a/afh.c b/afh.c
index c896a7d1eff4a843e2e61a4ec8b6dac4982ed197..e419d2708d7224aaa5330515b11d45947c0d5fab 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -159,7 +159,7 @@ static void print_chunk_table(struct afh_info *afhi, int audio_format_id,
                struct timeval tv;
                long unsigned from, to;
                const char *buf;
-               size_t len;
+               uint32_t len;
                tv_scale(i, &afhi->chunk_tv, &tv);
                from = tv2ms(&tv);
                tv_scale(i + 1, &afhi->chunk_tv, &tv);
@@ -177,7 +177,7 @@ static void print_chunk_table(struct afh_info *afhi, int audio_format_id,
                printf("%td - %td", buf - (const char *)map,
                        buf + len - (const char *)map);
                if (!OPT_GIVEN(PARSER_FRIENDLY))
-                       printf(" (%zu)", len);
+                       printf(" (%u)", len);
                printf("\n");
        }
        afh_close(ctx, audio_format_id);
diff --git a/afh.h b/afh.h
index b3295f6e2fda111bd30ec5d20cd2431bbea325a6..ba72d80e5917b103e879ce221526d1a1a5e3fccc 100644 (file)
--- a/afh.h
+++ b/afh.h
@@ -111,8 +111,8 @@ struct audio_format_handler {
         * portion of the memory mapped audio file. The caller must not call
         * free() on it.
         */
-       int (*get_chunk)(long unsigned chunk_num, void *afh_context,
-               const char **buf, size_t *len);
+       int (*get_chunk)(uint32_t chunk_num, void *afh_context,
+               const char **buf, uint32_t *len);
        /** Deallocate the resources occupied by ->open(). */
        void (*close)(void *afh_context);
        /**
@@ -131,7 +131,7 @@ int compute_afhi(const char *path, char *data, size_t size,
 const char *audio_format_name(int);
 __must_check int afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi,
                uint8_t audio_format_id, const void *map, size_t mapsize,
-               const char **buf, size_t *len, void **afh_context);
+               const char **buf, uint32_t *len, void **afh_context);
 void afh_close(void *afh_context, uint8_t audio_format_id);
 int32_t afh_get_start_chunk(int32_t approx_chunk_num,
                const struct afh_info *afhi, uint8_t audio_format_id);
index a267f58b106b9f0df09d3a8dad99368c3c519401..7e8f63d22a2126494d53e94457278be06142d4f7 100644 (file)
@@ -219,7 +219,7 @@ void clear_afhi(struct afh_info *afhi)
        free(afhi->tags.comment);
 }
 
-static inline size_t get_chunk_len(long unsigned chunk_num,
+static inline uint32_t get_chunk_len(long unsigned chunk_num,
                const struct afh_info *afhi)
 {
        return afhi->chunk_table[chunk_num + 1] - afhi->chunk_table[chunk_num];
@@ -247,7 +247,7 @@ static inline size_t get_chunk_len(long unsigned chunk_num,
  */
 __must_check int afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi,
                uint8_t audio_format_id, const void *map, size_t mapsize,
-               const char **buf, size_t *len, void **afh_context)
+               const char **buf, uint32_t *len, void **afh_context)
 {
        struct audio_format_handler *afh = afl[audio_format_id];
 
index 4f8ff4974f018ef92e5055ac7a28bf337e3aa301..6a0ec239bbcbd120efd130b5f8f24c2b136d4516 100644 (file)
@@ -174,6 +174,7 @@ static int afh_recv_post_select(__a_unused struct sched *s, void *context)
        char *buf;
        const char *start;
        size_t size;
+       uint32_t len;
        struct timeval chunk_time;
        unsigned j_given = RECV_CMD_OPT_GIVEN(AFH, JUST_IN_TIME, lpr);
        unsigned H_given = RECV_CMD_OPT_GIVEN(AFH, NO_HEADER, lpr);
@@ -197,12 +198,12 @@ static int afh_recv_post_select(__a_unused struct sched *s, void *context)
                long unsigned n;
                for (n = pard->first_chunk; n < pard->last_chunk; n++) {
                        ret = afh_get_chunk(n, afhi, pard->audio_format_num,
-                               pard->map, pard->map_size, &start, &size,
+                               pard->map, pard->map_size, &start, &len,
                                &pard->afh_context);
                        if (ret < 0)
                                goto out;
-                       PARA_DEBUG_LOG("adding %zu bytes\n", size);
-                       btr_add_output_dont_free(start, size, btrn);
+                       PARA_DEBUG_LOG("adding %u bytes\n", len);
+                       btr_add_output_dont_free(start, len, btrn);
                }
                ret = -E_RECV_EOF;
                goto out;
@@ -218,12 +219,12 @@ static int afh_recv_post_select(__a_unused struct sched *s, void *context)
        }
        ret = afh_get_chunk(pard->current_chunk, afhi,
                pard->audio_format_num, pard->map,
-               pard->map_size, &start, &size,
+               pard->map_size, &start, &len,
                &pard->afh_context);
        if (ret < 0)
                goto out;
        PARA_DEBUG_LOG("adding chunk %u\n", pard->current_chunk);
-       btr_add_output_dont_free(start, size, btrn);
+       btr_add_output_dont_free(start, len, btrn);
        if (pard->current_chunk >= pard->last_chunk) {
                ret = -E_RECV_EOF;
                goto out;
diff --git a/vss.c b/vss.c
index a4dfa94ed5a20f136ed83b8c4d003afd3f187886..eb51a1b3b64054a2c3f5862cae21ae9a5af99bdb 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -348,7 +348,7 @@ static int initialize_fec_client(struct fec_client *fc, struct vss_task *vsst)
 }
 
 static int vss_get_chunk(int chunk_num, struct vss_task *vsst,
-               char **buf, size_t *sz)
+               char **buf, uint32_t *len)
 {
        int ret;
 
@@ -363,15 +363,15 @@ static int vss_get_chunk(int chunk_num, struct vss_task *vsst,
        if (chunk_num == 0 && vsst->header_len > 0) {
                assert(vsst->header_buf);
                *buf = vsst->header_buf; /* stripped header */
-               *sz = vsst->header_len;
+               *len = vsst->header_len;
                return 0;
        }
        ret = afh_get_chunk(chunk_num, &mmd->afd.afhi,
                mmd->afd.audio_format_id, vsst->map, vsst->mapsize,
-               (const char **)buf, sz, &vsst->afh_context);
+               (const char **)buf, len, &vsst->afh_context);
        if (ret < 0) {
                *buf = NULL;
-               *sz = 0;
+               *len = 0;
        }
        return ret;
 }
@@ -380,7 +380,7 @@ static int compute_group_size(struct vss_task *vsst, struct fec_group *g,
                int max_bytes)
 {
        char *buf;
-       size_t len;
+       uint32_t len;
        int ret, i, max_chunks = PARA_MAX(1LU, 150 / tv2ms(vss_chunk_time()));
 
        if (g->first_chunk == 0) {
@@ -587,7 +587,7 @@ static int setup_next_fec_group(struct fec_client *fc, struct vss_task *vsst)
        slice_copied = 0;
        for (c = g->first_chunk; c < g->first_chunk + g->num_chunks; c++) {
                char *buf;
-               size_t src_len;
+               uint32_t src_len;
                ret = vss_get_chunk(c, vsst, &buf, &src_len);
                if (ret < 0)
                        return ret;
@@ -1030,7 +1030,7 @@ static void vss_send(struct vss_task *vsst)
        struct timeval due;
        struct fec_client *fc, *tmp_fc;
        char *buf;
-       size_t len;
+       uint32_t len;
 
        if (!vsst->map || !vss_playing())
                return;