diff mbox series

[FFmpeg-devel] avcodec/qpeldsp: copy less for the mc0x cases

Message ID 20220626135146.13096-1-michael@niedermayer.cc
State Accepted
Commit e690d4edf581c42dbd907c0fafe53fba86a00812
Headers show
Series [FFmpeg-devel] avcodec/qpeldsp: copy less for the mc0x cases | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Michael Niedermayer June 26, 2022, 1:51 p.m. UTC
Fixes: out of array access
Fixes: 47936/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-5745039940124672

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/qpeldsp.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Andreas Rheinhardt June 27, 2022, 5:57 a.m. UTC | #1
Michael Niedermayer:
> Fixes: out of array access
> Fixes: 47936/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-5745039940124672
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/qpeldsp.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/qpeldsp.c b/libavcodec/qpeldsp.c
> index 2b9146ceb1..5f937f9d9e 100644
> --- a/libavcodec/qpeldsp.c
> +++ b/libavcodec/qpeldsp.c
> @@ -199,7 +199,7 @@ static void OPNAME ## qpel8_mc01_c(uint8_t *dst, const uint8_t *src,          \
>      uint8_t full[16 * 9];                                                     \
>      uint8_t half[64];                                                         \
>                                                                                \
> -    copy_block9(full, src, 16, stride, 9);                                    \
> +    copy_block8(full, src, 16, stride, 9);                                    \
>      put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
>      OPNAME ## pixels8_l2_8(dst, full, half, stride, 16, 8, 8);                \
>  }                                                                             \
> @@ -209,7 +209,7 @@ static void OPNAME ## qpel8_mc02_c(uint8_t *dst, const uint8_t *src,          \
>  {                                                                             \
>      uint8_t full[16 * 9];                                                     \
>                                                                                \
> -    copy_block9(full, src, 16, stride, 9);                                    \
> +    copy_block8(full, src, 16, stride, 9);                                    \
>      OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);                   \
>  }                                                                             \
>                                                                                \
> @@ -219,7 +219,7 @@ static void OPNAME ## qpel8_mc03_c(uint8_t *dst, const uint8_t *src,          \
>      uint8_t full[16 * 9];                                                     \
>      uint8_t half[64];                                                         \
>                                                                                \
> -    copy_block9(full, src, 16, stride, 9);                                    \
> +    copy_block8(full, src, 16, stride, 9);                                    \
>      put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
>      OPNAME ## pixels8_l2_8(dst, full + 16, half, stride, 16, 8, 8);           \
>  }                                                                             \
> @@ -459,7 +459,7 @@ static void OPNAME ## qpel16_mc01_c(uint8_t *dst, const uint8_t *src,         \
>      uint8_t full[24 * 17];                                                    \
>      uint8_t half[256];                                                        \
>                                                                                \
> -    copy_block17(full, src, 24, stride, 17);                                  \
> +    copy_block16(full, src, 24, stride, 17);                                  \
>      put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
>      OPNAME ## pixels16_l2_8(dst, full, half, stride, 24, 16, 16);             \
>  }                                                                             \
> @@ -469,7 +469,7 @@ static void OPNAME ## qpel16_mc02_c(uint8_t *dst, const uint8_t *src,         \
>  {                                                                             \
>      uint8_t full[24 * 17];                                                    \
>                                                                                \
> -    copy_block17(full, src, 24, stride, 17);                                  \
> +    copy_block16(full, src, 24, stride, 17);                                  \
>      OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);                  \
>  }                                                                             \
>                                                                                \
> @@ -479,7 +479,7 @@ static void OPNAME ## qpel16_mc03_c(uint8_t *dst, const uint8_t *src,         \
>      uint8_t full[24 * 17];                                                    \
>      uint8_t half[256];                                                        \
>                                                                                \
> -    copy_block17(full, src, 24, stride, 17);                                  \
> +    copy_block16(full, src, 24, stride, 17);                                  \
>      put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
>      OPNAME ## pixels16_l2_8(dst, full + 24, half, stride, 24, 16, 16);        \
>  }                                                                             \

