1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

UTest: Fix crash for stack overflow, allocate object on heap. (#3394)

* UTest: Fix crash for stack overflow, allocate object on heap.
* H265: Refine hevc vps/sps/pps id range.

---------

Co-authored-by: chundonglinlin <chundonglinlin@163.com>
This commit is contained in:
Winlin 2023-01-30 11:20:47 +08:00 committed by GitHub
parent 6dd1536186
commit 913dcb4406
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 34 deletions

View file

@ -653,7 +653,7 @@ srs_error_t SrsVideoFrame::add_sample(char* bytes, int size)
}
SrsVideoCodecConfig* c = vcodec();
if (size <= 0) return err;
if (!bytes || size <= 0) return err;
// For HEVC(H.265), try to parse the IDR from NALUs.
if (c && c->id == SrsVideoCodecIdHEVC) {
@ -1157,8 +1157,8 @@ srs_error_t SrsFormat::hevc_demux_vps_rbsp(char* rbsp, int nb_rbsp)
// vps_video_parameter_set_id u(4)
int vps_video_parameter_set_id = bs.read_bits(4);
if (vps_video_parameter_set_id < 0 || vps_video_parameter_set_id > 16) {
return err;
if (vps_video_parameter_set_id < 0 || vps_video_parameter_set_id > SrsHevcMax_VPS_COUNT) {
return srs_error_new(ERROR_HEVC_DECODE_ERROR, "vps id out of range: %d", vps_video_parameter_set_id);
}
// select table
@ -1331,6 +1331,9 @@ srs_error_t SrsFormat::hevc_demux_sps_rbsp(char* rbsp, int nb_rbsp)
if ((err = bs.read_bits_ue(sps_seq_parameter_set_id)) != srs_success) {
return srs_error_wrap(err, "sps_seq_parameter_set_id");
}
if (sps_seq_parameter_set_id < 0 || sps_seq_parameter_set_id >= SrsHevcMax_SPS_COUNT) {
return srs_error_new(ERROR_HEVC_DECODE_ERROR, "sps id out of range: %d", sps_seq_parameter_set_id);
}
// for sps_table
SrsHevcDecoderConfigurationRecord *dec_conf_rec = &(vcodec->hevc_dec_conf_record_);
@ -1503,8 +1506,8 @@ srs_error_t SrsFormat::hevc_demux_pps_rbsp(char* rbsp, int nb_rbsp)
if ((err = bs.read_bits_ue(pps_pic_parameter_set_id)) != srs_success) {
return srs_error_wrap(err, "pps_pic_parameter_set_id");
}
if (pps_pic_parameter_set_id < 0 || pps_pic_parameter_set_id > 256) {
return err;
if (pps_pic_parameter_set_id < 0 || pps_pic_parameter_set_id >= SrsHevcMax_PPS_COUNT) {
return srs_error_new(ERROR_HEVC_DECODE_ERROR, "pps id out of range: %d", pps_pic_parameter_set_id);
}
// select table

View file

@ -490,6 +490,20 @@ struct SrsHevcHvccNalu {
std::vector<SrsHevcNalData> nal_data_vec;
};
/**
* HEVC Common Max define.
* @doc ITU-T-H.265-2021.pdf
*/
// @see F.7.3.2.1: vps_video_parameter_set_id is u(4).
// @doc ITU-T-H.265-2021.pdf, page 464.
const int SrsHevcMax_VPS_COUNT = 16;
// @see 7.4.3.2.1: sps_seq_parameter_set_id is in [0, 15].
// @doc ITU-T-H.265-2021.pdf, page 95.
const int SrsHevcMax_SPS_COUNT = 16;
// @see 7.4.3.3.1: pps_pic_parameter_set_id is in [0, 63].
// @doc ITU-T-H.265-2021.pdf, page 102.
const int SrsHevcMax_PPS_COUNT = 64;
/**
* Profile, tier and level
* @see 7.3.3 Profile, tier and level syntax
@ -903,9 +917,9 @@ struct SrsHevcDecoderConfigurationRecord
uint8_t length_size_minus_one;
std::vector<SrsHevcHvccNalu> nalu_vec;
SrsHevcRbspVps vps_table[16];
SrsHevcRbspSps sps_table[32];
SrsHevcRbspPps pps_table[256];
SrsHevcRbspVps vps_table[SrsHevcMax_VPS_COUNT];
SrsHevcRbspSps sps_table[SrsHevcMax_SPS_COUNT];
SrsHevcRbspPps pps_table[SrsHevcMax_PPS_COUNT];
};
#endif