From: Andre Noll Date: Sun, 24 Oct 2010 17:27:55 +0000 (+0200) Subject: vss: Introduce extra_header_buf. X-Git-Tag: v0.4.6~19^2~5 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=ead9cdc8160656e868f1d709ad1a764f9dcc3a2f vss: Introduce extra_header_buf. For the same reasons the extra data buffer is necessary, we also need to reserve an extra buffer for the header in order to not read-overflow the header buffer provided by the new get_header() function. --- diff --git a/vss.c b/vss.c index 8b374521..2dab278d 100644 --- a/vss.c +++ b/vss.c @@ -167,6 +167,8 @@ struct fec_client { struct timeval next_header_time; /** Used for the last source pointer of an audio file. */ unsigned char *extra_src_buf; + /** Needed for the last slice of the audio file header. */ + unsigned char *extra_header_buf; /** Extra slices needed to store largest chunk + header. */ int num_extra_slices; /** Contains the FEC-encoded data. */ @@ -327,6 +329,7 @@ static int initialize_fec_client(struct fec_client *fc, struct vss_task *vsst) fc->src_data = para_realloc(fc->src_data, k * sizeof(char *)); fc->enc_buf = para_realloc(fc->enc_buf, fc->mps); fc->extra_src_buf = para_realloc(fc->extra_src_buf, fc->mps); + fc->extra_header_buf = para_realloc(fc->extra_header_buf, fc->mps); fc->state = FEC_STATE_READY_TO_RUN; fc->next_header_time.tv_sec = 0; @@ -516,12 +519,27 @@ static int setup_next_fec_group(struct fec_client *fc, struct vss_task *vsst) fc->current_slice_num = 0; if (g->num == 0) set_group_timing(fc, vsst); - /* setup header slices */ buf = vsst->header_buf; for (i = 0; i < g->num_header_slices; i++) { - fc->src_data[i] = (const unsigned char *)buf; - buf += g->slice_bytes; + if (buf + g->slice_bytes <= vsst->header_buf + vsst->header_len) { + fc->src_data[i] = (const unsigned char *)buf; + buf += g->slice_bytes; + continue; + } + /* + * Can not use vss->header_buf for this slice as it + * goes beyond the buffer. This slice will not be fully + * used. + */ + uint32_t payload_size = vsst->header_buf + + vsst->header_len - buf; + memcpy(fc->extra_header_buf, buf, payload_size); + if (payload_size < g->slice_bytes) + memset(fc->extra_header_buf + payload_size, 0, + g->slice_bytes - payload_size); + fc->src_data[i] = fc->extra_header_buf; + assert(i == g->num_header_slices - 1); } /* setup data slices */ @@ -530,8 +548,7 @@ static int setup_next_fec_group(struct fec_client *fc, struct vss_task *vsst) if (buf + g->slice_bytes > vsst->map + mmd->size) { /* * Can not use the memory mapped audio file for this - * slice as it goes beyond the map. This slice will not - * be fully used. + * slice as it goes beyond the map. */ uint32_t payload_size = vsst->map + mmd->size - buf; memcpy(fc->extra_src_buf, buf, payload_size); @@ -627,6 +644,7 @@ void vss_del_fec_client(struct fec_client *fc) free(fc->src_data); free(fc->enc_buf); free(fc->extra_src_buf); + free(fc->extra_header_buf); fec_free(fc->parms); free(fc); }