OpenOffice Will Not Print on Tuesdays
Magicus dies Martis
PostScript jobs misidentified as Erlang bytecode on Tuesdays only.
- First Observed
- 2008
- Habitat
- CUPS print queues, Ubuntu 8.04
- Reported By
- Ubuntu Launchpad bug #255161
- Consequence
- Weekly status reports go unprinted.
The user's complaint to the Ubuntu bug tracker, filed in August 2008, was brief: OpenOffice will not print on Tuesdays. The bug had been observed for several weeks. The user wanted help.
The chain that produced this misery is short, and every link is reasonable in isolation.
OpenOffice writes its print output as a PostScript file. PostScript files are plain text, and
they conventionally begin with a comment header that records when the file was generated.
OpenOffice's header looked like %%CreationDate: (Tue Aug 12 10:14:22 2008). The header is harmless and ignored by
every PostScript interpreter.
The print system is CUPS. CUPS does not trust applications to declare the file format of their
output. Instead it shells out to file, the venerable Unix utility for sniffing
file types from their first few bytes. The file command looks up the bytes in a
magic database compiled from human-written rules.
One of those rules described Erlang JAM bytecode. The Erlang virtual machine, in its earlier
form, emitted compiled bytecode files whose first bytes were the three-character string Tue, followed by a space and a date. The rule worked beautifully on Erlang JAM
files. The rule also worked beautifully on any PostScript file generated by OpenOffice on a
Tuesday, because the PostScript file's first non-comment line started with the comment header,
which started with %%CreationDate: (Tue.
The pattern in the magic database matched on three bytes plus a space. The PostScript file
matched. CUPS asked file what to do with the document; file reported
"Erlang JAM bytecode"; CUPS had no handler for Erlang bytecode and refused to print.
The diagnosis was made by a user comparing print queues on a Tuesday and a Wednesday. The fix was to tighten the magic rule for Erlang JAM so that it required additional bytes specific to the JAM format. Four lines of patch. Three years between the introduction of the bug and the day someone connected the calendar to the file format.
The lesson is one most working programmers know in the abstract: every magic-byte detector is wrong on inputs its author did not imagine. The lesson made memorable is that some inputs only occur one day a week.