Some Bugs Are Really Funny

People learn from errors. Therefore bugs should be made public, not hidden.

GLib is a utility library originally developed for GNOME but also used by other projects. One of many functions it provides is g_date_set_parse(). It is really smart and simple. It accepts a string to parse but other than many date parsing functions it does not require a date format to be passed. Instead it tries to find numbers and month names in the parsed string and figure out what date they can represent. Of course, month names are recognized according to the current locale.

Let’s see how it works for Polish. Here is the list of month names:

Month # Full name Abbreviated name
1. Styczeń Sty
2. Luty Lut
3. Marzec Mar
4. Kwiecień Kwi
5. Maj Maj
6. Czerwiec Cze
7. Lipiec Lip
8. Sierpień Sie
9. Wrzesień Wrz
10. Październik Paź
11. Listopad Lis
12. Grudzień Gru

The loop implementing the algorithm iterates over all months and checks if the string being parsed contains a full or abbreviated month name as a substring. The first month which is found as a substring of the parsed string is recognized as a result. Let’s see what happens when a string containing the 9th month, September, which in Polish is wrzesień, is parsed by this algorithm:

Iteration # Full name Abbreviated name Does the string wrzesień contain it?
1. Styczeń Sty No
2. Luty Lut No
3. Marzec Mar No
4. Kwiecień Kwi No
5. Maj Maj No
6. Czerwiec Cze No
7. Lipiec Lip No
8. Sierpień Sie Yes: wrzesień!

So, as a result, the string wrzesień (September) is recognized as sierpień (August).

Is this severe at all?

To be honest, not really. The bug seems to have been around for 20 years now and nobody has complained so far. Parsing dates is not really useful. There are many good reasons why it may not work in localized texts, like incomplete or incorrect translations, varying orthographic rules, Unicode characters updates, etc. Probably no real applications actually use this.

Nevertheless, the problem has been reported to GNOME Bugzilla and will be worked on.