History

m_option: forbid non -1 negative values for video-aspect-override

Setting this to M_RANGE(-1, 10) meant that you could pass fractional negative values without it being an error. This is, of course, nonsense. -1 is the only special negative value with a meaning. Error out if we get anything else by doing some additional parsing before we send it off to parse_double which will then restrict the range to 0, 10 with these changes. Note that this approach requires defval to be there which is not the most extensible thing in the world. But there's literally only two OPT_ASPECT type options out of the hundreds we have so not a big deal. Ideally, this type should be OPT_CHOICE but with underlying doubles but that's too much effort to implement cleanly.

Dudemanguy committed 1 year ago

Commit cb91de21 parent 16828aa2 files · +15 −1Browse files

Unified · Split

2 files
  1. filters/f_decoder_wrapper.c +2 −1
  2. options/m_option.c +13 −0
filters/f_decoder_wrapper.c+2−1
@@ -125,7 +125,8 @@ const struct m_sub_options dec_wrapper_conf = { · 124 unmodified lines
125125 {"video-rotate", OPT_CHOICE(video_rotate, {"no", -1}),
126126 .flags = UPDATE_IMGPAR, M_RANGE(0, 359)},
127127 {"video-aspect-override", OPT_ASPECT(movie_aspect),
128− .flags = UPDATE_IMGPAR, M_RANGE(-1, 10)},
128+ .flags = UPDATE_IMGPAR, M_RANGE(0, 10),
129+ OPTDEF_DOUBLE(-1.0)},
129130 {"video-aspect-method", OPT_CHOICE(aspect_method,
130131 {"bitstream", 1}, {"container", 2}),
131132 .flags = UPDATE_IMGPAR},
options/m_option.c+13−0
@@ -1116,6 +1116,19 @@ static int parse_double_aspect(struct mp_log *log, const m_option_t *opt, · 1115 unmodified lines
11161116 VAL(dst) = 0.0;
11171117 return 1;
11181118 }
1119+
1120+ // Potentially allow -1 but forbid all other negative values.
1121+ if (opt->defval && *(double *)opt->defval == -1) {
1122+ struct bstr rest;
1123+ double val = bstrtod(param, &rest);
1124+ if (bstr_eatstart0(&rest, ":") || bstr_eatstart0(&rest, "/"))
1125+ val /= bstrtod(rest, &rest);
1126+ if (val == -1 && dst) {
1127+ VAL(dst) = -1.0;
1128+ return 1;
1129+ }
1130+ }
1131+
11191132 return parse_double(log, opt, name, param, dst);
11201133 }
11211134

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t