[FFmpeg-cvslog] OpenCL: Avoid potential buffer overflow in cmdutils_opencl.c
ffmpeg | branch: master | Maneesh Gupta | Tue Apr 28 13:26:31 2015 +0530| [cf234552b83a9503ff96572de2658b921b8842eb] | committer: Michael Niedermayer OpenCL: Avoid potential buffer overflow in cmdutils_opencl.c The opt_opencl_bench function copied the device name using strcpy without checking if the source string was larger. This patch fixes this by replacing the strcpy with av_strlcpy, with the string copy size capped to the destination buffer size. Signed-off-by: Maneesh Gupta Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cf234552b83a9503ff96572de2658b921b8842eb --- cmdutils_opencl.c |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmdutils_opencl.c b/cmdutils_opencl.c index 3dfd156..61478e2 100644 --- a/cmdutils_opencl.c +++ b/cmdutils_opencl.c @@ -22,6 +22,7 @@ #include "libavutil/time.h" #include "libavutil/log.h" #include "libavutil/opencl.h" +#include "libavutil/avstring.h" #include "cmdutils.h" typedef struct { @@ -238,7 +239,8 @@ int opt_opencl_bench(void *optctx, const char *opt, const char *arg) devices[count].platform_idx = i; devices[count].device_idx = j; devices[count].runtime = score; -strcpy(devices[count].device_name, device_node->device_name); +av_strlcpy(devices[count].device_name, device_node->device_name, + sizeof(devices[count].device_name)); count++; } } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] OpenCL: Fix ABI incompatibility issues
ffmpeg | branch: master | Maneesh Gupta | Tue Apr 28 13:20:38 2015 +0530| [91305c60261c77ad4a071062a21136fc0b6c5ab2] | committer: Michael Niedermayer OpenCL: Fix ABI incompatibility issues AVOpenCLDeviceNode and AVOpenCLPlatformNode used fixed static buffer for holding the device and platform name. This patch modifies these structures to use pointers instead. The memory required to hold the names is now dynamically allocated, the size for which is determined by querying appropriate OpenCL runtime APIs. Signed-off-by: Maneesh Gupta Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=91305c60261c77ad4a071062a21136fc0b6c5ab2 --- libavutil/opencl.c | 42 ++ libavutil/opencl.h | 10 ++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/libavutil/opencl.c b/libavutil/opencl.c index 2df5653..1d78214 100644 --- a/libavutil/opencl.c +++ b/libavutil/opencl.c @@ -181,9 +181,11 @@ static void free_device_list(AVOpenCLDeviceList *device_list) if (!device_list->platform_node[i]) continue; for (j = 0; j < device_list->platform_node[i]->device_num; j++) { + av_freep(&(device_list->platform_node[i]->device_node[j]->device_name)); av_freep(&(device_list->platform_node[i]->device_node[j])); } av_freep(&device_list->platform_node[i]->device_node); +av_freep(&(device_list->platform_node[i]->platform_name)); av_freep(&device_list->platform_node[i]); } av_freep(&device_list->platform_node); @@ -198,6 +200,8 @@ static int get_device_list(AVOpenCLDeviceList *device_list) cl_platform_id *platform_ids = NULL; cl_device_id *device_ids = NULL; AVOpenCLDeviceNode *device_node = NULL; +size_t platform_name_size = 0; +size_t device_name_size = 0; status = clGetPlatformIDs(0, NULL, &device_list->platform_num); if (status != CL_SUCCESS) { av_log(&opencl_ctx, AV_LOG_ERROR, @@ -232,8 +236,25 @@ static int get_device_list(AVOpenCLDeviceList *device_list) } device_list->platform_node[i]->platform_id = platform_ids[i]; status = clGetPlatformInfo(platform_ids[i], CL_PLATFORM_VENDOR, - sizeof(device_list->platform_node[i]->platform_name), - device_list->platform_node[i]->platform_name, NULL); + 0, NULL, &platform_name_size); +if (status != CL_SUCCESS) { +av_log(&opencl_ctx, AV_LOG_WARNING, +"Could not get size of platform name: %s\n", av_opencl_errstr(status)); +} else { +device_list->platform_node[i]->platform_name = av_malloc(platform_name_size * sizeof(char)); +if (!device_list->platform_node[i]->platform_name) { +av_log(&opencl_ctx, AV_LOG_WARNING, +"Could not allocate memory for device name: %s\n", av_opencl_errstr(status)); +} else { +status = clGetPlatformInfo(platform_ids[i], CL_PLATFORM_VENDOR, + platform_name_size * sizeof(char), + device_list->platform_node[i]->platform_name, NULL); +if (status != CL_SUCCESS) { +av_log(&opencl_ctx, AV_LOG_WARNING, +"Could not get platform name: %s\n", av_opencl_errstr(status)); +} +} +} total_devices_num = 0; for (j = 0; j < FF_ARRAY_ELEMS(device_type); j++) { status = clGetDeviceIDs(device_list->platform_node[i]->platform_id, @@ -271,8 +292,21 @@ static int get_device_list(AVOpenCLDeviceList *device_list) device_node->device_id = device_ids[k]; device_node->device_type = device_type[j]; status = clGetDeviceInfo(device_node->device_id, CL_DEVICE_NAME, - sizeof(device_node->device_name), device_node->device_name, - NULL); + 0, NULL, &device_name_size); +if (status != CL_SUCCESS) { +av_log(&opencl_ctx, AV_LOG_WARNING, +"Could not get size of device name: %s\n", av_opencl_errstr(status)); +continue; +} +device_node->device_name = av_malloc(device_name_size * sizeof(char)); +if (!device_node->device_name) { +av_log(&opencl_ctx, AV_LOG_WARNING, +
[FFmpeg-cvslog] OpenCL: Avoid potential buffer overflow in cmdutils_opencl.c
ffmpeg | branch: release/2.6 | Maneesh Gupta | Tue Apr 28 13:26:31 2015 +0530| [86a360e34985e881dec58ee2b4af0600e43bfc79] | committer: Michael Niedermayer OpenCL: Avoid potential buffer overflow in cmdutils_opencl.c The opt_opencl_bench function copied the device name using strcpy without checking if the source string was larger. This patch fixes this by replacing the strcpy with av_strlcpy, with the string copy size capped to the destination buffer size. Signed-off-by: Maneesh Gupta Signed-off-by: Michael Niedermayer (cherry picked from commit cf234552b83a9503ff96572de2658b921b8842eb) Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=86a360e34985e881dec58ee2b4af0600e43bfc79 --- cmdutils_opencl.c |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmdutils_opencl.c b/cmdutils_opencl.c index 3dfd156..61478e2 100644 --- a/cmdutils_opencl.c +++ b/cmdutils_opencl.c @@ -22,6 +22,7 @@ #include "libavutil/time.h" #include "libavutil/log.h" #include "libavutil/opencl.h" +#include "libavutil/avstring.h" #include "cmdutils.h" typedef struct { @@ -238,7 +239,8 @@ int opt_opencl_bench(void *optctx, const char *opt, const char *arg) devices[count].platform_idx = i; devices[count].device_idx = j; devices[count].runtime = score; -strcpy(devices[count].device_name, device_node->device_name); +av_strlcpy(devices[count].device_name, device_node->device_name, + sizeof(devices[count].device_name)); count++; } } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] OpenCL: Avoid potential buffer overflow in cmdutils_opencl.c
ffmpeg | branch: release/2.5 | Maneesh Gupta | Tue Apr 28 13:26:31 2015 +0530| [1e6352578ae4319b2427f9f2ffb8042e8d11894f] | committer: Michael Niedermayer OpenCL: Avoid potential buffer overflow in cmdutils_opencl.c The opt_opencl_bench function copied the device name using strcpy without checking if the source string was larger. This patch fixes this by replacing the strcpy with av_strlcpy, with the string copy size capped to the destination buffer size. Signed-off-by: Maneesh Gupta Signed-off-by: Michael Niedermayer (cherry picked from commit cf234552b83a9503ff96572de2658b921b8842eb) Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1e6352578ae4319b2427f9f2ffb8042e8d11894f --- cmdutils_opencl.c |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmdutils_opencl.c b/cmdutils_opencl.c index 3dfd156..61478e2 100644 --- a/cmdutils_opencl.c +++ b/cmdutils_opencl.c @@ -22,6 +22,7 @@ #include "libavutil/time.h" #include "libavutil/log.h" #include "libavutil/opencl.h" +#include "libavutil/avstring.h" #include "cmdutils.h" typedef struct { @@ -238,7 +239,8 @@ int opt_opencl_bench(void *optctx, const char *opt, const char *arg) devices[count].platform_idx = i; devices[count].device_idx = j; devices[count].runtime = score; -strcpy(devices[count].device_name, device_node->device_name); +av_strlcpy(devices[count].device_name, device_node->device_name, + sizeof(devices[count].device_name)); count++; } } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] OpenCL: Avoid potential buffer overflow in cmdutils_opencl.c
ffmpeg | branch: release/2.4 | Maneesh Gupta | Tue Apr 28 13:26:31 2015 +0530| [5260ba3e16a23a2b8a0ff161cfb9a57cdf91992f] | committer: Michael Niedermayer OpenCL: Avoid potential buffer overflow in cmdutils_opencl.c The opt_opencl_bench function copied the device name using strcpy without checking if the source string was larger. This patch fixes this by replacing the strcpy with av_strlcpy, with the string copy size capped to the destination buffer size. Signed-off-by: Maneesh Gupta Signed-off-by: Michael Niedermayer (cherry picked from commit cf234552b83a9503ff96572de2658b921b8842eb) Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5260ba3e16a23a2b8a0ff161cfb9a57cdf91992f --- cmdutils_opencl.c |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmdutils_opencl.c b/cmdutils_opencl.c index 3dfd156..61478e2 100644 --- a/cmdutils_opencl.c +++ b/cmdutils_opencl.c @@ -22,6 +22,7 @@ #include "libavutil/time.h" #include "libavutil/log.h" #include "libavutil/opencl.h" +#include "libavutil/avstring.h" #include "cmdutils.h" typedef struct { @@ -238,7 +239,8 @@ int opt_opencl_bench(void *optctx, const char *opt, const char *arg) devices[count].platform_idx = i; devices[count].device_idx = j; devices[count].runtime = score; -strcpy(devices[count].device_name, device_node->device_name); +av_strlcpy(devices[count].device_name, device_node->device_name, + sizeof(devices[count].device_name)); count++; } } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] doc/fftools-common-opts: update/ extend documentation for -opencl_bench option
ffmpeg | branch: master | Maneesh Gupta | Tue Jan 27 20:46:24 2015 +0530| [1600f85cbc4594c589cfea42121e3ddad0b974e9] | committer: Stefano Sabatini doc/fftools-common-opts: update/extend documentation for -opencl_bench option Signed-off-by: Stefano Sabatini > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1600f85cbc4594c589cfea42121e3ddad0b974e9 --- doc/fftools-common-opts.texi | 37 +++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index 7d52c1a..6556909 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -294,8 +294,41 @@ Possible flags for this option are: @end table @item -opencl_bench -Benchmark all available OpenCL devices and show the results. This option -is only available when FFmpeg has been compiled with @code{--enable-opencl}. +This option is used to benchmark all available OpenCL devices and print the +results. This option is only available when FFmpeg has been compiled with +@code{--enable-opencl}. + +When FFmpeg is configured with @code{--enable-opencl}, the options for the +global OpenCL context are set via @option{-opencl_options}. See the +"OpenCL Options" section in the ffmpeg-utils manual for the complete list of +supported options. Amongst others, these options include the ability to select +a specific platform and device to run the OpenCL code on. By default, FFmpeg +will run on the first device of the first platform. While the options for the +global OpenCL context provide flexibility to the user in selecting the OpenCL +device of their choice, most users would probably want to select the fastest +OpenCL device for their system. + +This option assists the selection of the most efficient configuration by +identifying the appropriate device for the user's system. The built-in +benchmark is run on all the OpenCL devices and the performance is measured for +each device. The devices in the results list are sorted based on their +performance with the fastest device listed first. The user can subsequently +invoke @command{ffmpeg} using the device deemed most appropriate via +@option{-opencl_options} to obtain the best performance for the OpenCL +accelerated code. + +Typical usage to use the fastest OpenCL device involve the following steps. + +Run the command: +@example +ffmpeg -opencl_bench +@end example +Note down the platform ID (@var{pidx}) and device ID (@var{didx}) of the first +i.e. fastest device in the list. +Select the platform and device using the command: +@example +ffmpeg -opencl_options platform_idx=@var{pidx}:device_idx=@var{didx} ... +@end example @item -opencl_options options (@emph{global}) Set OpenCL environment options. This option is only available when ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
[FFmpeg-cvslog] OpenCL: Avoid potential buffer overflow in cmdutils_opencl.c
ffmpeg | branch: release/2.2 | Maneesh Gupta | Tue Apr 28 13:26:31 2015 +0530| [25daf27484ea6d9c090975893804aa4f096fcfd4] | committer: Michael Niedermayer OpenCL: Avoid potential buffer overflow in cmdutils_opencl.c The opt_opencl_bench function copied the device name using strcpy without checking if the source string was larger. This patch fixes this by replacing the strcpy with av_strlcpy, with the string copy size capped to the destination buffer size. Signed-off-by: Maneesh Gupta Signed-off-by: Michael Niedermayer (cherry picked from commit cf234552b83a9503ff96572de2658b921b8842eb) Signed-off-by: Michael Niedermayer > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=25daf27484ea6d9c090975893804aa4f096fcfd4 --- cmdutils_opencl.c |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmdutils_opencl.c b/cmdutils_opencl.c index d7e3287..8686096 100644 --- a/cmdutils_opencl.c +++ b/cmdutils_opencl.c @@ -22,6 +22,7 @@ #include "libavutil/time.h" #include "libavutil/log.h" #include "libavutil/opencl.h" +#include "libavutil/avstring.h" #include "cmdutils.h" typedef struct { @@ -238,7 +239,8 @@ int opt_opencl_bench(void *optctx, const char *opt, const char *arg) devices[count].platform_idx = i; devices[count].device_idx = j; devices[count].runtime = score; -strcpy(devices[count].device_name, device_node->device_name); +av_strlcpy(devices[count].device_name, device_node->device_name, + sizeof(devices[count].device_name)); count++; } } ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog