diff mbox

[FFmpeg-devel,05/12] avcodec/alsdec: Avoid dereferencing context pointer in inner interleave loop

Message ID 20190925203858.27870-5-michael@niedermayer.cc
State Accepted
Commit 581a895c5c8b464a7fc7ebbaa6d9f565c10bae62
Headers show

Commit Message

Michael Niedermayer Sept. 25, 2019, 8:38 p.m. UTC
This makes the decoder faster

Improves/Fixes: Timeout (22sec -> 20sec)
Testcase: 17619/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ALS_fuzzer-5078510820917248

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

Comments

Paul B Mahol Sept. 26, 2019, 7:55 a.m. UTC | #1
lgtm

On 9/25/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
> This makes the decoder faster
>
> Improves/Fixes: Timeout (22sec -> 20sec)
> Testcase:
> 17619/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ALS_fuzzer-5078510820917248
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/alsdec.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c
> index a53c170d18..56313d206c 100644
> --- a/libavcodec/alsdec.c
> +++ b/libavcodec/alsdec.c
> @@ -1815,15 +1815,17 @@ static int decode_frame(AVCodecContext *avctx, void
> *data, int *got_frame_ptr,
>      #define INTERLEAVE_OUTPUT(bps)
>          \
>      {
>          \
>          int##bps##_t *dest = (int##bps##_t*)frame->data[0];
>          \
> +        int channels = avctx->channels;
>          \
> +        int32_t **raw_samples = ctx->raw_samples;
>          \
>          shift = bps - ctx->avctx->bits_per_raw_sample;
>          \
>          if (!ctx->cs_switch) {
>          \
>              for (sample = 0; sample < ctx->cur_frame_length; sample++)
>          \
> -                for (c = 0; c < avctx->channels; c++)
>          \
> -                    *dest++ = ctx->raw_samples[c][sample] * (1U << shift);
>           \
> +                for (c = 0; c < channels; c++)
>          \
> +                    *dest++ = raw_samples[c][sample] * (1U << shift);
>          \
>          } else {
>          \
>              for (sample = 0; sample < ctx->cur_frame_length; sample++)
>          \
> -                for (c = 0; c < avctx->channels; c++)
>          \
> -                    *dest++ = ctx->raw_samples[sconf->chan_pos[c]][sample]
> * (1U << shift); \
> +                for (c = 0; c < channels; c++)
>          \
> +                    *dest++ = raw_samples[sconf->chan_pos[c]][sample] * (1U
> << shift);\
>          }
>          \
>      }
>
> --
> 2.23.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer Sept. 26, 2019, 6:34 p.m. UTC | #2
On Thu, Sep 26, 2019 at 09:55:59AM +0200, Paul B Mahol wrote:
> lgtm

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c
index a53c170d18..56313d206c 100644
--- a/libavcodec/alsdec.c
+++ b/libavcodec/alsdec.c
@@ -1815,15 +1815,17 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
     #define INTERLEAVE_OUTPUT(bps)                                                   \
     {                                                                                \
         int##bps##_t *dest = (int##bps##_t*)frame->data[0];                          \
+        int channels = avctx->channels;                                              \
+        int32_t **raw_samples = ctx->raw_samples;                                    \
         shift = bps - ctx->avctx->bits_per_raw_sample;                               \
         if (!ctx->cs_switch) {                                                       \
             for (sample = 0; sample < ctx->cur_frame_length; sample++)               \
-                for (c = 0; c < avctx->channels; c++)                                \
-                    *dest++ = ctx->raw_samples[c][sample] * (1U << shift);            \
+                for (c = 0; c < channels; c++)                                       \
+                    *dest++ = raw_samples[c][sample] * (1U << shift);                \
         } else {                                                                     \
             for (sample = 0; sample < ctx->cur_frame_length; sample++)               \
-                for (c = 0; c < avctx->channels; c++)                                \
-                    *dest++ = ctx->raw_samples[sconf->chan_pos[c]][sample] * (1U << shift); \
+                for (c = 0; c < channels; c++)                                       \
+                    *dest++ = raw_samples[sconf->chan_pos[c]][sample] * (1U << shift);\
         }                                                                            \
     }