GNOME Bugzilla – Bug 503029
g_time_val_from_iso8601 parse non-ISO8601 dates
Last modified: 2007-12-19 17:42:04 UTC
Parsing this date: Thu, 06 Apr 2006 09:00:00 PDT Gives back an ISO8601 date: -1-11-30T00:00:00Z
This string is used in this Podcast: http://www.symantec.com/content/en/us/about/rss/ent/ent.xml and parsed using totem-pl-parser. It should be enough to check whether the first bits of string passed are numerical or not, rather than blindly pushing them through strtoul.
Created attachment 100771 [details] [review] glib-ignore-non-iso8601-dates.patch Patch tested with the mentioned testcase.
From looking at the "Years" section of http://en.wikipedia.org/wiki/ISO_8601 it appears that -50000-01-01 is a valid way to refer to January 1, 50000BC
(In reply to comment #3) > From looking at the "Years" section of http://en.wikipedia.org/wiki/ISO_8601 > it appears that -50000-01-01 is a valid way to refer to January 1, 50000BC I guess we can easily check whether the first digit is a '-'. + if (!g_ascii_isdigit (*iso_date) || *iso_date != '-') Would that do?
According to the article I cited, it can also be a +. Anyway, how does that help you with your example of -1-11-30T00:00:00Z ?
(In reply to comment #5) > According to the article I cited, it can also be a +. + if (!g_ascii_isdigit (*iso_date) || *iso_date != '-' || *iso_date != '+') > Anyway, how does that help you with your example of -1-11-30T00:00:00Z ? No, the bug is that g_time_val_from_iso8601 parses "Thu, 06 Apr 2006 09:00:00 PDT" as an ISO 8601.
Ah, ok then. Go ahead, with that change.
Fixed in trunk and 2.14. Thanks. 2007-12-13 Bastien Nocera <hadess@hadess.net> * glib/gtimer.c: (g_time_val_from_iso8601): Don't try to parse dates that start with anything but a digit, a plus or a minus sign, as those can't be valid ISO8601 dates (Closes: #503029)
the applied patch is completely wrong: the icondition checked will always fail, and it's also missing a pointer dereference (which produced a warning). this fixes the regression spotted by the test suite and fixes the bug as well. - if (!g_ascii_isdigit (*iso_date) || iso_date != '-' || *iso_date != '+') + + if (!g_ascii_isdigit (*iso_date) && *iso_date != '-' && *iso_date != '+') I can apply it and add a check on the test suite as well.
committed to trunk, should go in glib-2-14 as well. 2007-12-19 Emmanuele Bassi <ebassi@gnome.org> * glib/gtimer.c (g_time_val_from_iso8601): Fix the date validation check. (#503029) * tests/testglib.c (various_string_tests): Add an invalid date for testing the above fix.
committed to glib-2-14 branch as well.