[FFmpeg-devel] [PATCH] vorbisdec: Simplify, do no calculate same value twice.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Wed Apr 11 21:45:32 CEST 2012


The 0 assignment is just for paranoia reasons, the function
is only called from init and we should bail out directly
on failure.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
 libavcodec/vorbisdec.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index ddc79fc..2268a45 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -685,10 +685,13 @@ static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
         res_setup->begin          = get_bits(gb, 24);
         res_setup->end            = get_bits(gb, 24);
         res_setup->partition_size = get_bits(gb, 24) + 1;
+        res_setup->ptns_to_read =
+            (res_setup->end - res_setup->begin) / res_setup->partition_size;
         /* Validations to prevent a buffer overflow later. */
         if (res_setup->begin>res_setup->end ||
             res_setup->end > (res_setup->type == 2 ? vc->audio_channels : 1) * vc->blocksize[1] / 2 ||
-            (res_setup->end-res_setup->begin) / res_setup->partition_size > V_MAX_PARTITIONS) {
+            res_setup->ptns_to_read > V_MAX_PARTITIONS) {
+            res_setup->ptns_to_read = 0;
             av_log(vc->avccontext, AV_LOG_ERROR,
                    "partition out of bounds: type, begin, end, size, blocksize: %"PRIu16", %"PRIu32", %"PRIu32", %u, %"PRIu32"\n",
                    res_setup->type, res_setup->begin, res_setup->end,
@@ -699,8 +702,6 @@ static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
         res_setup->classifications = get_bits(gb, 6) + 1;
         GET_VALIDATED_INDEX(res_setup->classbook, 8, vc->codebook_count)
 
-        res_setup->ptns_to_read =
-            (res_setup->end - res_setup->begin) / res_setup->partition_size;
         res_setup->classifs = av_malloc(res_setup->ptns_to_read *
                                         vc->audio_channels *
                                         sizeof(*res_setup->classifs));
-- 
1.7.10



More information about the ffmpeg-devel mailing list