[x265] [PATCH] Fix issue with left-over filename not being treated as input parameter

Kirithika Kalirathnam kirithika at multicorewareinc.com
Fri Sep 27 09:53:41 UTC 2024


Updated the patch to avoid buffer overrun that may occur when using strcpy.
>From 4008932553d1c57f12a649653f211086e591dd70 Mon Sep 17 00:00:00 2001
From: Kirithika <kirithika at multicorewareinc.com>
Date: Wed, 18 Sep 2024 14:52:12 +0530
Subject: [PATCH] Fix issue with left-over filename not being treated as
input
 parameter

This commit also fixes the buffer overrun issue that may occur due to strcpy
---
 source/x265cli.cpp | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/source/x265cli.cpp b/source/x265cli.cpp
index ca7d9c973..40eac4c8d 100755
--- a/source/x265cli.cpp
+++ b/source/x265cli.cpp
@@ -598,6 +598,7 @@ namespace X265_NS {
         for (int view = 0; view < MAX_VIEWS; view++)
         {
             inputfn[view] = X265_MALLOC(char, sizeof(char) * 1024);
+            memset(inputfn[view], 0, sizeof(char) * 1024);
         }
         const char* reconfn[MAX_LAYERS] = { NULL };
         const char *outputfn = NULL;
@@ -738,7 +739,7 @@ namespace X265_NS {
                 OPT("frames") this->framesToBeEncoded =
(uint32_t)x265_atoi(optarg, bError);
                 OPT("no-progress") this->bProgress = false;
                 OPT("output") outputfn = optarg;
-                OPT("input") strcpy(inputfn[0] , optarg);
+                OPT("input") strncpy(inputfn[0] , optarg, 1024);
                 OPT("recon") reconfn[0] = optarg;
                 OPT("input-depth") inputBitDepth =
(uint32_t)x265_atoi(optarg, bError);
                 OPT("dither") this->bDither = true;
@@ -805,10 +806,11 @@ namespace X265_NS {
             }
         }

-#if !ENABLE_MULTIVIEW
-        if (optind < argc && !inputfn[0])
-            inputfn[0] = argv[optind++];
-#endif
+        if (param->numViews < 2)
+        {
+            if (optind < argc && !(*inputfn[0]))
+                strncpy(inputfn[0], argv[optind++], 1024);
+        }
         if (optind < argc && !outputfn)
             outputfn = argv[optind++];
         if (optind < argc)
@@ -1406,7 +1408,7 @@ namespace X265_NS {
                         if (0);
                         OPT("input")
                         {
-                            strcpy(fn[numInput++], optarg);
+                            strncpy(fn[numInput++], optarg, 1024);
                         }

                     }
-- 
2.28.0.windows.1

*Thanks,*
*Kirithika*


On Fri, Sep 27, 2024 at 2:30 PM Kirithika Kalirathnam <
kirithika at multicorewareinc.com> wrote:

> Please ignore the previous patch and find the updated patch attached.
> From 89161b8e14b11ad595de610704b70c0a3ccd81c0 Mon Sep 17 00:00:00 2001
> From: Kirithika <kirithika at multicorewareinc.com>
> Date: Wed, 18 Sep 2024 14:52:12 +0530
> Subject: [PATCH] Fix issue with left-over filename not being treated as
> input
>  parameter
>
> ---
>  source/x265cli.cpp | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/source/x265cli.cpp b/source/x265cli.cpp
> index ca7d9c973..ba0b620b7 100755
> --- a/source/x265cli.cpp
> +++ b/source/x265cli.cpp
> @@ -598,6 +598,7 @@ namespace X265_NS {
>          for (int view = 0; view < MAX_VIEWS; view++)
>          {
>              inputfn[view] = X265_MALLOC(char, sizeof(char) * 1024);
> +            memset(inputfn[view], 0, sizeof(char) * 1024);
>          }
>          const char* reconfn[MAX_LAYERS] = { NULL };
>          const char *outputfn = NULL;
> @@ -805,10 +806,11 @@ namespace X265_NS {
>              }
>          }
>
> -#if !ENABLE_MULTIVIEW
> -        if (optind < argc && !inputfn[0])
> -            inputfn[0] = argv[optind++];
> -#endif
> +        if (param->numViews < 2)
> +        {
> +            if (optind < argc && !(*inputfn[0]))
> +                strcpy(inputfn[0], argv[optind++]);
> +        }
>          if (optind < argc && !outputfn)
>              outputfn = argv[optind++];
>          if (optind < argc)
> --
> 2.28.0.windows.1
>
> *Thanks,*
> *Kirithika*
>
>
> On Fri, Sep 27, 2024 at 10:12 AM Kirithika Kalirathnam <
> kirithika at multicorewareinc.com> wrote:
>
>> From 9bdaa0ace80a25523e6e66a4c792c4d81b7249a2 Mon Sep 17 00:00:00 2001
>> From: Kirithika <kirithika at multicorewareinc.com>
>> Date: Wed, 18 Sep 2024 14:52:12 +0530
>> Subject: [PATCH] Fix issue with left-over filename not being treated as
>> input
>>  parameter
>>
>> ---
>>  source/x265cli.cpp | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/source/x265cli.cpp b/source/x265cli.cpp
>> index ca7d9c973..26f15d5c6 100755
>> --- a/source/x265cli.cpp
>> +++ b/source/x265cli.cpp
>> @@ -598,6 +598,7 @@ namespace X265_NS {
>>          for (int view = 0; view < MAX_VIEWS; view++)
>>          {
>>              inputfn[view] = X265_MALLOC(char, sizeof(char) * 1024);
>> +            memset(inputfn[view], 0, sizeof(char) * 1024);
>>          }
>>          const char* reconfn[MAX_LAYERS] = { NULL };
>>          const char *outputfn = NULL;
>> @@ -806,8 +807,8 @@ namespace X265_NS {
>>          }
>>
>>  #if !ENABLE_MULTIVIEW
>> -        if (optind < argc && !inputfn[0])
>> -            inputfn[0] = argv[optind++];
>> +        if (optind < argc && !(*inputfn[0]))
>> +            strcpy(inputfn[0], argv[optind++]);
>>  #endif
>>          if (optind < argc && !outputfn)
>>              outputfn = argv[optind++];
>> --
>> 2.28.0.windows.1
>>
>> *Thanks,*
>> *Kirithika*
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20240927/c48f62ff/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: input-parameter-patch3.diff
Type: application/octet-stream
Size: 2259 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20240927/c48f62ff/attachment-0001.obj>


More information about the x265-devel mailing list