m_property: stop expanding strings after 10 properties during fuzzing

Some properties, like `${decoder-list}`, are resource-intensive to
expand. Prevent fuzzing from generating strings with excessive
expansions to encourage shorter test cases.

Expanding properties on each playback frame for `osd-msg1` can be
demanding. However, in regular use cases, this typically isn’t an issue,
so implementing a caching solution wouldn’t be practical in real
scenarios.

Fixes timeouts on OSS-Fuzz.
This commit is contained in:
Kacper Michajłow 2024-11-02 02:04:51 +01:00
parent 4def28ad0d
commit 2054d872d4
1 changed files with 7 additions and 0 deletions

View File

@ -293,6 +293,9 @@ char *m_properties_expand_string(const struct m_property *prop_list,
bool skip = false; bool skip = false;
int level = 0, skip_level = 0; int level = 0, skip_level = 0;
bstr str = bstr0(str0); bstr str = bstr0(str0);
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
int n = 0;
#endif
while (str.len) { while (str.len) {
if (level > 0 && bstr_eatstart0(&str, "}")) { if (level > 0 && bstr_eatstart0(&str, "}")) {
@ -311,6 +314,10 @@ char *m_properties_expand_string(const struct m_property *prop_list,
bool have_fallback = bstr_eatstart0(&str, ":"); bool have_fallback = bstr_eatstart0(&str, ":");
if (!skip) { if (!skip) {
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if (n++ > 10)
break;
#endif
skip = expand_property(prop_list, &ret, &ret_len, name, skip = expand_property(prop_list, &ret, &ret_len, name,
have_fallback, ctx); have_fallback, ctx);
if (skip) if (skip)