Index: includes/ajax.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/ajax.inc,v
retrieving revision 1.28
diff -u -p -r1.28 ajax.inc
--- includes/ajax.inc	26 Mar 2010 18:58:12 -0000	1.28
+++ includes/ajax.inc	29 Mar 2010 23:11:15 -0000
@@ -270,7 +270,9 @@ function ajax_form_callback() {
 
   // This call recreates the form relying solely on the $form_state that
   // drupal_process_form() set up.
-  $form = drupal_rebuild_form($form_id, $form_state, $form_build_id);
+  if ($form_state['rebuild'] && $form_state['process_input'] && !form_get_errors()) {
+    $form = drupal_rebuild_form($form_id, $form_state, $form_build_id);
+  }
 
   // As part of drupal_process_form(), the element that triggered the form
   // submission is determined, and in the case of AJAX, it might not be a
Index: modules/file/file.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/file/file.module,v
retrieving revision 1.23
diff -u -p -r1.23 file.module
--- modules/file/file.module	27 Mar 2010 05:52:49 -0000	1.23
+++ modules/file/file.module	29 Mar 2010 23:11:16 -0000
@@ -239,7 +239,9 @@ function file_ajax_upload() {
 
   // This call recreates the form relying solely on the form_state that the
   // drupal_process_form() set up.
-  $form = drupal_rebuild_form($form_id, $form_state, $form_build_id);
+  if ($form_state['rebuild'] && $form_state['process_input'] && !form_get_errors()) {
+    $form = drupal_rebuild_form($form_id, $form_state, $form_build_id);
+  }
 
   // Retrieve the element to be rendered.
   foreach ($form_parents as $parent) {
