How to destroy your OS with tar
vorakl.com
vorakl.com
Like when I have an electrician at me house. Says the old way was dumb... but that was fully up to code in 1954.
Time makes fools of us all.
On that point, some heavy machinery took years before adding safety guards (some even required legislation before improving safety)
... AFTER a "tvf[jzx]", I hope
Does -x have some side effect that -t would list for you?
Most tar programs do prevent extracting tarballs containing absolute paths (like '/etc/passwd') and relative paths (like '../../../etc/passwd'), but older tar programs still allow that. And programs written in Go, because of course: https://github.com/golang/go/issues/55356
Overall, if your HDD size is infinite and you're using GNU tar, or another recent tar, you can skip 't' I think before doing a '-C' extraction into some safe directory.
To add absolute paths to an archive, there is "-P" option, and man says it works only for creating archives: "Don't strip leading slashes from filenames when creating archives".
To extract absolute paths from the archive, you need to add the "-C /" option, and although the tool says "tar: Strip leading `/' from member names", it will still extract it in the right place because the paths become relative and -C puts them in the root.
However, if you add "-P" during the extraction (which is not mentioned in man), the "strip leading slashes" information disappears.
So if this message bothers someone, "tar -C / -xPf file.tar" will cleanly extract absolute paths from the archive ;)
char name[100];
(See https://man.archlinux.org/man/tar.5.en )So anything that will write an absolute path there, including literally opening it in a text editor and replacing the path by hand because that whole header is just fixed length ASCII with null terminated strings.
(I mean I assume the tar(1) command can do it too but you don't need that, the format is dead simple, if weird.)
curl ... | sudo bash
might have pitfalls? Gasp.I personally avoid software whose manual suggests this type of install because I think of the developers as not that intelligent ones.
Maintaining that kind of monstruosity of shell scripts that have to work on all kind of OS or linux distros must be a giant PITA compared to the simplicity of making an appimage/flatpak and a set of deb/rpm packages for the most popular distros and clear instructions for port maintainers to do the same for archlinux and BSD systems.
This is far, far less complex than having to maintain and distribute an entire bundled runtime environment, deal with inconsistent behavior with the local config, etc. Flatpak and AppImage have their use cases, but by no means are they simpler than just putting binaries in the right places -- they are in fact an entire additional layer of complexity.
https://docs.waydro.id/usage/install-on-desktops (see Ubuntu section)
Instead, you shoud wget, review and execute locally or something similar.
So I assume that you also never do that - and the downloaded installer is even worse, because you can't easily look inside the executable to determine what it does.
Shocking news : Installing software installs the software.
But cpio existed when I first used Unix in 1982/3
With pax, the `-k` option will not overwrite existing files. Also not using `-p o` or `-p e` will not preserve rights. I don't know why you would extract and preserve rights to extract binaries in a chroot, usually you would want to control the permissions instead.
[1] pax is the recommended archive utility in the POSIX shell&utilities section while tar and cpio aren't mentionned.
Tar can do all the same things, it just requires options either on the archiving or extraction end.
I got in and out of it a few times to make sure what I was going to do, then I launched it again (but I didn't add any arguments).
Not only didn't it complain, it defaulted to my root disk, and I ended up destroying my partition table.
Luckily the system was still running and I was able to backup everything before I shut the system down.
https://docs.voidlinux.org/installation/guides/chroot.html#t...
bwrap --bind $HOME/void_chroot/ / --ro-bind /etc/resolv.conf /etc/resolv.conf --rw-bind /home/ /home/ --proc /proc --dev /dev /bin/sh
Instead of xchroot, use bwrap.I wish I knew this before taking a backup and reformatting.
Always test your backups I guess..
I'm asking this because I was trying to reproduce the same situation and everything seems to be working fine:
$ tar -C /tmp/root3 -cvf test.tar .
./
./.config/
./.config/test
./.local/
./var/
./var/db/
./var/db/xbps/
or even like this $ tar -cvf test2.tar root3/
root3/
root3/.config/
root3/.config/test
root3/.local/
root3/var/
root3/var/db/
root3/var/db/xbps/
No special options were needed. But, if I do it this way, then, there are definitely missing all dot directories: $ tar -cvf test2.tar root3/*
root3/usr/
root3/usr/bin/
root3/usr/bin/xbps-uunshare
But this problem is not a tar's problem. That's only because "*" mask doesn't match dot files: $ echo root3/*
root3/usr root3/var
For that purpose, you need to clearly add a dot: $ echo root3/.*
root3/.config root3/.local
Thus, the solution might be $ tar -cvf test2.tar root3/.* root3/*
root3/.config/
root3/.config/test
root3/.local/
root3/usr/
root3/usr/bin/
But, I'd rather stick to "-C dir/" option instead of relying on "*" mask in this case. tar -cvf mytar.tar /home/myuser/*
Was definitely the syntax I ran. I'm on FreeBSD so just tar. If a filename begins with a <period> ( '.' ), the <period> shall be explicitly
matched by using a <period> as the first character of the pattern or immediately
following a <slash> character. The leading <period> shall not be matched by:
* The <asterisk> or <question-mark> special characters
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...Interesting fact about the FreeBSD tar's origins:
GNU tar was included as the standard system tar in
FreeBSD beginning with FreeBSD 1.0.
This is a complete re-implementation based
on the libarchive(3) library. It was first released with
FreeBSD 5.4 in May, 2005.
https://man.freebsd.org/cgi/man.cgi?query=tarMy personal journey with FreeBSD began with version 5.3 (the first stable release on the 5th branch) in November 2004. I was completely unaware of such a significant tar change, and apparently I didn't care at the time. However, the entire 5th branch has been so revolutionary compared to the 4th branch that this change is just a drop in the bucket ;)
I'd still extract to a local folder as nonroot, though, so still the right conclusion.
This is a really good point! It solves the main problem. I'll add it to the article.
Although that's what, unfortunately, is set by default (at least in GNU tar):
--overwrite-dir (Overwrite metadata of existing directories when extracting (default).)
Don't take this the wrong way. Nice write up. :)
......
Sudo ... why would you sudo a command that you don't understand?
RTFM ... all of the behaviour you experienced is well documented. There are no surprises.
POSIX and UNIX utils are flexible and powerful. This is why we love them. Don't blame the hammer.
Sandbox anything you extract and review it. Extract in a test environment. Extract without sudo and copy the files and permissions you need.
tar -tv is simply tests the archive and outputs the paths. You ignored what it told you - that it would overwrite ./ :)
#### Never ever do this! $ sudo tar -C / -xvfp xbps-static-latest.x86_64-musl.tar.xz
Insanity.
Cheers :)