swscale/format: check pixel type in ff_sws_encode/decode_colors()

This would otherwise generate illegal ops and undefined behavior, for
pixel formats without any supported corresponding pixel type.

This didn't cause any issues previously because the following
`ff_sws_encode_pixfmt` would normally fail for such formats, and the UB
was ignored in practice.

Signed-off-by: Niklas Haas <git@haasn.dev>
This commit is contained in:
Niklas Haas
2026-02-26 18:08:49 +00:00
committed by Niklas Haas
parent 096e20b4b8
commit d4202809da
+8 -2
View File
@@ -1319,10 +1319,13 @@ int ff_sws_decode_colors(SwsContext *ctx, SwsPixelType type,
SwsOpList *ops, const SwsFormat *fmt, bool *incomplete)
{
const AVLumaCoefficients *c = av_csp_luma_coeffs_from_avcsp(fmt->csp);
const SwsPixelType pixel_type = fmt_pixel_type(fmt->format);
if (!pixel_type)
return AVERROR(ENOTSUP);
RET(ff_sws_op_list_append(ops, &(SwsOp) {
.op = SWS_OP_CONVERT,
.type = fmt_pixel_type(fmt->format),
.type = pixel_type,
.convert.to = type,
}));
@@ -1402,6 +1405,9 @@ int ff_sws_encode_colors(SwsContext *ctx, SwsPixelType type,
const SwsFormat *dst, bool *incomplete)
{
const AVLumaCoefficients *c = av_csp_luma_coeffs_from_avcsp(dst->csp);
const SwsPixelType pixel_type = fmt_pixel_type(dst->format);
if (!pixel_type)
return AVERROR(ENOTSUP);
switch (dst->csp) {
case AVCOL_SPC_RGB:
@@ -1496,7 +1502,7 @@ int ff_sws_encode_colors(SwsContext *ctx, SwsPixelType type,
return ff_sws_op_list_append(ops, &(SwsOp) {
.type = type,
.op = SWS_OP_CONVERT,
.convert.to = fmt_pixel_type(dst->format),
.convert.to = pixel_type,
});
}