One Bug Down

Argg. I just spent all morning figuring out why some pages on this site wouldn’t load. The issue came down to a call to getimagesize in wp-content/plugins/textile2-new.php.

The change that fixed it (in unified diff format):

--- textile2-new.php.old        Tue Jun  8 23:36:12 2004
+++ textile2-new.php    Sun Jul 11 15:19:04 2004
@@ -2805,7 +2805,7 @@
         }
       }
     }
-    return @getimagesize($file);
+    return;
   } // function image_size

   /**

Read on for a more detailed discussion.

Here’s a copy of the old code:

  function image_size($file) {
    $Have_ImageSize = function_exists('getimagesize');
    if ($Have_ImageSize) {
      if (file_exists($file)) {
        return @getimagesize($file);
      } else {
        if ($docroot = ($this->docroot() ? $this->docroot() : $_SERVER['DOCUMENT_ROOT'])) {
          $fullpath = $docroot . preg_replace('|^/*(.*)$|', '/$1', $file);
          if (file_exists($fullpath)) {
            return @getimagesize($fullpath);
          }
        }
      }
    }
    return @getimagesize($file);
  } // function image_size

Notice how getimagesize is called even if it doesn’t exists? Well that’s poor form, but the @ in front of getimagesize hides all error messages. Convenient.

But the problem came down to this, my host appears to silently fail if getimagesize is called with a remote URL. So all my posts that linked to pictures on remote sites weren’t working.

The new code block fixes this by ensuring that file_exists is called before any getimagesize call.