[PATCH] Fix decoding crash on some trashed interlaced MPEG2 streams. This fixes issue 2367.
Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> writes:
From 20e1e656ab07edbfaec5e329a408139720c6b8e7 Mon Sep 17 00:00:00 2001 From: anatoly <anatoly.nenashev at ovsoft.ru> Date: Fri, 18 Feb 2011 01:01:45 +0300 Subject: [PATCH] Fix decoding crash on some trashed interlaced MPEG2 streams. This fixes issue 2367.
--- libavcodec/mpeg12.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 3c73627..28292ab 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1763,7 +1763,12 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift; s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift;
+ if (s->mb_intra || !field_pic || s->last_picture.data[0] || + s->first_field || s->picture_structure != s->field_select[0][0] + 1) {
Is it really necessary to do all these checks per MB?
MPV_decode_mb(s, s->block); + } else { + av_log(avctx, AV_LOG_ERROR, "Some restrictions for inter prediction are broken, skipping macroblock\n"); + }
if (++s->mb_x >= s->mb_width) { const int mb_size= 16>>s->avctx->lowres; -- 1.7.1
-- M?ns Rullg?rd mans at mansr.com
On 18.02.2011 03:47, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From 20e1e656ab07edbfaec5e329a408139720c6b8e7 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Fri, 18 Feb 2011 01:01:45 +0300 Subject: [PATCH] Fix decoding crash on some trashed interlaced MPEG2 streams. This fixes issue 2367.
--- libavcodec/mpeg12.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 3c73627..28292ab 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1763,7 +1763,12 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, s->dest[1] +=(16>> lowres)>> s->chroma_x_shift; s->dest[2] +=(16>> lowres)>> s->chroma_x_shift;
+ if (s->mb_intra || !field_pic || s->last_picture.data[0] || + s->first_field || s->picture_structure != s->field_select[0][0] + 1) {
Is it really necessary to do all these checks per MB?
You are right. Checks for "field_pic", "s->last_picture.data[0]", "s->first_field" can be done outside the loop. Changed patch in attachment.
Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 03:47, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From 20e1e656ab07edbfaec5e329a408139720c6b8e7 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Fri, 18 Feb 2011 01:01:45 +0300 Subject: [PATCH] Fix decoding crash on some trashed interlaced MPEG2 streams. This fixes issue 2367.
--- libavcodec/mpeg12.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 3c73627..28292ab 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1763,7 +1763,12 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, s->dest[1] +=(16>> lowres)>> s->chroma_x_shift; s->dest[2] +=(16>> lowres)>> s->chroma_x_shift;
+ if (s->mb_intra || !field_pic || s->last_picture.data[0] || + s->first_field || s->picture_structure != s->field_select[0][0] + 1) {
Is it really necessary to do all these checks per MB?
You are right. Checks for "field_pic", "s->last_picture.data[0]", "s->first_field" can be done outside the loop. Changed patch in attachment.
From ecdb1bfe09823bf423a86e6866b129e5bcabf14f Mon Sep 17 00:00:00 2001 From: anatoly <anatoly.nenashev at ovsoft.ru> Date: Fri, 18 Feb 2011 12:08:05 +0300 Subject: [PATCH] Fix crash of decoder on MPEG2 interlaced streams (issue 2367)
--- libavcodec/mpeg12.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 3c73627..45c1881 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1640,6 +1640,8 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, AVCodecContext *avctx= s->avctx; const int field_pic= s->picture_structure != PICT_FRAME; const int lowres= s->avctx->lowres; + const int check_mb_inter = field_pic && !s->first_field && + s->pict_type == FF_P_TYPE && !s->last_picture.data[0];
s->resync_mb_x= s->resync_mb_y= -1; @@ -1763,7 +1765,12 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift; s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift;
+ if (!check_mb_inter || s->mb_intra || + s->picture_structure != s->field_select[0][0] + 1) { MPV_decode_mb(s, s->block); + } else { + av_log(avctx, AV_LOG_ERROR, "Some restrictions for inter prediction are broken, skipping macroblock\n"); + }
What is the actual problem you are trying to detect? Missing reference picture? -- M?ns Rullg?rd mans at mansr.com
On 18.02.2011 15:26, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 03:47, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
From 20e1e656ab07edbfaec5e329a408139720c6b8e7 Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Fri, 18 Feb 2011 01:01:45 +0300 Subject: [PATCH] Fix decoding crash on some trashed interlaced MPEG2 streams. This fixes issue 2367.
--- libavcodec/mpeg12.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 3c73627..28292ab 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1763,7 +1763,12 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, s->dest[1] +=(16>> lowres)>> s->chroma_x_shift; s->dest[2] +=(16>> lowres)>> s->chroma_x_shift;
+ if (s->mb_intra || !field_pic || s->last_picture.data[0] || + s->first_field || s->picture_structure != s->field_select[0][0] + 1) {
Is it really necessary to do all these checks per MB?
You are right. Checks for "field_pic", "s->last_picture.data[0]", "s->first_field" can be done outside the loop. Changed patch in attachment.
From ecdb1bfe09823bf423a86e6866b129e5bcabf14f Mon Sep 17 00:00:00 2001 From: anatoly<anatoly.nenashev at ovsoft.ru> Date: Fri, 18 Feb 2011 12:08:05 +0300 Subject: [PATCH] Fix crash of decoder on MPEG2 interlaced streams (issue 2367)
--- libavcodec/mpeg12.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 3c73627..45c1881 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1640,6 +1640,8 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, AVCodecContext *avctx= s->avctx; const int field_pic= s->picture_structure != PICT_FRAME; const int lowres= s->avctx->lowres; + const int check_mb_inter = field_pic&& !s->first_field&& + s->pict_type == FF_P_TYPE&& !s->last_picture.data[0];
s->resync_mb_x= s->resync_mb_y= -1; @@ -1763,7 +1765,12 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, s->dest[1] +=(16>> lowres)>> s->chroma_x_shift; s->dest[2] +=(16>> lowres)>> s->chroma_x_shift;
+ if (!check_mb_inter || s->mb_intra || + s->picture_structure != s->field_select[0][0] + 1) { MPV_decode_mb(s, s->block); + } else { + av_log(avctx, AV_LOG_ERROR, "Some restrictions for inter prediction are broken, skipping macroblock\n"); + }
What is the actual problem you are trying to detect? Missing reference picture?
The problem is available when second field of first decoded interlaced picture has P-type. In this case inter prediction can be done from the first field of current picture (works fine) or from the second field of previous picture (crashes decoder). Sample exploit attached to issue 2367. This sample was specially prepared to show the problem.
Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 15:26, M?ns Rullg?rd wrote:
What is the actual problem you are trying to detect? Missing reference picture?
The problem is available when second field of first decoded interlaced picture has P-type. In this case inter prediction can be done from the first field of current picture (works fine) or from the second field of previous picture (crashes decoder). Sample exploit attached to issue 2367. This sample was specially prepared to show the problem.
Couldn't that be checked per frame instead of per MB? Sure, doing it per MB might allow decoding some blocks, but is that really worth it? -- M?ns Rullg?rd mans at mansr.com
On 18.02.2011 18:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 15:26, M?ns Rullg?rd wrote:
What is the actual problem you are trying to detect? Missing reference picture?
The problem is available when second field of first decoded interlaced picture has P-type. In this case inter prediction can be done from the first field of current picture (works fine) or from the second field of previous picture (crashes decoder). Sample exploit attached to issue 2367. This sample was specially prepared to show the problem.
Couldn't that be checked per frame instead of per MB? Sure, doing it per MB might allow decoding some blocks, but is that really worth it?
I don't know how to made this check per frame because there may be some macroblocks predicted from the first field of current picture and the other predicted from the second field of previous picture. I can't find this information without decoding each macroblock.
On 18.02.2011 19:09, Anatoly Nenashev wrote:
On 18.02.2011 18:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 15:26, M?ns Rullg?rd wrote:
What is the actual problem you are trying to detect? Missing reference picture?
The problem is available when second field of first decoded interlaced picture has P-type. In this case inter prediction can be done from the first field of current picture (works fine) or from the second field of previous picture (crashes decoder). Sample exploit attached to issue 2367. This sample was specially prepared to show the problem. Couldn't that be checked per frame instead of per MB? Sure, doing it per MB might allow decoding some blocks, but is that really worth it?
I don't know how to made this check per frame because there may be some macroblocks predicted from the first field of current picture and the other predicted from the second field of previous picture. I can't find this information without decoding each macroblock.
May be there is another way to fix this problem. For now mpeg2 decoder doesn't check mismatch of temporal_reference value in first and second fields. We may check if temporal_reference values for the first and second fields are mismatched and then skip second field decoding. May be it's about another problem but this also fixes crash of decoder on exploit sample.
Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 19:09, Anatoly Nenashev wrote:
On 18.02.2011 18:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 15:26, M?ns Rullg?rd wrote:
What is the actual problem you are trying to detect? Missing reference picture?
The problem is available when second field of first decoded interlaced picture has P-type. In this case inter prediction can be done from the first field of current picture (works fine) or from the second field of previous picture (crashes decoder). Sample exploit attached to issue 2367. This sample was specially prepared to show the problem. Couldn't that be checked per frame instead of per MB? Sure, doing it per MB might allow decoding some blocks, but is that really worth it?
I don't know how to made this check per frame because there may be some macroblocks predicted from the first field of current picture and the other predicted from the second field of previous picture. I can't find this information without decoding each macroblock.
May be there is another way to fix this problem. For now mpeg2 decoder doesn't check mismatch of temporal_reference value in first and second fields. We may check if temporal_reference values for the first and second fields are mismatched and then skip second field decoding. May be it's about another problem but this also fixes crash of decoder on exploit sample.
I think this check fixing your crash is accidental. What if you change your file so the temporal_reference fields match? -- M?ns Rullg?rd mans at mansr.com
Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 18:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 15:26, M?ns Rullg?rd wrote:
What is the actual problem you are trying to detect? Missing reference picture?
The problem is available when second field of first decoded interlaced picture has P-type. In this case inter prediction can be done from the first field of current picture (works fine) or from the second field of previous picture (crashes decoder). Sample exploit attached to issue 2367. This sample was specially prepared to show the problem.
Couldn't that be checked per frame instead of per MB? Sure, doing it per MB might allow decoding some blocks, but is that really worth it?
I don't know how to made this check per frame because there may be some macroblocks predicted from the first field of current picture and the other predicted from the second field of previous picture. I can't find this information without decoding each macroblock.
Two possibilities: - ditch the entire frame if any possible references are missing - substitute a dummy picture for missing references The second of these is equivalent to your patch with less per-MB overhead for undamaged files. -- M?ns Rullg?rd mans at mansr.com
M?ns Rullg?rd <mans at mansr.com> writes:
Anatoly Nenashev <anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 18:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 15:26, M?ns Rullg?rd wrote:
What is the actual problem you are trying to detect? Missing reference picture?
The problem is available when second field of first decoded interlaced picture has P-type. In this case inter prediction can be done from the first field of current picture (works fine) or from the second field of previous picture (crashes decoder). Sample exploit attached to issue 2367. This sample was specially prepared to show the problem.
Couldn't that be checked per frame instead of per MB? Sure, doing it per MB might allow decoding some blocks, but is that really worth it?
I don't know how to made this check per frame because there may be some macroblocks predicted from the first field of current picture and the other predicted from the second field of previous picture. I can't find this information without decoding each macroblock.
Two possibilities:
- ditch the entire frame if any possible references are missing
s/frame/picture/
- substitute a dummy picture for missing references
The second of these is equivalent to your patch with less per-MB overhead for undamaged files.
-- M?ns Rullg?rd mans at mansr.com
On 18.02.2011 19:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 18:38, M?ns Rullg?rd wrote:
Anatoly Nenashev<anatoly.nenashev at ovsoft.ru> writes:
On 18.02.2011 15:26, M?ns Rullg?rd wrote:
What is the actual problem you are trying to detect? Missing reference picture?
The problem is available when second field of first decoded interlaced picture has P-type. In this case inter prediction can be done from the first field of current picture (works fine) or from the second field of previous picture (crashes decoder). Sample exploit attached to issue 2367. This sample was specially prepared to show the problem.
Couldn't that be checked per frame instead of per MB? Sure, doing it per MB might allow decoding some blocks, but is that really worth it?
I don't know how to made this check per frame because there may be some macroblocks predicted from the first field of current picture and the other predicted from the second field of previous picture. I can't find this information without decoding each macroblock.
Two possibilities:
- ditch the entire frame if any possible references are missing - substitute a dummy picture for missing references
The second of these is equivalent to your patch with less per-MB overhead for undamaged files.
Second version is implemented.
On Tue, Feb 22, 2011 at 12:07:41PM +0300, Anatoly Nenashev wrote:
On 18.02.2011 19:38, Måns Rullgård wrote:
Anatoly Nenashev<anatoly.nenashev@ovsoft.ru> writes:
On 18.02.2011 18:38, Måns Rullgård wrote:
Anatoly Nenashev<anatoly.nenashev@ovsoft.ru> writes:
On 18.02.2011 15:26, Måns Rullgård wrote:
What is the actual problem you are trying to detect? Missing reference picture?
The problem is available when second field of first decoded interlaced picture has P-type. In this case inter prediction can be done from the first field of current picture (works fine) or from the second field of previous picture (crashes decoder). Sample exploit attached to issue 2367. This sample was specially prepared to show the problem.
Couldn't that be checked per frame instead of per MB? Sure, doing it per MB might allow decoding some blocks, but is that really worth it?
I don't know how to made this check per frame because there may be some macroblocks predicted from the first field of current picture and the other predicted from the second field of previous picture. I can't find this information without decoding each macroblock.
Two possibilities:
- ditch the entire frame if any possible references are missing - substitute a dummy picture for missing references
The second of these is equivalent to your patch with less per-MB overhead for undamaged files.
Second version is implemented.
mpegvideo.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) cf17a29128eb6b8d28e4fb9cd220820500a846ee 0001-Fix-crash-of-interlaced-MPEG2-decoding.patch From ccb5ded4abd41894b9a41c4d59a9a2aad3683ea7 Mon Sep 17 00:00:00 2001 From: anatoly <anatoly.nenashev@ovsoft.ru> Date: Tue, 22 Feb 2011 12:04:50 +0300 Subject: [PATCH] Fix crash of interlaced MPEG2 decoding
a little late but patch applied and issue fixed thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Observe your enemies, for they first find out your faults. -- Antisthenes
On Friday, 18 February 2011 at 10:13, Anatoly Nenashev wrote: [...]
+ } else { + av_log(avctx, AV_LOG_ERROR, "Some restrictions for inter prediction are broken, skipping macroblock\n"); + }
"Some" is not informative. Please revise the message to say which ones are broken or just use something like "Invalid restrictions for inter prediction, skipping macroblock". Regards, Dominik -- MPlayer http://mplayerhq.hu | RPM Fusion http://rpmfusion.org There should be a science of discontent. People need hard times and oppression to develop psychic muscles. -- from "Collected Sayings of Muad'Dib" by the Princess Irulan
Il giorno ven, 18/02/2011 alle 12.13 +0300, Anatoly Nenashev ha scritto:
+ if (!check_mb_inter || s->mb_intra || + s->picture_structure != s->field_select[0][0] + 1) { MPV_decode_mb(s, s->block);
While you're at it, this looks unaligned now, inside the if(). -- Diego Elio Petten? ? Flameeyes http://blog.flameeyes.eu/
participants (5)
-
anatoly.nenashev@ovsoft.ru -
dominik@greysector.net -
flameeyes@gmail.com -
mans@mansr.com -
Michael Niedermayer