--- image.module.orig	2007-12-18 23:56:48.000000000 +0100
+++ image.module	2008-01-03 14:18:18.237352995 +0100
@@ -385,21 +385,23 @@
   $result = db_query("SELECT f.nid, f.filename, f.filesize, f.filemime FROM {files} f WHERE f.filepath = '%s'", $filepath);
   if ($file = db_fetch_object($result)) {
     $node = node_load(array('type' => 'image', 'nid' => $file->nid));
-    if (node_access('view', $node)) {
-      // The user either needs to have 'view original images' permission or
-      // the path must be listed for something other than the node's original
-      // size. This will be the case when the orignal is smaller than a 
-      // derivative size.
-      $images = (array) $node->images;
-      unset($images[IMAGE_ORIGINAL]);
-      if (user_access('view original images') || in_array($filepath, $images)) {
-        return array(
-          'Content-Type: '. mime_header_encode($file->filemime),
-          'Content-Length: '. (int) $file->filesize,
-        );
+    if ($node) {
+      if (node_access('view', $node)) {
+        // The user either needs to have 'view original images' permission or
+        // the path must be listed for something other than the node's original
+        // size. This will be the case when the orignal is smaller than a 
+        // derivative size.
+        $images = (array) $node->images;
+        unset($images[IMAGE_ORIGINAL]);
+        if (user_access('view original images') || in_array($filepath, $images)) {
+          return array(
+            'Content-Type: '. mime_header_encode($file->filemime),
+            'Content-Length: '. (int) $file->filesize,
+          );
+        }
       }
+      return -1;
     }
-    return -1;
   }
 }
 
