aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-04-10 18:35:07 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-04-25 15:06:54 +0200
commitfd90005b4619b5f2731a5ec83af8c60a6bb1a5eb (patch)
tree7b2042ce30baeeced1b1269d3f876bb579b34a5f
parentcf80856cbc790c8dc1b743bd5bdd1093a08467ca (diff)
downloadffmpeg-fd90005b4619b5f2731a5ec83af8c60a6bb1a5eb.tar.gz
avcodec/h264: Do not fail with randomly truncated VUIs
Fixes Ticket4445 Tested-by: Vittorio Giovara <vittorio.giovara@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit bc48c88918f767e0dffcd138ae8e5c3052e8a92f) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/h264.c9
-rw-r--r--libavcodec/h264.h2
-rw-r--r--libavcodec/h264_parser.c2
-rw-r--r--libavcodec/h264_ps.c7
4 files changed, 13 insertions, 7 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 4fde3441f1..47570154cd 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1686,7 +1686,9 @@ again:
break;
case NAL_SPS:
init_get_bits(&h->gb, ptr, bit_length);
- if (ff_h264_decode_seq_parameter_set(h) < 0 && (h->is_avc ? nalsize : 1)) {
+ if (ff_h264_decode_seq_parameter_set(h, 0) >= 0)
+ break;
+ if (h->is_avc ? nalsize : 1) {
av_log(h->avctx, AV_LOG_DEBUG,
"SPS decoding failure, trying again with the complete NAL\n");
if (h->is_avc)
@@ -1695,8 +1697,11 @@ again:
break;
init_get_bits(&h->gb, &buf[buf_index + 1 - consumed],
8*(next_avc - buf_index + consumed - 1));
- ff_h264_decode_seq_parameter_set(h);
+ if (ff_h264_decode_seq_parameter_set(h, 0) >= 0)
+ break;
}
+ init_get_bits(&h->gb, ptr, bit_length);
+ ff_h264_decode_seq_parameter_set(h, 1);
break;
case NAL_PPS:
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index ec0b023267..2c975934a2 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -779,7 +779,7 @@ int ff_h264_decode_sei(H264Context *h);
/**
* Decode SPS
*/
-int ff_h264_decode_seq_parameter_set(H264Context *h);
+int ff_h264_decode_seq_parameter_set(H264Context *h, int ignore_truncation);
/**
* compute profile from sps
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 14d709cd1e..d57bf5f60b 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -271,7 +271,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
init_get_bits(&h->gb, ptr, 8 * dst_length);
switch (h->nal_unit_type) {
case NAL_SPS:
- ff_h264_decode_seq_parameter_set(h);
+ ff_h264_decode_seq_parameter_set(h, 0);
break;
case NAL_PPS:
ff_h264_decode_picture_parameter_set(h, h->gb.size_in_bits);
diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index d969aa1e3e..0e8be36413 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -317,7 +317,7 @@ static void decode_scaling_matrices(H264Context *h, SPS *sps,
}
}
-int ff_h264_decode_seq_parameter_set(H264Context *h)
+int ff_h264_decode_seq_parameter_set(H264Context *h, int ignore_truncation)
{
int profile_idc, level_idc, constraint_set_flags = 0;
unsigned int sps_id;
@@ -538,9 +538,10 @@ int ff_h264_decode_seq_parameter_set(H264Context *h)
}
if (get_bits_left(&h->gb) < 0) {
- av_log(h->avctx, AV_LOG_ERROR,
+ av_log(h->avctx, ignore_truncation ? AV_LOG_WARNING : AV_LOG_ERROR,
"Overread %s by %d bits\n", sps->vui_parameters_present_flag ? "VUI" : "SPS", -get_bits_left(&h->gb));
- goto fail;
+ if (!ignore_truncation)
+ goto fail;
}
if (!sps->sar.den)