Apache mod_rewrite bug still lurks

There’s this enormous apache mod_rewrite bug that I ran into back in 2005, and to my dismay, it’s still there. Long-standing bugs are usually small edge cases that don’t affect many people, but this one is a monster that I suspects pretty much everyone that’s using mod_rewrite, and they’ve just been lucky in avoiding it. The basic issue is this: if you match params that require URL encoding to be safe, mod_rewrite will not rewrite the back-reference (that’s $1 below) correctly. So take this very simple redirect:

RewriteRule ^(.*)$ index.php?show=$1 [R]

so you hit http://www.example.com/a%2Fb and mod_rewrite neatly rewrites it as http://www.example.com/index.php?show=a/b! Notice that it has urldecoded the matched parameter in the replacement string.

Apache 2.2 introduced a new B flag to deal with this, but that apparently suffers the same problem! There are two workarounds I’ve used that are both horrible: double-encode the source string (if you are in control of both start and end points of the URLs) to survive the spurious urldecode, or base-64 encode (javascript flavour) it and do the decoding yourself. I did warn you they were horrible.

I’ll bet that there are a zillion mod_rewrites out there that suffer from this fundamental problem and haven’t even noticed. If a few people voted for this to be fixed, it would probably go away…

Subversion MERGE error on commit nailed

Recently I’ve had a problem with subversion commits returning a ‘200 OK’ result, accompanied by a peculiar MERGE error (when I’m not doing a merge), but weirdly, the commit had actually made it into the repo. I’d googled for this a while ago with no success, but I had another try today and found this post. Thinking about it, I’d had this problem since updating to the very-very-long-awaited trac 0.11 release. So I tracked down the latest release of the trac-post-commit-hook script and installed that, and amazingly enough, it just works. Thank you UberGeek!

Munin per-plugin timeouts

I had a munin plugin that suddenly stopped reporting, and in the munin-node log there were lots of errors like this:

2007/06/27-06:50:26 Plugin timeout: myplugin : Interrupted system call

So it looks like the plugin is taking too long, but how to extend the timeout? Seems I’m not alone in wondering this. So I had a rummage in the source of munin-node, and it seems to want a ‘timeout’ parameter in its config. So I added a simple timeout 60 to munin-node.conf and it worked! However, that’s a global setting rather than a per-plugin timeout, so I took a flying guess at putting the same directive in my plugin spec in /etc/munin/plugin-conf.d/munin-node like this:
timeout 60
user root

And that worked too!


Well, Hackday was certainly an experience – the lightning strike and the roof vents opening was really quite disturbing! The lack of WiFi early on was a real pain as it made it very hard to connect projects, people and skills, so I suspect that most hacks were done by people who had arranged something beforehand, or who happened to meet at the bus stop.

Anyway, I got involved, along with Rob, Andy, Edward and James in something that turned into Fruitr – the search engine for unimaginative chefs. The basic idea was: take a picture of a piece of fruit, submit it to our site, and you’re rewarded with recipes that use that fruit. Rob and James worked on using a C++ image recognition library (not sure which one) from a Pylons Python app, which was driven by statistical matching against images from Flickr that are tagged with ‘fruitr’. Edward provided API access to his database of recipes courtesy of his site BigMunch, and I developed the testing web interface (later rolled into the main python app), and the email (in and out) interface. Andy had an abortive attempt at creating a J2ME app to talk to it, but was hampered by BlueTooth interference, buggy phones and poor mobile reception. We really had it all running by about midnight, and just a final polish was needed in the morning.

I spent much of Sunday looking at APIs to use with AMEE, without much luck or inspiration, then messed about creating an Apple Quartz Composer file that can be used as a screen saver. It grabs images tagged with ‘hackdaylondon’ from Flickr and presents them on faces of a bunch of rotating cubes. One face of the cubes displays live video (assuming you’re on a Mac Book? or similar which has a camera). There is also a spectrum-driven audio bar display, and a rotating Hack Day logo, which is also moved by sound. You can download the Quartz composer file.

I did the presentations for both hacks. For the Fruitr one I just ran out of time – sweaty fingers and trackpads really don’t mix. Because demoing a screen saver is not too hard, I dressed it up as a load of presentation faux-pas. I hope nobody thought it was for real!

Generally it was all pretty good fun, and it certainly had an excellent atmosphere, not to mention the endless supply of chocolate. Playing doubles tennis on the Wii at 2am was another highlight, along with the “non-showing” of Doctor Who…

I needed to leave before prizes and the Rumble Strips gig, so I missed out on that bit, and at the end of it all, I completely failed to grab a pink bean bag for Z. Oh well, I’ll be back next year!