[FFmpeg-trac] #10320(avutil:new): `av_opt_set_int()` overflow/not-working bug

FFmpeg trac at avcodec.org
Fri Apr 14 20:00:44 EEST 2023


#10320: `av_opt_set_int()`  overflow/not-working bug
-------------------------------------+-------------------------------------
             Reporter:  think3r      |                     Type:  defect
               Status:  new          |                 Priority:  normal
            Component:  avutil       |                  Version:  git-
             Keywords:  Integer      |  master
  overflow                           |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------
 = `av_opt_set_int()` function will overflow/failed when set a large
 `uint64_t` number

 * below is the test code from `libavutil/tests/opt.c` :

 {{{
 diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
 index 5799e45c6a..c950cfab16 100644
 --- a/libavutil/tests/opt.c
 +++ b/libavutil/tests/opt.c
 @@ -49,6 +49,7 @@ typedef struct TestContext {
      void *binary2;
      int binary_size2;
      int64_t num64;
 +    uint64_t numu64;
      float flt;
      double dbl;
      char *escape;
 @@ -86,6 +87,7 @@ static const AVOption test_options[]= {
      {"bin1",       "set binary value",   OFFSET(binary1),
 AV_OPT_TYPE_BINARY,         { .str=NULL },                     0,
 0, 1 },
      {"bin2",       "set binary value",   OFFSET(binary2),
 AV_OPT_TYPE_BINARY,         { .str="" },                       0,
 0, 1 },
      {"num64",      "set num 64bit",      OFFSET(num64),
 AV_OPT_TYPE_INT64,          { .i64 = 1 },                      0,
 100, 1 },
 +    {"numu64",     "set num u64",        OFFSET(numu64),
 AV_OPT_TYPE_UINT64,         { .i64 = 0xb4000078c6bdbb60 },     0,
 UINT_MAX, 1 },
      {"flt",        "set float",          OFFSET(flt),
 AV_OPT_TYPE_FLOAT,          { .dbl = 1.0 / 3 },                0,
 100, 1 },
      {"dbl",        "set double",         OFFSET(dbl),
 AV_OPT_TYPE_DOUBLE,         { .dbl = 1.0 / 3 },                0,
 100, 1 },
      {"bool1",      "set boolean value",  OFFSET(bool1),
 AV_OPT_TYPE_BOOL,           { .i64 = -1 },                    -1,
 1, 1 },
 }}}

 * The error : `Value -5476376628152124416.000000 for parameter 'numu64'
 out of range [0 - 4.29497e+09]`

 * Reason : Loss of precision when convert between `int64_t`/`uint64_t` and
 `double`. Which will happends on :
   1. `AVOption.max` and `AVOption.min`
   2. `write_number()` in file `libavutil/opt.c`
-- 
Ticket URL: <https://trac.ffmpeg.org/ticket/10320>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list