diff mbox series

[FFmpeg-devel] avfilter/vf_zscale: fix crash on unaligned input

Message ID f9S2OZoK88jv3bWV5D1ob5dzDSG3DwrVtMqsD_AI2fdE6wZRA-LKVchyhMiZNAbsKi5uhCHSci2AOWmawkg2YlH1d7hxk0Sx6BOwBPXRnPo=@protonmail.com
State Accepted
Headers show
Series [FFmpeg-devel] avfilter/vf_zscale: fix crash on unaligned input | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

jjadfh5dfg Feb. 15, 2020, 6:17 a.m. UTC
Sent with [ProtonMail](https://protonmail.com) Secure Email.

Comments

Paul B Mahol Feb. 15, 2020, 3:08 p.m. UTC | #1
On 2/15/20, jjadfh5dfg <jjadfh5dfg@protonmail.com> wrote:
> Sent with [ProtonMail](https://protonmail.com) Secure Email.

How to apply this? Author name is not valid.
Please specify meaningful name, like: Donnie Darko Rabbit
jjadfh5dfg Feb. 15, 2020, 7:02 p.m. UTC | #2
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Saturday, February 15, 2020 7:08 AM, Paul B Mahol <onemda@gmail.com> wrote:

> On 2/15/20, jjadfh5dfg jjadfh5dfg@protonmail.com wrote:
>
> > Sent with ProtonMail Secure Email.
>
> How to apply this? Author name is not valid.
> Please specify meaningful name, like: Donnie Darko Rabbit
>
> 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".

To apply the patch, please use this command:

$ git am 0001-avfilter-vf_zscale-fix-crash-on-unaligned-input.patch

You may change the author if it displeases you.

Sent with ProtonMail Secure Email.
Paul B Mahol Feb. 15, 2020, 7:11 p.m. UTC | #3
On 2/15/20, jjadfh5dfg <jjadfh5dfg@protonmail.com> wrote:
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Saturday, February 15, 2020 7:08 AM, Paul B Mahol <onemda@gmail.com>
> wrote:
>
>> On 2/15/20, jjadfh5dfg jjadfh5dfg@protonmail.com wrote:
>>
>> > Sent with ProtonMail Secure Email.
>>
>> How to apply this? Author name is not valid.
>> Please specify meaningful name, like: Donnie Darko Rabbit
>>
>> 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".
>
> To apply the patch, please use this command:
>
> $ git am 0001-avfilter-vf_zscale-fix-crash-on-unaligned-input.patch
>
> You may change the author if it displeases you.

Personally I do not care, but others do.
So If you plan to send more patches to zscale and  not just this one
please consider changing it to something more pleasing.

>
> Sent with ProtonMail Secure Email.
> _______________________________________________
> 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".
jjadfh5dfg Feb. 17, 2020, 7:01 a.m. UTC | #4
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Saturday, February 15, 2020 11:11 AM, Paul B Mahol <onemda@gmail.com> wrote:

> On 2/15/20, jjadfh5dfg jjadfh5dfg@protonmail.com wrote:
>
> > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> > On Saturday, February 15, 2020 7:08 AM, Paul B Mahol onemda@gmail.com
> > wrote:
> >
> > > On 2/15/20, jjadfh5dfg jjadfh5dfg@protonmail.com wrote:
> > >
> > > > Sent with ProtonMail Secure Email.
> > >
> > > How to apply this? Author name is not valid.
> > > Please specify meaningful name, like: Donnie Darko Rabbit
> > > 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".
> >
> > To apply the patch, please use this command:
> > $ git am 0001-avfilter-vf_zscale-fix-crash-on-unaligned-input.patch
> > You may change the author if it displeases you.
>
> Personally I do not care, but others do.
> So If you plan to send more patches to zscale and not just this one
> please consider changing it to something more pleasing.
>
> > Sent with ProtonMail Secure Email.
> >
> > 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".
>
> 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".

Please find attached a revised patch with different author field.

Sent with ProtonMail Secure Email.
Paul B Mahol Feb. 25, 2020, 6:58 p.m. UTC | #5
Applied

On 2/17/20, jjadfh5dfg <jjadfh5dfg@protonmail.com> wrote:
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Saturday, February 15, 2020 11:11 AM, Paul B Mahol <onemda@gmail.com>
> wrote:
>
>> On 2/15/20, jjadfh5dfg jjadfh5dfg@protonmail.com wrote:
>>
>> > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
>> > On Saturday, February 15, 2020 7:08 AM, Paul B Mahol onemda@gmail.com
>> > wrote:
>> >
>> > > On 2/15/20, jjadfh5dfg jjadfh5dfg@protonmail.com wrote:
>> > >
>> > > > Sent with ProtonMail Secure Email.
>> > >
>> > > How to apply this? Author name is not valid.
>> > > Please specify meaningful name, like: Donnie Darko Rabbit
>> > > 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".
>> >
>> > To apply the patch, please use this command:
>> > $ git am 0001-avfilter-vf_zscale-fix-crash-on-unaligned-input.patch
>> > You may change the author if it displeases you.
>>
>> Personally I do not care, but others do.
>> So If you plan to send more patches to zscale and not just this one
>> please consider changing it to something more pleasing.
>>
>> > Sent with ProtonMail Secure Email.
>> >
>> > 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".
>>
>> 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".
>
> Please find attached a revised patch with different author field.
>
> Sent with ProtonMail Secure Email.
>
diff mbox series

Patch

From 098bcfc165d111b0e00cdaa015044a5b07a66da1 Mon Sep 17 00:00:00 2001
From: "he.who.shall.not.be.named" <notreply@example.com>
Date: Thu, 13 Feb 2020 22:50:38 -0800
Subject: [PATCH 1/3] avfilter/vf_zscale: fix crash on unaligned input

---
 libavfilter/vf_zscale.c | 59 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 49 insertions(+), 10 deletions(-)

diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c
index 46c5dd7f38..023a5d10e9 100644
--- a/libavfilter/vf_zscale.c
+++ b/libavfilter/vf_zscale.c
@@ -44,6 +44,8 @@ 
 #include "libavutil/imgutils.h"
 #include "libavutil/avassert.h"
 
+#define ZIMG_ALIGNMENT 32
+
 static const char *const var_names[] = {
     "in_w",   "iw",
     "in_h",   "ih",
@@ -502,6 +504,44 @@  static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params *par
     return 0;
 }
 
+static int realign_frame(const AVPixFmtDescriptor *desc, AVFrame **frame)
+{
+    AVFrame *aligned = NULL;
+    int ret = 0, plane;
+
+    /* Realign any unaligned input frame. */
+    for (plane = 0; plane < 3; plane++) {
+        int p = desc->comp[plane].plane;
+        if ((uintptr_t)(*frame)->data[p] % ZIMG_ALIGNMENT || (*frame)->linesize[p] % ZIMG_ALIGNMENT) {
+            if (!(aligned = av_frame_alloc())) {
+                ret = AVERROR(ENOMEM);
+                goto fail;
+            }
+
+            aligned->format = (*frame)->format;
+            aligned->width  = (*frame)->width;
+            aligned->height = (*frame)->height;
+
+            if ((ret = av_frame_get_buffer(aligned, ZIMG_ALIGNMENT)) < 0)
+                goto fail;
+
+            if ((ret = av_frame_copy(aligned, *frame)) < 0)
+                goto fail;
+
+            if ((ret = av_frame_copy_props(aligned, *frame)) < 0)
+                goto fail;
+
+            av_frame_free(frame);
+            *frame = aligned;
+            return 0;
+        }
+    }
+
+fail:
+    av_frame_free(&aligned);
+    return ret;
+}
+
 static int filter_frame(AVFilterLink *link, AVFrame *in)
 {
     ZScaleContext *s = link->dst->priv;
@@ -512,12 +552,14 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
     zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
     char buf[32];
     int ret = 0, plane;
-    AVFrame *out;
+    AVFrame *out = NULL;
 
-    out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
-    if (!out) {
-        av_frame_free(&in);
-        return AVERROR(ENOMEM);
+    if ((ret = realign_frame(desc, &in)) < 0)
+        goto fail;
+
+    if (!(out = ff_get_video_buffer(outlink, outlink->w, outlink->h))) {
+        ret =  AVERROR(ENOMEM);
+        goto fail;
     }
 
     av_frame_copy_props(out, in);
@@ -546,11 +588,8 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
         link->dst->inputs[0]->w      = in->width;
         link->dst->inputs[0]->h      = in->height;
 
-        if ((ret = config_props(outlink)) < 0) {
-            av_frame_free(&in);
-            av_frame_free(&out);
-            return ret;
-        }
+        if ((ret = config_props(outlink)) < 0)
+            goto fail;
 
         zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
         zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);
-- 
2.17.1