mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +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:
parent
6dd1536186
commit
913dcb4406
3 changed files with 56 additions and 34 deletions
|
@ -653,7 +653,7 @@ srs_error_t SrsVideoFrame::add_sample(char* bytes, int size)
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsVideoCodecConfig* c = vcodec();
|
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.
|
// For HEVC(H.265), try to parse the IDR from NALUs.
|
||||||
if (c && c->id == SrsVideoCodecIdHEVC) {
|
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)
|
// vps_video_parameter_set_id u(4)
|
||||||
int vps_video_parameter_set_id = bs.read_bits(4);
|
int vps_video_parameter_set_id = bs.read_bits(4);
|
||||||
if (vps_video_parameter_set_id < 0 || vps_video_parameter_set_id > 16) {
|
if (vps_video_parameter_set_id < 0 || vps_video_parameter_set_id > SrsHevcMax_VPS_COUNT) {
|
||||||
return err;
|
return srs_error_new(ERROR_HEVC_DECODE_ERROR, "vps id out of range: %d", vps_video_parameter_set_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// select table
|
// 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) {
|
if ((err = bs.read_bits_ue(sps_seq_parameter_set_id)) != srs_success) {
|
||||||
return srs_error_wrap(err, "sps_seq_parameter_set_id");
|
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
|
// for sps_table
|
||||||
SrsHevcDecoderConfigurationRecord *dec_conf_rec = &(vcodec->hevc_dec_conf_record_);
|
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) {
|
if ((err = bs.read_bits_ue(pps_pic_parameter_set_id)) != srs_success) {
|
||||||
return srs_error_wrap(err, "pps_pic_parameter_set_id");
|
return srs_error_wrap(err, "pps_pic_parameter_set_id");
|
||||||
}
|
}
|
||||||
if (pps_pic_parameter_set_id < 0 || pps_pic_parameter_set_id > 256) {
|
if (pps_pic_parameter_set_id < 0 || pps_pic_parameter_set_id >= SrsHevcMax_PPS_COUNT) {
|
||||||
return err;
|
return srs_error_new(ERROR_HEVC_DECODE_ERROR, "pps id out of range: %d", pps_pic_parameter_set_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// select table
|
// select table
|
||||||
|
|
|
@ -490,6 +490,20 @@ struct SrsHevcHvccNalu {
|
||||||
std::vector<SrsHevcNalData> nal_data_vec;
|
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
|
* Profile, tier and level
|
||||||
* @see 7.3.3 Profile, tier and level syntax
|
* @see 7.3.3 Profile, tier and level syntax
|
||||||
|
@ -903,9 +917,9 @@ struct SrsHevcDecoderConfigurationRecord
|
||||||
uint8_t length_size_minus_one;
|
uint8_t length_size_minus_one;
|
||||||
std::vector<SrsHevcHvccNalu> nalu_vec;
|
std::vector<SrsHevcHvccNalu> nalu_vec;
|
||||||
|
|
||||||
SrsHevcRbspVps vps_table[16];
|
SrsHevcRbspVps vps_table[SrsHevcMax_VPS_COUNT];
|
||||||
SrsHevcRbspSps sps_table[32];
|
SrsHevcRbspSps sps_table[SrsHevcMax_SPS_COUNT];
|
||||||
SrsHevcRbspPps pps_table[256];
|
SrsHevcRbspPps pps_table[SrsHevcMax_PPS_COUNT];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3457,8 +3457,9 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsAudioFrame f;
|
SrsAudioFrame f;
|
||||||
SrsAudioCodecConfig cc;
|
SrsAudioCodecConfig* cc = new SrsAudioCodecConfig();
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(&cc));
|
SrsAutoFree(SrsAudioCodecConfig, cc);
|
||||||
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.acodec() != NULL);
|
EXPECT_TRUE(f.acodec() != NULL);
|
||||||
|
|
||||||
HELPER_EXPECT_SUCCESS(f.add_sample((char*)1, 10));
|
HELPER_EXPECT_SUCCESS(f.add_sample((char*)1, 10));
|
||||||
|
@ -3472,7 +3473,6 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
EXPECT_TRUE(2 == f.nb_samples);
|
EXPECT_TRUE(2 == f.nb_samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsAudioFrame f;
|
SrsAudioFrame f;
|
||||||
EXPECT_TRUE(0 == f.nb_samples);
|
EXPECT_TRUE(0 == f.nb_samples);
|
||||||
|
@ -3496,8 +3496,9 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsVideoFrame f;
|
SrsVideoFrame f;
|
||||||
SrsVideoCodecConfig cc;
|
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(&cc));
|
SrsAutoFree(SrsVideoCodecConfig, cc);
|
||||||
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.vcodec() != NULL);
|
EXPECT_TRUE(f.vcodec() != NULL);
|
||||||
|
|
||||||
HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x05", 1));
|
HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x05", 1));
|
||||||
|
@ -3507,8 +3508,9 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsVideoFrame f;
|
SrsVideoFrame f;
|
||||||
SrsVideoCodecConfig cc;
|
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(&cc));
|
SrsAutoFree(SrsVideoCodecConfig, cc);
|
||||||
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.vcodec() != NULL);
|
EXPECT_TRUE(f.vcodec() != NULL);
|
||||||
|
|
||||||
HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x07", 1));
|
HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x07", 1));
|
||||||
|
@ -3517,8 +3519,9 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsVideoFrame f;
|
SrsVideoFrame f;
|
||||||
SrsVideoCodecConfig cc;
|
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(&cc));
|
SrsAutoFree(SrsVideoCodecConfig, cc);
|
||||||
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.vcodec() != NULL);
|
EXPECT_TRUE(f.vcodec() != NULL);
|
||||||
|
|
||||||
HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x08", 1));
|
HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x08", 1));
|
||||||
|
@ -3527,8 +3530,9 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsVideoFrame f;
|
SrsVideoFrame f;
|
||||||
SrsVideoCodecConfig cc;
|
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(&cc));
|
SrsAutoFree(SrsVideoCodecConfig, cc);
|
||||||
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.vcodec() != NULL);
|
EXPECT_TRUE(f.vcodec() != NULL);
|
||||||
|
|
||||||
HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x09", 1));
|
HELPER_EXPECT_SUCCESS(f.add_sample((char*)"\x09", 1));
|
||||||
|
@ -3537,8 +3541,9 @@ VOID TEST(KernelCodecTest, AVFrame)
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsVideoFrame f;
|
SrsVideoFrame f;
|
||||||
SrsVideoCodecConfig cc;
|
SrsVideoCodecConfig* cc = new SrsVideoCodecConfig();
|
||||||
HELPER_EXPECT_SUCCESS(f.initialize(&cc));
|
SrsAutoFree(SrsVideoCodecConfig, cc);
|
||||||
|
HELPER_EXPECT_SUCCESS(f.initialize(cc));
|
||||||
EXPECT_TRUE(f.vcodec() != NULL);
|
EXPECT_TRUE(f.vcodec() != NULL);
|
||||||
|
|
||||||
for (int i = 0; i < SrsMaxNbSamples; i++) {
|
for (int i = 0; i < SrsMaxNbSamples; i++) {
|
||||||
|
@ -4830,11 +4835,11 @@ VOID TEST(KernelUtilityTest, CoverBitsBufferAll)
|
||||||
uint32_t v = 0;
|
uint32_t v = 0;
|
||||||
srs_error_t err = bb.read_bits_ue(v);
|
srs_error_t err = bb.read_bits_ue(v);
|
||||||
HELPER_EXPECT_SUCCESS(err);
|
HELPER_EXPECT_SUCCESS(err);
|
||||||
EXPECT_EQ(1280, v);
|
EXPECT_EQ(1280, (int)v);
|
||||||
|
|
||||||
err = bb.read_bits_ue(v);
|
err = bb.read_bits_ue(v);
|
||||||
HELPER_EXPECT_SUCCESS(err);
|
HELPER_EXPECT_SUCCESS(err);
|
||||||
EXPECT_EQ(720, v);
|
EXPECT_EQ(720, (int)v);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
|
Loading…
Reference in a new issue