Index: modules/profile/profile.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.test,v
retrieving revision 1.30
diff -u -p -r1.30 profile.test
--- modules/profile/profile.test	30 Aug 2010 00:22:03 -0000	1.30
+++ modules/profile/profile.test	12 Oct 2010 10:26:02 -0000
@@ -160,6 +160,50 @@ class ProfileTestCase extends DrupalWebT
   }
 }
 
+class ProfileTestUserFields extends ProfileTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => "Test that custom fields don't break user pictures.",
+      'description' => "Test that custom fields don't break user pictures.",
+      'group' => 'Profile'
+    );
+  }
+
+  public function testProfileFields() {
+    variable_set('user_pictures', 1);
+
+    $this->drupalLogin($this->normal_user);
+    $user_picture = $this->createUserPicture();
+
+    $this->drupalLogin($this->admin_user);
+    $field = $this->createProfileField('textfield');
+    $this->drupalLogout();
+
+    $this->drupalLogin($this->normal_user);
+    $this->setProfileField($field);
+    $this->drupalGet('user');
+    $this->assertRaw(file_uri_target($user_picture->uri), t("Image is displayed in user's profile page after creating and setting a profile field."));
+  }
+
+  protected function createUserPicture() {
+
+    $image = current($this->drupalGetTestFiles('image'));
+    $info = image_get_info($image->uri);
+    $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10);
+    variable_set('user_picture_dimensions', $test_dim);
+    variable_set('user_picture_file_size', 0);
+
+    $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
+    $this->drupalPost('user/' . $this->normal_user->uid . '/edit', $edit, t('Save'));
+
+    $account = user_load($this->normal_user->uid, TRUE);
+    $pic_path = isset($account->picture) ? $account->picture->uri : NULL;
+    $this->drupalGet('user');
+    $this->assertRaw(file_uri_target($pic_path), t("Image is displayed in user's profile page"));
+    return $pic_path? $account->picture : FALSE;
+  }
+}
+
 class ProfileTestFields extends ProfileTestCase {
   public static function getInfo() {
     return array(
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.1208
diff -u -p -r1.1208 user.module
--- modules/user/user.module	11 Oct 2010 19:43:23 -0000	1.1208
+++ modules/user/user.module	12 Oct 2010 10:26:12 -0000
@@ -446,13 +446,15 @@ function user_save($account, $edit = arr
         }
       }
 
-      // Delete the previous picture if it was deleted or replaced.
-      if ($delete_previous_picture && !empty($account->picture->fid)) {
-        file_usage_delete($account->picture, 'user', 'user', $account->uid);
-        file_delete($account->picture);
-      }
+      if ($category == 'account') {
+        // Delete the previous picture if it was deleted or replaced.
+        if ($delete_previous_picture && !empty($account->picture->fid)) {
+          file_usage_delete($account->picture, 'user', 'user', $account->uid);
+          file_delete($account->picture);
+        }
 
-      $edit['picture'] = empty($edit['picture']->fid) ? 0 : $edit['picture']->fid;
+        $edit['picture'] = empty($edit['picture']->fid) ? 0 : $edit['picture']->fid;
+      }
 
       // Do not allow 'uid' to be changed.
       $edit['uid'] = $account->uid;