Are the arch-specific dsp functions affected by this, too?
Do you happen to know why copy_block9/17 has been used in this code?
(After all, using copy_block8/16 should result in a slight speedup, so I
using copy_block9/17 must have been intentional.)

- Andreas
Michael Niedermayer June 27, 2022, 12:40 p.m. UTC | #2
On Mon, Jun 27, 2022 at 07:57:06AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: out of array access
> > Fixes: 47936/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-5745039940124672
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/qpeldsp.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/libavcodec/qpeldsp.c b/libavcodec/qpeldsp.c
> > index 2b9146ceb1..5f937f9d9e 100644
> > --- a/libavcodec/qpeldsp.c
> > +++ b/libavcodec/qpeldsp.c
> > @@ -199,7 +199,7 @@ static void OPNAME ## qpel8_mc01_c(uint8_t *dst, const uint8_t *src,          \
> >      uint8_t full[16 * 9];                                                     \
> >      uint8_t half[64];                                                         \
> >                                                                                \
> > -    copy_block9(full, src, 16, stride, 9);                                    \
> > +    copy_block8(full, src, 16, stride, 9);                                    \
> >      put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
> >      OPNAME ## pixels8_l2_8(dst, full, half, stride, 16, 8, 8);                \
> >  }                                                                             \
> > @@ -209,7 +209,7 @@ static void OPNAME ## qpel8_mc02_c(uint8_t *dst, const uint8_t *src,          \
> >  {                                                                             \
> >      uint8_t full[16 * 9];                                                     \
> >                                                                                \
> > -    copy_block9(full, src, 16, stride, 9);                                    \
> > +    copy_block8(full, src, 16, stride, 9);                                    \
> >      OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);                   \
> >  }                                                                             \
> >                                                                                \
> > @@ -219,7 +219,7 @@ static void OPNAME ## qpel8_mc03_c(uint8_t *dst, const uint8_t *src,          \
> >      uint8_t full[16 * 9];                                                     \
> >      uint8_t half[64];                                                         \
> >                                                                                \
> > -    copy_block9(full, src, 16, stride, 9);                                    \
> > +    copy_block8(full, src, 16, stride, 9);                                    \
> >      put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
> >      OPNAME ## pixels8_l2_8(dst, full + 16, half, stride, 16, 8, 8);           \
> >  }                                                                             \
> > @@ -459,7 +459,7 @@ static void OPNAME ## qpel16_mc01_c(uint8_t *dst, const uint8_t *src,         \
> >      uint8_t full[24 * 17];                                                    \
> >      uint8_t half[256];                                                        \
> >                                                                                \
> > -    copy_block17(full, src, 24, stride, 17);                                  \
> > +    copy_block16(full, src, 24, stride, 17);                                  \
> >      put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
> >      OPNAME ## pixels16_l2_8(dst, full, half, stride, 24, 16, 16);             \
> >  }                                                                             \
> > @@ -469,7 +469,7 @@ static void OPNAME ## qpel16_mc02_c(uint8_t *dst, const uint8_t *src,         \
> >  {                                                                             \
> >      uint8_t full[24 * 17];                                                    \
> >                                                                                \
> > -    copy_block17(full, src, 24, stride, 17);                                  \
> > +    copy_block16(full, src, 24, stride, 17);                                  \
> >      OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);                  \
> >  }                                                                             \
> >                                                                                \
> > @@ -479,7 +479,7 @@ static void OPNAME ## qpel16_mc03_c(uint8_t *dst, const uint8_t *src,         \
> >      uint8_t full[24 * 17];                                                    \
> >      uint8_t half[256];                                                        \
> >                                                                                \
> > -    copy_block17(full, src, 24, stride, 17);                                  \
> > +    copy_block16(full, src, 24, stride, 17);                                  \
> >      put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
> >      OPNAME ## pixels16_l2_8(dst, full + 24, half, stride, 24, 16, 16);        \
> >  }                                                                             \
> 
> Are the arch-specific dsp functions affected by this, too?

the fuzzer sample does not cause a anomaly in the x86 functions


