[FFmpeg-cvslog] avcodec/h264: Do not fail with randomly truncated VUIs
Michael Niedermayer
git at videolan.org
Sat Apr 11 22:12:30 CEST 2015
ffmpeg | branch: release/2.6 | Michael Niedermayer <michaelni at gmx.at> | Fri Apr 10 18:35:07 2015 +0200| [05b448082ae093755336897408b21736bb704b33] | committer: Michael Niedermayer
avcodec/h264: Do not fail with randomly truncated VUIs
Fixes Ticket4445
Tested-by: Vittorio Giovara <vittorio.giovara at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
(cherry picked from commit bc48c88918f767e0dffcd138ae8e5c3052e8a92f)
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=05b448082ae093755336897408b21736bb704b33
---
libavcodec/h264.c | 9 +++++++--
libavcodec/h264.h | 2 +-
libavcodec/h264_parser.c | 2 +-
libavcodec/h264_ps.c | 7 ++++---
4 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 8268c87..a32366e 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1636,7 +1636,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)
@@ -1645,8 +1647,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 a9a351d..b260d55 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -777,7 +777,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 8eda6b8..6e8b1e8 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -280,7 +280,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 a9c199f..fa4bc78 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -297,7 +297,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;
@@ -518,9 +518,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)
More information about the ffmpeg-cvslog
mailing list