History

avcodec/decode: validate hw_frames_ctx when AVHWAccel.free_frame_priv is used

Validate that a hw_frames_ctx is available before using it for the AVHWAccel.free_frame_priv callback, and don't require it to be present when the callback is not in use by the HWAccel. v2: check for free_frame_priv (Hendrik) v3: return EINVAL (Christoph Reiter) v4: better commit message (Hendrik) v5: fix typo with missed frames_ctx (Lynne) See[1]: https://github.com/msys2/MINGW-packages/pull/19050 Fixes: be07145109 ("avcodec: add AVHWAccel.free_frame_priv callback") CC: Lynne <dev@lynne.ee> CC: Christoph Reiter <reiter.christoph@gmail.com> Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>

Dmitry Rogozhkin committed 2 years ago

Commit e9c93001 parent 641f8a71 file · +14 −5Browse files

Unified · Split

libavcodec/decode.c+14−5
@@ -1838,17 +1838,26 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) · 1837 unmodified lines
1838int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)1838int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
1839{1839{
1840 const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);1840 const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
1841 AVHWFramesContext *frames_ctx;
1842 1841
1843 if (!hwaccel || !hwaccel->frame_priv_data_size)1842 if (!hwaccel || !hwaccel->frame_priv_data_size)
1844 return 0;1843 return 0;
1845 1844
1846 av_assert0(!*hwaccel_picture_private);1845 av_assert0(!*hwaccel_picture_private);
1847 1846
1848 frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;1847 if (hwaccel->free_frame_priv) {
1849 *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0,1848 AVHWFramesContext *frames_ctx;
1850 frames_ctx->device_ctx,1849
1851 hwaccel->free_frame_priv);1850 if (!avctx->hw_frames_ctx)
1851 return AVERROR(EINVAL);
1852
1853 frames_ctx = (AVHWFramesContext *) avctx->hw_frames_ctx->data;
1854 *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0,
1855 frames_ctx->device_ctx,
1856 hwaccel->free_frame_priv);
1857 } else {
1858 *hwaccel_picture_private = ff_refstruct_allocz(hwaccel->frame_priv_data_size);
1859 }
1860
1852 if (!*hwaccel_picture_private)1861 if (!*hwaccel_picture_private)
1853 return AVERROR(ENOMEM);1862 return AVERROR(ENOMEM);
1854 1863

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