Changeset 5731


Ignore:
Timestamp:
Jan 24, 2018 2:37:39 AM (6 years ago)
Author:
ming
Message:

Re #2084: Make sure the output size of opus_decode() doesn't exceed the available frame size.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-codec/opus.c

    r5728 r5731  
    2626#include <pjmedia/endpoint.h> 
    2727#include <pj/log.h> 
     28#include <pj/math.h> 
    2829 
    2930#if defined(PJMEDIA_HAS_OPUS_CODEC) && (PJMEDIA_HAS_OPUS_CODEC!=0) 
     
    976977     * is missing. 
    977978     */ 
     979    frm_size = output->size / (sizeof(opus_int16) * 
     980               opus_data->cfg.channel_cnt); 
    978981    if (inframe->type != PJMEDIA_FRAME_TYPE_AUDIO || fec) { 
    979         frm_size = opus_data->cfg.sample_rate * opus_data->ptime / 1000; 
    980     } else { 
    981         frm_size = output->size / (sizeof(opus_int16) * 
    982                    opus_data->cfg.channel_cnt); 
     982        frm_size = PJ_MIN(frm_size, 
     983                          opus_data->cfg.sample_rate * 
     984                          opus_data->ptime / 1000); 
    983985    } 
    984986    decoded_samples = opus_decode( opus_data->dec, 
     
    10511053 
    10521054    inframe = &opus_data->dec_frame[opus_data->dec_frame_index]; 
     1055    frm_size = output->size / (sizeof(opus_int16) * 
     1056               opus_data->cfg.channel_cnt); 
    10531057    if (inframe->type != PJMEDIA_FRAME_TYPE_AUDIO) { 
    1054         frm_size = opus_data->cfg.sample_rate * opus_data->ptime/1000; 
    1055     } else { 
    1056         frm_size = output->size / (sizeof(opus_int16) * 
    1057                    opus_data->cfg.channel_cnt); 
     1058        frm_size = PJ_MIN(frm_size, opus_data->cfg.sample_rate * 
     1059                          opus_data->ptime/1000); 
    10581060    } 
    10591061    decoded_samples = opus_decode(opus_data->dec, 
Note: See TracChangeset for help on using the changeset viewer.