Commit 6b1faf5b0b for ffmpeg
commit 6b1faf5b0bc5a61d485620a3daf62203b287d2c4
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Tue Nov 17 12:32:01 2026 -0600
avformat/hevc: allow 32 long-term reference pictures in an SPS
H.265 7.4.3.2.1 allows num_long_term_ref_pics_sps up to 32, as the
decoder does. An SPS with 32 failed hvcC writing.
The codec string test case passes before this change; it guards the
codec string once it comes from hevc.c.
diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index 5a4226994c..697d831261 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -747,7 +747,7 @@ static int hvcc_parse_sps(GetBitContext *gb, HVCCNALUnit *nal,
if (get_bits1(gb)) { // long_term_ref_pics_present_flag
unsigned num_long_term_ref_pics_sps = get_ue_golomb_long(gb);
- if (num_long_term_ref_pics_sps > 31U)
+ if (num_long_term_ref_pics_sps > HEVC_MAX_LONG_TERM_REF_PICS)
return AVERROR_INVALIDDATA;
for (i = 0; i < num_long_term_ref_pics_sps; i++) { // num_long_term_ref_pics_sps
int len = FFMIN(log2_max_pic_order_cnt_lsb_minus4 + 4, 16);
diff --git a/libavformat/tests/codecstring.c b/libavformat/tests/codecstring.c
index bd257dd4d8..091bf04552 100644
--- a/libavformat/tests/codecstring.c
+++ b/libavformat/tests/codecstring.c
@@ -75,6 +75,17 @@ static const uint8_t hevc_hvcc_constraints_full[] = {
0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00,
};
+/* hevc_annexb with the maximum of 32 long-term reference pictures */
+static const uint8_t hevc_annexb_32_long_term_refs[] = {
+ 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03,
+ 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x1e, 0xa0, 0x14,
+ 0x20, 0x79, 0x65, 0x95, 0x9a, 0x49, 0x32, 0xc1, 0x08, 0x00, 0x04, 0x04,
+ 0x03, 0x02, 0x01, 0x40, 0xc0, 0x70, 0x40, 0x24, 0x14, 0x0b, 0x06, 0x03,
+ 0x41, 0xc0, 0xf0, 0x80, 0x44, 0x24, 0x13, 0x0a, 0x05, 0x42, 0xc1, 0x70,
+ 0xc0, 0x64, 0x34, 0x1b, 0x0e, 0x07, 0x43, 0xc1, 0xf7, 0x80, 0xb4, 0x04,
+ 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x64, 0x20,
+};
+
typedef struct TestCase {
const char *name;
enum AVCodecID codec_id;
@@ -114,6 +125,9 @@ static const TestCase cases[] = {
{ "hevc-hvcc-constraints-full", AV_CODEC_ID_HEVC,
MKTAG('h', 'v', 'c', '1'), AV_PROFILE_UNKNOWN,
hevc_hvcc_constraints_full, sizeof(hevc_hvcc_constraints_full) },
+ { "hevc-annexb-32-long-term-refs", AV_CODEC_ID_HEVC,
+ MKTAG('h', 'v', 'c', '1'), AV_PROFILE_UNKNOWN,
+ hevc_annexb_32_long_term_refs, sizeof(hevc_annexb_32_long_term_refs) },
{ "aac-lc", AV_CODEC_ID_AAC, 0,
AV_PROFILE_AAC_LOW, NULL, 0 },
};
diff --git a/tests/ref/fate/codecstring b/tests/ref/fate/codecstring
index 7ef22bd9d7..c1c3be9323 100644
--- a/tests/ref/fate/codecstring
+++ b/tests/ref/fate/codecstring
@@ -11,4 +11,5 @@ hevc-hvcc-zeroed: error
hevc-hvcc-profile-space: hvc1.A1.6.L30.90
hevc-hvcc-constraints: hvc1.1.6.L30.90.00.10
hevc-hvcc-constraints-full: hvc1.1.6.L30.90.10.20.30.40.50
+hevc-annexb-32-long-term-refs: hvc1.1.6.L30.90
aac-lc: mp4a.40.2