Opened 10 years ago

Closed 10 years ago

#3495 closed defect (fixed)

Call to sws_getCachedContext() with SWS_BICUBLIN will always raise an assert exception

Reported by: cyril Owned by:
Priority: important Component: swscale
Version: git-master Keywords: crash abort regression
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

Summary of the bug: A call to sws_getCachedContext() with SWS_BICUBLIN as the flag will always raise the assert exception at line 377 of libswscale/util.c av_assert0(sizeFactor > 0).

How to reproduce:
In a dummy program, make this call:

SwsContext *pSwsContext = NULL;
sws_getCachedContext(pSwsContext,
            720, 406,AV_PIX_FMT_YUV420P,
            256, 144, AV_PIX_FMT_BGRA,
            SWS_BICUBLIN, NULL, NULL, NULL
        );

It will always raise the above assert exception.

This is a regression introduced by this commit:

2013-11-05 	Stefano Sabatini	lsws/utils: introduce scale_algorithms array

Indeed, sws_init_context() is called, which in turn calls initFilter() twice, first for the luma component then for the chroma component. The assert is raised for the chroma component.
A possible fix is to reshuffle the static const ScaleAlgorithm scale_algorithms[] rows so that SWS_BICUBLIN is set after SWS_BILINEAR and not before.

Change History (4)

comment:1 by Carl Eugen Hoyos, 10 years ago

If you have a patch fixing this problem, please send it to the ffmpeg-devel mailing list.
If you cannot send a patch please attach a sample C program here that allows to reproduce the issue (or post a ffmpeg command line together with complete, uncut console output if it allows to reproduce the problem).

comment:2 by cyril, 10 years ago

I already explained how to reproduce the bug programmatically:

#include <libswscale/swscale.h>
void main() {
    SwsContext *pSwsContext = NULL;
    sws_getCachedContext(pSwsContext,
            720, 406,AV_PIX_FMT_YUV420P,
            256, 144, AV_PIX_FMT_BGRA,
            SWS_BICUBLIN, NULL, NULL, NULL
        );
}

I don't know how to send a patch, but in libswscale/utils.c, replace the below lines:

281 static const ScaleAlgorithm scale_algorithms[] = {
282     { SWS_AREA,          "area averaging",                  1 /* downscale only, for upscale it is bilinear */ },
283     { SWS_BICUBIC,       "bicubic",                         4 },
284     { SWS_BICUBLIN,      "luma bicubic / chroma bilinear", -1 },
285     { SWS_BILINEAR,      "bilinear",                        2 },
286     { SWS_FAST_BILINEAR, "fast bilinear",                  -1 },
287     { SWS_GAUSS,         "Gaussian",                        8 /* infinite ;) */ },
288     { SWS_LANCZOS,       "Lanczos",                        -1 /* custom */ },
289     { SWS_POINT,         "nearest neighbor / point",       -1 },
290     { SWS_SINC,          "sinc",                           20 /* infinite ;) */ },
291     { SWS_SPLINE,        "bicubic spline",                 20 /* infinite :)*/ },
292     { SWS_X,             "experimental",                    8 },
293 };

by

281 static const ScaleAlgorithm scale_algorithms[] = {
282     { SWS_AREA,          "area averaging",                  1 /* downscale only, for upscale it is bilinear */ },
283     { SWS_BICUBIC,       "bicubic",                         4 },
284     { SWS_BILINEAR,      "bilinear",                        2 },
285     { SWS_BICUBLIN,      "luma bicubic / chroma bilinear", -1 },
286     { SWS_FAST_BILINEAR, "fast bilinear",                  -1 },
287     { SWS_GAUSS,         "Gaussian",                        8 /* infinite ;) */ },
288     { SWS_LANCZOS,       "Lanczos",                        -1 /* custom */ },
289     { SWS_POINT,         "nearest neighbor / point",       -1 },
290     { SWS_SINC,          "sinc",                           20 /* infinite ;) */ },
291     { SWS_SPLINE,        "bicubic spline",                 20 /* infinite :)*/ },
292     { SWS_X,             "experimental",                    8 },
293 };

comment:3 by Carl Eugen Hoyos, 10 years ago

Keywords: crash abort regression added

comment:4 by Carl Eugen Hoyos, 10 years ago

Reproduced by developer: set
Resolution: fixed
Status: newclosed

Should be fixed in e6fe804b - thank you for the report!

Note: See TracTickets for help on using tickets.