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
18381838 int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
18391839 {
18401840 const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
1841− AVHWFramesContext *frames_ctx;
18421841
18431842 if (!hwaccel || !hwaccel->frame_priv_data_size)
18441843 return 0;
18451844
18461845 av_assert0(!*hwaccel_picture_private);
18471846
1848− frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
1849− *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0,
1850− frames_ctx->device_ctx,
1851− hwaccel->free_frame_priv);
1847+ if (hwaccel->free_frame_priv) {
1848+ AVHWFramesContext *frames_ctx;
1849+
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+
18521861 if (!*hwaccel_picture_private)
18531862 return AVERROR(ENOMEM);
18541863

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