Skip to content

Commit caf774e

Browse files
committed
lavc: Don't crash on missing codec opts
codec->priv_class could be null, fixes GH-435
1 parent af222c7 commit caf774e

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

src/video_compress/libavcodec.cpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,30 +2123,15 @@ get_opt_default_value(const AVOption *opt)
21232123
}
21242124
}
21252125

2126-
/// @aram encoder - if bool, print for both encoder and decoder
2127-
static bool
2128-
show_coder_help(string const &name, bool encoder)
2129-
{
2130-
bool dec_found = true;
2131-
if (encoder) {
2132-
dec_found = show_coder_help(name, false);
2133-
}
2134-
const auto *codec = encoder
2135-
? avcodec_find_encoder_by_name(name.c_str())
2136-
: avcodec_find_decoder_by_name(name.c_str());
2137-
if (codec == nullptr) {
2138-
if (!dec_found) {
2139-
MSG(ERROR,
2140-
"Unable to find neither encoder nor decoder %s!\n",
2141-
name.c_str());
2142-
}
2143-
return false;
2144-
}
2126+
static void print_codec_opts(const std::string& name, bool encoder, const AVCodec *codec){
2127+
if(!codec->priv_class)
2128+
return;
2129+
21452130
col() << "Options for " << SBOLD(name) << " "
21462131
<< (encoder ? "encoder" : "decoder") << ":\n";
21472132
const auto *opt = codec->priv_class->option;
21482133
if (opt == nullptr) {
2149-
return true;
2134+
return;
21502135
}
21512136
while (opt->name != nullptr) {
21522137
string default_val;
@@ -2175,6 +2160,28 @@ show_coder_help(string const &name, bool encoder)
21752160
col() << indent << SBOLD(opt->name) << help_str << default_val << "\n";
21762161
opt++;
21772162
}
2163+
}
2164+
2165+
/// @aram encoder - if bool, print for both encoder and decoder
2166+
static bool
2167+
show_coder_help(string const &name, bool encoder)
2168+
{
2169+
bool dec_found = true;
2170+
if (encoder) {
2171+
dec_found = show_coder_help(name, false);
2172+
}
2173+
const auto *codec = encoder
2174+
? avcodec_find_encoder_by_name(name.c_str())
2175+
: avcodec_find_decoder_by_name(name.c_str());
2176+
if (codec == nullptr) {
2177+
if (!dec_found) {
2178+
MSG(ERROR,
2179+
"Unable to find neither encoder nor decoder %s!\n",
2180+
name.c_str());
2181+
}
2182+
return false;
2183+
}
2184+
print_codec_opts(name, encoder, codec);
21782185
print_codec_aux_usage(name);
21792186
color_printf("\n");
21802187
return true;

0 commit comments

Comments
 (0)