From 01f7fc0ad13a3bd53d436a4eaf0dfcb52cb4c286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Cartegnie?= Date: Thu, 27 Nov 2025 15:52:55 +0100 Subject: [PATCH] test: webvtt: add CSS parser error recovery test --- modules/codec/webvtt/css_test.c | 47 ++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/modules/codec/webvtt/css_test.c b/modules/codec/webvtt/css_test.c index ae0b87d24f..1234c65fa8 100644 --- a/modules/codec/webvtt/css_test.c +++ b/modules/codec/webvtt/css_test.c @@ -425,11 +425,56 @@ error: return 1; } +static int test_error_cases(void) +{ + const char *css = + /* Invalid charset */ + "@charset \"UTF-8\" extra;\n" + "@charset ;\n" + /* Invalid block */ + "el1 { color { ; color: red } }\n" + "el2 { color: red; }\n" + "el3 { color: red !important fail; }\n" + "el4 { font-family: ; }\n" + "el5 { weight: *; }\n" + "el6 { color: red; !important }\n" + /* Invalid selectors */ + "#123abc { color: red; }\n" /* HASH starting with digit triggers YYERROR */ + "el7 + ;\n" /* combinators without right side */ + "el8 ~ ;\n" + "el9 > ;\n" + "el10 , ;\n" + /* Invalid declarations */ + "div { ; }\n" + "div { color: ; }\n" + "div { color: *; }\n" + /* Invalid function / expr */ + "div { foo(): 1; }\n" + "div { bar( ; }\n" + ; + + PARSE_CSS("test_error_cases"); + + /* We just want to make sure the parser + * does not crash on error handling and backtracking + * and frees memory */ + + VLC_UNUSED(rule); + + vlc_css_parser_Clean(&p); + return 0; + +error: + vlc_css_parser_Clean(&p); + return 1; +} + int main(void) { return test_element_selectors() || test_attributes_selectors() || test_pseudo_selectors() || test_combinators() || - test_values(); + test_values() || + test_error_cases(); }