Tar Error: Unexpected Eof in Archive

Tar error: Unexpected EOF in archive

Interesting. I have a few questions which may point out the problem.

1/ Are you untarring on the same platform as you're tarring on? They may be different versions of tar (e.g., GNU and old-unix)? If they're different, can you untar on the same box you tarred on?

2/ What happens when you simply gunzip myarchive.tar.gz? Does that work? Maybe your file is being corrupted/truncated. I'm assuming you would notice if the compression generated errors, yes?

Based on the GNU tar source, it will only print that message if find_next_block() returns 0 prematurely which is usually caused by truncated archive.

Docker ERROR: Error processing tar file(exit status 1): unexpected EOF

There is an built in command to remove unused images (Version 1.13+):

docker image prune

Now to handle the situation:

  • Stop Docker Service

    systemctl stop docker
  • Backup /var/lib/docker then:

  • Remove /var/lib/docker
    Caution: This will remove images, containers, volumes, ... make sure you back it up first.

    rm -rf /var/lib/docker
  • Start Docker service

    systemctl start docker  

Update:

As noted in the other answer, In somecases it might be file permissions issue. Please review permissions.

tar.extractall() does not recognize unexpected EOF

I wrote a work around. It works with my tar files. I guess it supports not all types of objects which can be stored in a tar file.

# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, unicode_literals, print_function
import os
import tarfile

class TarfileWhichRaisesOnEOF(tarfile.TarFile):
def extractall(self, path=".", members=None):
super(TarfileWhichRaisesOnEOF, self).extractall(path, members)
if members is None:
members = self

for tarinfo in members:
if not tarinfo.isfile():
continue
file=os.path.join(path, tarinfo.name)
size_real=os.path.getsize(file)
if size_real!=tarinfo.size:
raise tarfile.ExtractError('Extracting %s: Size does not match. According to tarinfo %s and on disk %s' % (
tarinfo, tarinfo.size, size_real))

why I got unexpected EOF Error file creating react native app

In your code, add something where you check for the EOF and then skip over it so it doesn't give you an error. This sort of thing happened in some of my code once too.

docker load - unexpected EOF

It turned out that the image upload was not successful, and the file was cut short, so it literally had an unexpected EOF. (duh)

Using md5sum or ls to compare the files would have helped me spot this error much sooner.

Shoutout to this google result which stated the same.

How can I check if .tar (not tar.gz) file is corrupt or not, in Ubuntu?

When asking a question regarding Linux, try to state the distro you are encountering the error on. It might help others better understand the problem and in turn, to help you better.

OK, now into the answer.

You can use 7zip to easily test whether an archive is corrupted or not. If 7zip, which is distributed via the p7zip package isn't already installed, install it with one of the following commands matching your Linux distribution.

Ubuntu: sudo apt install p7zip

Fedora/Cent OS/RHEL: sudo yum install p7zip

Arch/Manjaro: sudo pacman -S p7zip

To check whether it's been successfully installed, run 7z. You should see an output similar to this:

7-Zip [64] 17.03 : Copyright (c) 1999-2020 Igor Pavlov : 2017-08-28
p7zip Version 17.03 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,4 CPUs x64)

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]

<Commands>
a : Add files to archive
b : Benchmark
d : Delete files from archive
e : Extract files from archive (without using directory names)
h : Calculate hash values for files
i : Show information about supported formats
l : List contents of archive
rn : Rename files in archive
t : Test integrity of archive
u : Update files to archive
x : eXtract files with full paths

<Switches>
-- : Stop switches parsing
@listfile : set path to listfile that contains file names
-ai[r[-|0]]{@listfile|!wildcard} : Include archives
-ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
-ao{a|s|t|u} : set Overwrite mode
-an : disable archive_name field
-bb[0-3] : set output log level
-bd : disable progress indicator
-bs{o|e|p}{0|1|2} : set output stream for output/error/progress line
-bt : show execution time statistics
-i[r[-|0]]{@listfile|!wildcard} : Include filenames
-m{Parameters} : set compression Method
-mmt[N] : set number of CPU threads
-mx[N] : set compression level: -mx1 (fastest) ... -mx9 (ultra)
-o{Directory} : set Output directory
-p{Password} : set Password
-r[-|0] : Recurse subdirectories
-sa{a|e|s} : set Archive name mode
-scc{UTF-8|WIN|DOS} : set charset for for console input/output
-scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files
-scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands
-sdel : delete files after compression
-seml[.] : send archive by email
-sfx[{name}] : Create SFX archive
-si[{name}] : read data from stdin
-slp : set Large Pages mode
-slt : show technical information for l (List) command
-snh : store hard links as links
-snl : store symbolic links as links
-sni : store NT security information
-sns[-] : store NTFS alternate streams
-so : write data to stdout
-spd : disable wildcard matching for file names
-spe : eliminate duplication of root folder for extract command
-spf : use fully qualified file paths
-ssc[-] : set sensitive case mode
-ssw : compress shared files
-stl : set archive timestamp from the most recently modified file
-stm{HexMask} : set CPU thread affinity mask (hexadecimal number)
-stx{Type} : exclude archive type
-t{Type} : Set type of archive
-u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options
-v{Size}[b|k|m|g] : Create volumes
-w[{path}] : assign Work directory. Empty path means a temporary directory
-x[r[-|0]]{@listfile|!wildcard} : eXclude filenames
-y : assume Yes on all queries

Now, as you can see, you can run the following command to test if a particular archive is corrupted or not. Replace archive_name with the filename of .tar file you want to test.

7z t archive_name.tar

In my case, an archive, test.tar contains 2 files and is healthy. And following is the output I received.

7-Zip [64] 17.03 : Copyright (c) 1999-2020 Igor Pavlov : 2017-08-28
p7zip Version 17.03 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,4 CPUs x64)

Scanning the drive for archives:
1 file, 10240 bytes (10 KiB)

Testing archive: test.tar
--
Path = test.tar
Type = tar
Physical Size = 10240
Headers Size = 2048
Code Page = UTF-8

Everything is Ok

Files: 2
Size: 7980
Compressed: 10240

You can see that "Everything is Ok" has been outputted, which means the archive is healthy.


Now I've intentionally made that same archive corrupt. Let's see what 7z t test.tar outputs now.

7-Zip [64] 17.03 : Copyright (c) 1999-2020 Igor Pavlov : 2017-08-28
p7zip Version 17.03 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,4 CPUs x64)

Scanning the drive for archives:
1 file, 10224 bytes (10 KiB)

Testing archive: test1.tar
ERROR: test1.tar
test1.tar
Open ERROR: Can not open the file as [tar] archive

ERRORS:
Is not archive

Can't open as archive: 1
Files: 0
Size: 0
Compressed: 0

You can see that it outputs various messages like "Can not open the file as [tar] archive." and "Is not archive". You might get similar or same messages if your archive is corrupted.



Related Topics



Leave a reply



Submit