Thursday, July 23, 2009

Bug of the day

Todays entry is about a fun little bug that a customer reported the other day. The cause is very straight forward, if you know a little trivia about Windows.

Without going into too much detail, the product I work is a type of document management system. You add files to the document management system and can do various things to them. For various reasons the document management system sometimes creates icon files for different document types and stores these icon files in the local file system. For example if you added a file called 'abc.mp3' to the system then an icon might get created on the local file system called 'mp3.ico'. Seems reasonable right?

However a customer reported a bug that had our support team stumped. They were getting an error when they tired to add documents that had the file extension 'con'. If you know a bit about windows you have probably guessed the problem already. Since the very begining of time MS-DOS, and later Windows, have had a list of several file names that are reserved in all folders. From here:

Do not use the following reserved device names for the name of a file:
CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9

Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended.


Of course once you know this the cause of the bug is obvious. The user adds a file named 'abc.con' to the system, which then creates a file named 'con.ico', and then Windows gets upset. The reserved words are of course names of devices, they exist so you can use devices like files à la UNIX. The strange thing is they are reserved in all directories.

Anyway the lessons are:

1. The more general lesson: As the files names were essentially determined by user input they should have been sanitized at some point.

2. The more specific lesson: Be aware that there are some less obvious rules about valid file names in Windows.  

No comments: