diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el
index 6c7f755..c6eef01 100644
--- a/lisp/tar-mode.el
+++ b/lisp/tar-mode.el
@@ -531,25 +531,28 @@ defun tar-untar-buffer ()
   "Extract all archive members in the tar-file into the current directory."
   (interactive)
   ;; FIXME: make it work even if we're not in tar-mode.
-  (let ((descriptors tar-parse-info))   ;Read the var in its buffer.
-    (with-current-buffer
-        (if (tar-data-swapped-p) tar-data-buffer (current-buffer))
-      (set-buffer-multibyte nil)          ;Hopefully, a no-op.
-      (dolist (descriptor descriptors)
-        (let* ((name (tar-header-name descriptor))
-               (dir (if (eq (tar-header-link-type descriptor) 5)
-                        name
-                      (file-name-directory name)))
-               (start (tar-header-data-start descriptor))
-               (end (+ start (tar-header-size descriptor))))
-          (unless (file-directory-p name)
-            (message "Extracting %s" name)
-            (if (and dir (not (file-exists-p dir)))
-                (make-directory dir t))
-            (unless (file-directory-p name)
-	      (let ((coding-system-for-write 'no-conversion))
-		(write-region start end name)))
-            (set-file-modes name (tar-header-mode descriptor))))))))
+  (let ((data-buf (if (tar-data-swapped-p) tar-data-buffer (current-buffer))))
+    (with-current-buffer data-buf
+      (set-buffer-multibyte nil))       ; Hopefully, a no-op.
+    (dolist (descriptor tar-parse-info)
+      (let* ((name (tar-header-name descriptor))
+	     (dir (if (eq (tar-header-link-type descriptor) 5)
+		      name
+		    (file-name-directory name)))
+	     (start (tar-header-data-start descriptor))
+	     (end (+ start (tar-header-size descriptor))))
+	(unless (file-directory-p name)
+	  (message "Extracting %s" name)
+	  (if (and dir (not (file-exists-p dir)))
+	      (make-directory dir t))
+	  (unless (file-directory-p name)
+	    (let ((coding-system-for-write 'no-conversion)
+		  ;; Note that default-directory may have a different
+		  ;; value in the data buffer.
+		  (name (expand-file-name name default-directory)))
+	      (with-current-buffer data-buf
+		(write-region start end name))))
+	  (set-file-modes name (tar-header-mode descriptor)))))))
 
 (defun tar-summarize-buffer ()
   "Parse the contents of the tar file in the current buffer."
