summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@coaxion.net>2020-12-21 17:48:45 +0000
committerSebastian Dröge <slomo@coaxion.net>2020-12-21 17:48:45 +0000
commit8f590df123715011b7d1e005e3f618e0ded4fdec (patch)
treeaf47122a8630bb1da8b93d39fa01a92f88eb5f9b
parent581ae46efea67986965057fcc21e9879abdf031e (diff)
parentfec38762b313c735c6ece54feae3535c9be130c8 (diff)
downloadglib-8f590df123715011b7d1e005e3f618e0ded4fdec.tar.gz
Merge branch 'ossfuzz-28718-date-normalization' into 'master'
gdate: Limit length of dates which can be parsed as valid See merge request GNOME/glib!1821
-rw-r--r--glib/gdate.c9
-rw-r--r--glib/tests/date.c4
2 files changed, 12 insertions, 1 deletions
diff --git a/glib/gdate.c b/glib/gdate.c
index 391b142a8..253ab6524 100644
--- a/glib/gdate.c
+++ b/glib/gdate.c
@@ -1229,14 +1229,21 @@ g_date_set_parse (GDate *d,
{
GDateParseTokens pt;
guint m = G_DATE_BAD_MONTH, day = G_DATE_BAD_DAY, y = G_DATE_BAD_YEAR;
+ gsize str_len;
g_return_if_fail (d != NULL);
/* set invalid */
g_date_clear (d, 1);
+ /* Anything longer than this is ridiculous and could take a while to normalize.
+ * This limit is chosen arbitrarily. */
+ str_len = strlen (str);
+ if (str_len > 200)
+ return;
+
/* The input has to be valid UTF-8. */
- if (!g_utf8_validate (str, -1, NULL))
+ if (!g_utf8_validate_len (str, str_len, NULL))
return;
G_LOCK (g_date_global);
diff --git a/glib/tests/date.c b/glib/tests/date.c
index 38de1d9be..542293c4b 100644
--- a/glib/tests/date.c
+++ b/glib/tests/date.c
@@ -191,6 +191,10 @@ test_parse_invalid (void)
{
/* Incomplete UTF-8 sequence */
"\xfd",
+ /* Ridiculously long input */
+ "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
+ "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
+ "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
};
gsize i;