Search code examples
bashzipwindows-10catvisual-glitch

Is it safe to run cat command on a .zip file?


In bash, when I run cat on a .zip file, it outputs a bunch of symbols that scroll up the screen quickly. It also makes some beeping noises. This is both a little scary and awesome.

Is it safe for me to keep doing this? I kind of want to have this as a trick up my sleeve, so to speak. I want to wow my friends, family and future employers; and I know this trick is sure to impress.

Anyone know if there are any harmful effects from doing this?


Solution

  • It depends, what you consider safe. Some binary sequences are changing the behaviour of the terminal. Like, for example, size of scrolling window, colour, background colour, character set, etc. They can move cursor in other place, disable echo or make sound. However, all of those effects are easily revocable by using reset command.

    Some sequences may put some characters as you would be pressing some keys. For example, run under screen following command:

    printf "\033Z"
    

    It will display some garbage, then place a string of characters on input, immediately after bash prompt. For me it looks like:

    arturcz@szczaw:/tmp$ printf "\033Z"
    ^[[?1;2carturcz@szczaw:/tmp$ 1;2c
    

    If you press Enter key, bash will try to run this command:

    ^[[?1;2carturcz@szczaw:/tmp$ 1;2c
    bash: 1: command not found
    bash: 2c: command not found
    arturcz@szczaw:/tmp$ 
    

    I don't have neither 1 nor 2c command. But if you have them, they will be run. And it could be dangerous. The risk is not so big, but you shall be careful. So, if you decide to play with those glitches, remember to use backspace or ctrl-u to clean up the input line.

    BTW, you can prepare a file with control characters to draw a funny animation. For example, save following script to a file, let's say, script.sh:

    #!/bin/bash
    printf "\033[?25l"
    printf "\033[H\033[2J";
    for m in $(seq 1 100); do
        echo $m >&2
        for p in $(seq 20 -1 10); do
            for r in $(seq 0 1000); do
                printf "\033[${p};10H^o^"
            done
            printf "\033[${p};10H   "
        done
        for p in $(seq 10 20); do
            printf "\033[${p};10H^o^"
            for r in $(seq 0 1000); do
                printf "\033[${p};10H^o^"
            done
            printf "\033[${p};10H   "
        done
    done
    printf "\033[34h\033[?25h"
    

    then run it as:

    bash script.sh > anim.txt
    

    It could take a moment, but the script shows a percentage of work done. As you can see the content of anim.txt is not so much binary, however when you run it as:

    screen cat anim.txt
    

    you will see a simple animation. The screen command is required, as the script uses screen terminal control characters. Also, by using the screen the process of displaying will be slow down a little, what is especially important for a modern computers, as the animation would be displayed really, really fast.

    If you want to know more about those control sequences, read terminfo(5) manual and NCURSES Programming HOWTO.