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
44#include "libavutil/imgutils.h"44#include "libavutil/imgutils.h"
45#include "libavutil/avassert.h"45#include "libavutil/avassert.h"
46 46
47#define ZIMG_ALIGNMENT 32
48
47static const char *const var_names[] = {49static const char *const var_names[] = {
48 "in_w", "iw",50 "in_w", "iw",
49 "in_h", "ih",51 "in_h", "ih",
@@ -502,6 +504,44 @@ static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params *par · 452 unmodified lines
502 return 0;504 return 0;
503}505}
504 506
507static 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
540fail:
541 av_frame_free(&aligned);
542 return ret;
543}
544
505static int filter_frame(AVFilterLink *link, AVFrame *in)545static int filter_frame(AVFilterLink *link, AVFrame *in)
506{546{
507 ZScaleContext *s = link->dst->priv;547 ZScaleContext *s = link->dst->priv;
@@ -512,12 +552,14 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 4 unmodified lines
512 zimg_image_buffer dst_buf = { ZIMG_API_VERSION };552 zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
513 char buf[32];553 char buf[32];
514 int ret = 0, plane;554 int ret = 0, plane;
515 AVFrame *out;555 AVFrame *out = NULL;
516 556
517 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);557 if ((ret = realign_frame(desc, &in)) < 0)
518 if (!out) {558 goto fail;
519 av_frame_free(&in);559
520 return AVERROR(ENOMEM);560 if (!(out = ff_get_video_buffer(outlink, outlink->w, outlink->h))) {
561 ret = AVERROR(ENOMEM);
562 goto fail;
521 }563 }
522 564
523 av_frame_copy_props(out, in);565 av_frame_copy_props(out, in);
@@ -546,11 +588,8 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 22 unmodified lines
546 link->dst->inputs[0]->w = in->width;588 link->dst->inputs[0]->w = in->width;
547 link->dst->inputs[0]->h = in->height;589 link->dst->inputs[0]->h = in->height;
548 590
549 if ((ret = config_props(outlink)) < 0) {591 if ((ret = config_props(outlink)) < 0)
550 av_frame_free(&in);592 goto fail;
551 av_frame_free(&out);
552 return ret;
553 }
554 593
555 zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);594 zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
556 zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);595 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