> Do you happen to know why copy_block9/17 has been used in this code?

probably because there was asm anyway so it was unused code or maybe it
was oversight or some sort of code sharing/code cache use reduction but
these hypothesis dont fit entirely. so i dont really know/rememeber


> (After all, using copy_block8/16 should result in a slight speedup, so I
> using copy_block9/17 must have been intentional.)

[...]
Michael Niedermayer July 12, 2022, 6:13 p.m. UTC | #3
On Mon, Jun 27, 2022 at 02:40:04PM +0200, Michael Niedermayer wrote:
> On Mon, Jun 27, 2022 at 07:57:06AM +0200, Andreas Rheinhardt wrote:
> > Michael Niedermayer:
> > > Fixes: out of array access
> > > Fixes: 47936/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-5745039940124672
> > > 
> > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > >  libavcodec/qpeldsp.c | 12 ++++++------
> > >  1 file changed, 6 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/libavcodec/qpeldsp.c b/libavcodec/qpeldsp.c
> > > index 2b9146ceb1..5f937f9d9e 100644
> > > --- a/libavcodec/qpeldsp.c
> > > +++ b/libavcodec/qpeldsp.c
> > > @@ -199,7 +199,7 @@ static void OPNAME ## qpel8_mc01_c(uint8_t *dst, const uint8_t *src,          \
> > >      uint8_t full[16 * 9];                                                     \
> > >      uint8_t half[64];                                                         \
> > >                                                                                \
> > > -    copy_block9(full, src, 16, stride, 9);                                    \
> > > +    copy_block8(full, src, 16, stride, 9);                                    \
> > >      put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
> > >      OPNAME ## pixels8_l2_8(dst, full, half, stride, 16, 8, 8);                \
> > >  }                                                                             \
> > > @@ -209,7 +209,7 @@ static void OPNAME ## qpel8_mc02_c(uint8_t *dst, const uint8_t *src,          \
> > >  {                                                                             \
> > >      uint8_t full[16 * 9];                                                     \
> > >                                                                                \
> > > -    copy_block9(full, src, 16, stride, 9);                                    \
> > > +    copy_block8(full, src, 16, stride, 9);                                    \
> > >      OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);                   \
> > >  }                                                                             \
> > >                                                                                \
> > > @@ -219,7 +219,7 @@ static void OPNAME ## qpel8_mc03_c(uint8_t *dst, const uint8_t *src,          \
> > >      uint8_t full[16 * 9];                                                     \
> > >      uint8_t half[64];                                                         \
> > >                                                                                \
> > > -    copy_block9(full, src, 16, stride, 9);                                    \
> > > +    copy_block8(full, src, 16, stride, 9);                                    \
> > >      put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
> > >      OPNAME ## pixels8_l2_8(dst, full + 16, half, stride, 16, 8, 8);           \
> > >  }                                                                             \
> > > @@ -459,7 +459,7 @@ static void OPNAME ## qpel16_mc01_c(uint8_t *dst, const uint8_t *src,         \
> > >      uint8_t full[24 * 17];                                                    \
> > >      uint8_t half[256];                                                        \
> > >                                                                                \
> > > -    copy_block17(full, src, 24, stride, 17);                                  \
> > > +    copy_block16(full, src, 24, stride, 17);                                  \
> > >      put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
> > >      OPNAME ## pixels16_l2_8(dst, full, half, stride, 24, 16, 16);             \
> > >  }                                                                             \
> > > @@ -469,7 +469,7 @@ static void OPNAME ## qpel16_mc02_c(uint8_t *dst, const uint8_t *src,         \
> > >  {                                                                             \
> > >      uint8_t full[24 * 17];                                                    \
> > >                                                                                \
> > > -    copy_block17(full, src, 24, stride, 17);                                  \
> > > +    copy_block16(full, src, 24, stride, 17);                                  \
> > >      OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);                  \
> > >  }                                                                             \
> > >                                                                                \
> > > @@ -479,7 +479,7 @@ static void OPNAME ## qpel16_mc03_c(uint8_t *dst, const uint8_t *src,         \
> > >      uint8_t full[24 * 17];                                                    \
> > >      uint8_t half[256];                                                        \
> > >                                                                                \
> > > -    copy_block17(full, src, 24, stride, 17);                                  \
> > > +    copy_block16(full, src, 24, stride, 17);                                  \
> > >      put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
> > >      OPNAME ## pixels16_l2_8(dst, full + 24, half, stride, 24, 16, 16);        \
> > >  }                                                                             \
> > 
> > Are the arch-specific dsp functions affected by this, too?
> 
> the fuzzer sample does not cause a anomaly in the x86 functions
> 
> 
> > Do you happen to know why copy_block9/17 has been used in this code?
> 
> probably because there was asm anyway so it was unused code or maybe it
> was oversight or some sort of code sharing/code cache use reduction but
> these hypothesis dont fit entirely. so i dont really know/rememeber

