History

avfilter/vf_zscale: fix crash on unaligned input

Jacob Ruiz committed 6 years ago

Commit ba2581a1 parent 7e08a921 file · +49 −10Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_zscale.c+49−10
@@ -44,6 +44,8 @@ · 43 unmodified lines
4444 #include "libavutil/imgutils.h"
4545 #include "libavutil/avassert.h"
4646
47+#define ZIMG_ALIGNMENT 32
48+
4749 static const char *const var_names[] = {
4850 "in_w", "iw",
4951 "in_h", "ih",
@@ -502,6 +504,44 @@ static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params *par · 452 unmodified lines
502504 return 0;
503505 }
504506
507+static int realign_frame(const AVPixFmtDescriptor *desc, AVFrame **frame)
508+{
509+ AVFrame *aligned = NULL;
510+ int ret = 0, plane;
511+
512+ /* Realign any unaligned input frame. */
513+ for (plane = 0; plane < 3; plane++) {
514+ int p = desc->comp[plane].plane;
515+ if ((uintptr_t)(*frame)->data[p] % ZIMG_ALIGNMENT || (*frame)->linesize[p] % ZIMG_ALIGNMENT) {
516+ if (!(aligned = av_frame_alloc())) {
517+ ret = AVERROR(ENOMEM);
518+ goto fail;
519+ }
520+
521+ aligned->format = (*frame)->format;
522+ aligned->width = (*frame)->width;
523+ aligned->height = (*frame)->height;
524+
525+ if ((ret = av_frame_get_buffer(aligned, ZIMG_ALIGNMENT)) < 0)
526+ goto fail;
527+
528+ if ((ret = av_frame_copy(aligned, *frame)) < 0)
529+ goto fail;
530+
531+ if ((ret = av_frame_copy_props(aligned, *frame)) < 0)
532+ goto fail;
533+
534+ av_frame_free(frame);
535+ *frame = aligned;
536+ return 0;
537+ }
538+ }
539+
540+fail:
541+ av_frame_free(&aligned);
542+ return ret;
543+}
544+
505545 static int filter_frame(AVFilterLink *link, AVFrame *in)
506546 {
507547 ZScaleContext *s = link->dst->priv;
@@ -512,12 +552,14 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 4 unmodified lines
512552 zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
513553 char buf[32];
514554 int ret = 0, plane;
515− AVFrame *out;
555+ AVFrame *out = NULL;
516556
517− out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
518− if (!out) {
519− av_frame_free(&in);
520− return AVERROR(ENOMEM);
557+ if ((ret = realign_frame(desc, &in)) < 0)
558+ goto fail;
559+
560+ if (!(out = ff_get_video_buffer(outlink, outlink->w, outlink->h))) {
561+ ret = AVERROR(ENOMEM);
562+ goto fail;
521563 }
522564
523565 av_frame_copy_props(out, in);
@@ -546,11 +588,8 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 22 unmodified lines
546588 link->dst->inputs[0]->w = in->width;
547589 link->dst->inputs[0]->h = in->height;
548590
549− if ((ret = config_props(outlink)) < 0) {
550− av_frame_free(&in);
551− av_frame_free(&out);
552− return ret;
553− }
591+ if ((ret = config_props(outlink)) < 0)
592+ goto fail;
554593
555594 zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
556595 zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t