Before this, the filter blindly casts to AVVulkanDeviceContext and passes invalid values to libplacebo if it's not.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -252,6 +252,7 @@ static int init_vulkan(AVFilterContext *avctx) · 251 unmodified lines | ||
| 252 | 252 | { |
| 253 | 253 | int err = 0; |
| 254 | 254 | LibplaceboContext *s = avctx->priv; |
| 255 | + const AVHWDeviceContext *avhwctx; | |
| 255 | 256 | const AVVulkanDeviceContext *hwctx; |
| 256 | 257 | uint8_t *buf = NULL; |
| 257 | 258 | size_t buf_len; |
| @@ -261,7 +262,15 @@ static int init_vulkan(AVFilterContext *avctx) · 3 unmodified lines | ||
| 261 | 262 | return AVERROR(EINVAL); |
| 262 | 263 | } |
| 263 | 264 | |
| 264 | − hwctx = ((AVHWDeviceContext*) avctx->hw_device_ctx->data)->hwctx; | |
| 265 | + avhwctx = avctx->hw_device_ctx->data; | |
| 266 | + | |
| 267 | + if (avhwctx->type != AV_HWDEVICE_TYPE_VULKAN) { | |
| 268 | + av_log(s, AV_LOG_ERROR, "Expected vulkan hwdevice for vf_libplacebo, got %s.\n", | |
| 269 | + av_hwdevice_get_type_name(avhwctx->type)); | |
| 270 | + return AVERROR(EINVAL); | |
| 271 | + } | |
| 272 | + | |
| 273 | + hwctx = avhwctx->hwctx; | |
| 265 | 274 | |
| 266 | 275 | /* Import libavfilter vulkan context into libplacebo */ |
| 267 | 276 | s->vulkan = pl_vulkan_import(s->log, pl_vulkan_import_params( |