either way dont want to leave this open, so will apply. If more is needed
that will be fixed once we know of it

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/qpeldsp.c b/libavcodec/qpeldsp.c
index 2b9146ceb1..5f937f9d9e 100644
--- a/libavcodec/qpeldsp.c
+++ b/libavcodec/qpeldsp.c
@@ -199,7 +199,7 @@  static void OPNAME ## qpel8_mc01_c(uint8_t *dst, const uint8_t *src,          \
     uint8_t full[16 * 9];                                                     \
     uint8_t half[64];                                                         \
                                                                               \
-    copy_block9(full, src, 16, stride, 9);                                    \
+    copy_block8(full, src, 16, stride, 9);                                    \
     put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
     OPNAME ## pixels8_l2_8(dst, full, half, stride, 16, 8, 8);                \
 }                                                                             \
@@ -209,7 +209,7 @@  static void OPNAME ## qpel8_mc02_c(uint8_t *dst, const uint8_t *src,          \
 {                                                                             \
     uint8_t full[16 * 9];                                                     \
                                                                               \
-    copy_block9(full, src, 16, stride, 9);                                    \
+    copy_block8(full, src, 16, stride, 9);                                    \
     OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);                   \
 }                                                                             \
                                                                               \
@@ -219,7 +219,7 @@  static void OPNAME ## qpel8_mc03_c(uint8_t *dst, const uint8_t *src,          \
     uint8_t full[16 * 9];                                                     \
     uint8_t half[64];                                                         \
                                                                               \
-    copy_block9(full, src, 16, stride, 9);                                    \
+    copy_block8(full, src, 16, stride, 9);                                    \
     put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
     OPNAME ## pixels8_l2_8(dst, full + 16, half, stride, 16, 8, 8);           \
 }                                                                             \
@@ -459,7 +459,7 @@  static void OPNAME ## qpel16_mc01_c(uint8_t *dst, const uint8_t *src,         \
     uint8_t full[24 * 17];                                                    \
     uint8_t half[256];                                                        \
                                                                               \
-    copy_block17(full, src, 24, stride, 17);                                  \
+    copy_block16(full, src, 24, stride, 17);                                  \
     put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
     OPNAME ## pixels16_l2_8(dst, full, half, stride, 24, 16, 16);             \
 }                                                                             \
@@ -469,7 +469,7 @@  static void OPNAME ## qpel16_mc02_c(uint8_t *dst, const uint8_t *src,         \
 {                                                                             \
     uint8_t full[24 * 17];                                                    \
                                                                               \
-    copy_block17(full, src, 24, stride, 17);                                  \
+    copy_block16(full, src, 24, stride, 17);                                  \
     OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);                  \
 }                                                                             \
                                                                               \
@@ -479,7 +479,7 @@  static void OPNAME ## qpel16_mc03_c(uint8_t *dst, const uint8_t *src,         \
     uint8_t full[24 * 17];                                                    \
     uint8_t half[256];                                                        \
                                                                               \
-    copy_block17(full, src, 24, stride, 17);                                  \
+    copy_block16(full, src, 24, stride, 17);                                  \
     put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
     OPNAME ## pixels16_l2_8(dst, full + 24, half, stride, 24, 16, 16);        \
 }                                                                             \