diff mbox series

[FFmpeg-devel,1/3] avutil/hwcontext_vaapi: Abuse the AVBuffer API a bit less

Message ID AM7PR03MB6660B79231C17F82FCE346BD8FAE9@AM7PR03MB6660.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,1/3] avutil/hwcontext_vaapi: Abuse the AVBuffer API a bit less | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Oct. 4, 2021, 2:32 p.m. UTC
In this case there is no underlying data at all; the actual data
has been shoe-horned into the pointer, which does not point to any
storage owned by us. So use a size of zero as buffer pool size.

(This fixes segfaults if one uses vaapi with memory poisoning enabled;
but the memset call in pool_release_buffer() still receives an invalid
pointer, so it is still undefined behaviour.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/hwcontext_vaapi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 83e542876d..3578d49da3 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -490,7 +490,7 @@  static AVBufferRef *vaapi_pool_alloc(void *opaque, size_t size)
     av_log(hwfc, AV_LOG_DEBUG, "Created surface %#x.\n", surface_id);
 
     ref = av_buffer_create((uint8_t*)(uintptr_t)surface_id,
-                           sizeof(surface_id), &vaapi_buffer_free,
+                           0, &vaapi_buffer_free,
                            hwfc, AV_BUFFER_FLAG_READONLY);
     if (!ref) {
         vaDestroySurfaces(hwctx->display, &surface_id, 1);
@@ -593,7 +593,7 @@  static int vaapi_frames_init(AVHWFramesContext *hwfc)
         }
 
         hwfc->internal->pool_internal =
-            av_buffer_pool_init2(sizeof(VASurfaceID), hwfc,
+            av_buffer_pool_init2(0, hwfc,
                                  &vaapi_pool_alloc, NULL);
         if (!hwfc->internal->pool_internal) {
             av_log(hwfc, AV_LOG_ERROR, "Failed to create VAAPI surface pool.\n");