[gtk/matthiasc/for-master] cssfiltervalue: Reject invalid filters
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master] cssfiltervalue: Reject invalid filters
- Date: Sat, 6 Feb 2021 04:04:04 +0000 (UTC)
commit 9abebb5c71701d5c89b75b1d2db3e05418c78dab
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Feb 5 22:59:20 2021 -0500
cssfiltervalue: Reject invalid filters
The Filter Effects Spec doesn't allow negative values
for most of the filter parameters.
gtk/gtkcssfiltervalue.c | 48 ++++++++++++++++++++++++++++
testsuite/css/parser/invalid-filter1.css | 3 ++
testsuite/css/parser/invalid-filter1.errors | 1 +
testsuite/css/parser/invalid-filter1.ref.css | 0
4 files changed, 52 insertions(+)
---
diff --git a/gtk/gtkcssfiltervalue.c b/gtk/gtkcssfiltervalue.c
index b7d0c5b42b..4d697d7d88 100644
--- a/gtk/gtkcssfiltervalue.c
+++ b/gtk/gtkcssfiltervalue.c
@@ -826,6 +826,12 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
if (!gtk_css_parser_consume_function (parser, 1, 1, gtk_css_filter_parse_length,
&filter.blur.value))
goto fail;
+ if (_gtk_css_number_value_get (filter.blur.value, 100) < 0)
+ {
+ gtk_css_parser_error_syntax (parser, "Negative filter value not allowed");
+ goto fail;
+ }
+
filter.type = GTK_CSS_FILTER_BLUR;
computed = computed && gtk_css_value_is_computed (filter.blur.value);
}
@@ -834,6 +840,12 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
if (!gtk_css_parser_consume_function (parser, 1, 1, gtk_css_filter_parse_number,
&filter.brightness.value))
goto fail;
+ if (_gtk_css_number_value_get (filter.brightness.value, 100) < 0)
+ {
+ gtk_css_parser_error_syntax (parser, "Negative filter value not allowed");
+ goto fail;
+ }
+
filter.type = GTK_CSS_FILTER_BRIGHTNESS;
computed = computed && gtk_css_value_is_computed (filter.brightness.value);
}
@@ -842,6 +854,12 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
if (!gtk_css_parser_consume_function (parser, 1, 1, gtk_css_filter_parse_number,
&filter.contrast.value))
goto fail;
+ if (_gtk_css_number_value_get (filter.contrast.value, 100) < 0)
+ {
+ gtk_css_parser_error_syntax (parser, "Negative filter value not allowed");
+ goto fail;
+ }
+
filter.type = GTK_CSS_FILTER_CONTRAST;
computed = computed && gtk_css_value_is_computed (filter.contrast.value);
}
@@ -850,6 +868,12 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
if (!gtk_css_parser_consume_function (parser, 1, 1, gtk_css_filter_parse_number,
&filter.grayscale.value))
goto fail;
+ if (_gtk_css_number_value_get (filter.contrast.value, 100) < 0)
+ {
+ gtk_css_parser_error_syntax (parser, "Negative filter value not allowed");
+ goto fail;
+ }
+
filter.type = GTK_CSS_FILTER_GRAYSCALE;
computed = computed && gtk_css_value_is_computed (filter.grayscale.value);
}
@@ -866,6 +890,12 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
if (!gtk_css_parser_consume_function (parser, 1, 1, gtk_css_filter_parse_number,
&filter.invert.value))
goto fail;
+ if (_gtk_css_number_value_get (filter.invert.value, 100) < 0)
+ {
+ gtk_css_parser_error_syntax (parser, "Negative filter value not allowed");
+ goto fail;
+ }
+
filter.type = GTK_CSS_FILTER_INVERT;
computed = computed && gtk_css_value_is_computed (filter.invert.value);
}
@@ -874,6 +904,12 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
if (!gtk_css_parser_consume_function (parser, 1, 1, gtk_css_filter_parse_number,
&filter.opacity.value))
goto fail;
+ if (_gtk_css_number_value_get (filter.opacity.value, 100) < 0)
+ {
+ gtk_css_parser_error_syntax (parser, "Negative filter value not allowed");
+ goto fail;
+ }
+
filter.type = GTK_CSS_FILTER_OPACITY;
computed = computed && gtk_css_value_is_computed (filter.opacity.value);
}
@@ -882,6 +918,12 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
if (!gtk_css_parser_consume_function (parser, 1, 1, gtk_css_filter_parse_number,
&filter.saturate.value))
goto fail;
+ if (_gtk_css_number_value_get (filter.saturate.value, 100) < 0)
+ {
+ gtk_css_parser_error_syntax (parser, "Negative filter value not allowed");
+ goto fail;
+ }
+
filter.type = GTK_CSS_FILTER_SATURATE;
computed = computed && gtk_css_value_is_computed (filter.saturate.value);
}
@@ -890,6 +932,12 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
if (!gtk_css_parser_consume_function (parser, 1, 1, gtk_css_filter_parse_number,
&filter.sepia.value))
goto fail;
+ if (_gtk_css_number_value_get (filter.sepia.value, 100) < 0)
+ {
+ gtk_css_parser_error_syntax (parser, "Negative filter value not allowed");
+ goto fail;
+ }
+
filter.type = GTK_CSS_FILTER_SEPIA;
computed = computed && gtk_css_value_is_computed (filter.sepia.value);
}
diff --git a/testsuite/css/parser/invalid-filter1.css b/testsuite/css/parser/invalid-filter1.css
new file mode 100644
index 0000000000..52580b853e
--- /dev/null
+++ b/testsuite/css/parser/invalid-filter1.css
@@ -0,0 +1,3 @@
+a {
+ filter: blur(-1px);
+}
diff --git a/testsuite/css/parser/invalid-filter1.errors b/testsuite/css/parser/invalid-filter1.errors
new file mode 100644
index 0000000000..b91e500d69
--- /dev/null
+++ b/testsuite/css/parser/invalid-filter1.errors
@@ -0,0 +1 @@
+invalid-filter1.css:2:20-21: error: GTK_CSS_PARSER_ERROR_SYNTAX
diff --git a/testsuite/css/parser/invalid-filter1.ref.css b/testsuite/css/parser/invalid-filter1.ref.css
new file mode 100644
index 0000000000..e69de29bb2
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]