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

Karam Singh karam.singh at multicorewareinc.com
Mon Sep 30 08:19:41 UTC 2024


This patch has been pushed to the master branch.
*__________________________*
*Karam Singh*
*Ph.D. IIT Guwahati*
Senior Software (Video Coding) Engineer
Mobile: +91 8011279030
Block 9A, 6th floor, DLF Cyber City
Manapakkam, Chennai 600 089


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

> 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*
>>>
>> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20240930/e3560e6b/attachment-0001.htm>


More information about the x265-devel mailing list