revjim.net Rotating Header Image

It's my own damn fault

So Gallery breaks under PHP5.0.0b3. Big deal. I'll just put PHP4 back. Hah. WRONG!

Running an existing Gallery under PHP5.0.0b3 that was running under PHP4 causes it to break simply by accessing it in your browser window. And, it doesn't just break with some ugly error messages that are repaired when you put PHP4 back. It breaks for good.

There are some bugs in PHP5 that have to do with "serialize" and "unserialize" (unserialize lowercases class names which confuses AutoLoad functions, and object references are not properly preserved with unserialize). Both of these bugs have been fixed in CVS but weren't fixed when PHP5.0.0b3 was released. That, in itself, isn't a problem. I mean sure, that might lead Gallery not to work under PHP5. But it doesn't cause any permanent damage alone.

However, when coupled with the horrible code that is Gallery, things get a bit worse. Although I can't find proof of this in their code (since it's nearly impossible to read and understand) it seems that whenever an album, or photo is viewed Gallery reads the album data and photo data from two files in the file system using "unserialize". These files were created with "serialize" and they contain all of the information about the items in your gallery. In order to store how many times an album has been viewed, and other assorted data like that, it updates those counters in memory and then "serialize"s them to the disk. However, it seems they don't ever bother to check that the "unserialized" data looks even remotely close to what they are expecting. They just alter whatever they feel the need to alter, "serialize" again and stuff it back on the file system. And, since PHP5.0.0b3 reads the serialized data in wrong, it was of course written back out wrong. Simply by viewing the album. And because all of the data for the photographs are stored in one file per album, all of the photos in the album, and the album itself, become destroyed with no complaint or apparent problem.

It's akin to having a script that would access a row in a table on a database server. Then, regardless of whether it was capable of successfully retrieving that row, it would rewrite it to the table. And, if the table didn't look the way it expected the table to look, it would simply drop the table and create a new one.

So, needless to say, as PHP5 ran for about 1 hour yesterday, several web bots and miscellaneous people were looking at various albums. All in all, I think 9 were lost on the entire server. At least, that's what I know of so far.

However, there is hope. I guess Gallery knows that what it is doing is stupid. So, to save themselves a bit, they make a backup of the datafile before they overwrite it. But, only one backup. In a couple of cases, this one backup was enough. In most of the cases, the backup was as ruined as the current version.

Now, the images themselves aren't lost. They remained in the directory untouched. However, without those image names being referenced in the datafiles, they don't appear. And, along with the image name references went the name of the album, any image captions, the permissions of the album, click counts, picture votes, comments, etc. Even if I could decipher exactly what those datafiles are supposed to look like and how to generate every different possibility in them, the caption data and ownership information are lost. So, it doesn't really do any good.

It's my own fault and I take full responsibility.

There is one good thing that comes of this. Because there is so much data on the server, I never had the means to back it all up, so I just backed up my own stuff every now and then. Well, I will be doing full daily backups of all server data starting… hopefully today… or whenever I get the rsync script for it written.

Again, if you lost any images, I am very, very sorry. I'll be happy to credit a couple months of service for you.

In order to fix your broken gallerys you'll need to rebuild the albums and then reupload the images. If you don't have the images any more, let me know and I'll send them to you.

Again, I'm very, very sorry. I was stupid. I'm a fuck up.

Google Buzz
blog comments powered by Disqus