#25 doesn't wait for gzip/bzip child

Production/Stable
open
nobody
5
2012-09-14
2007-04-23
Egmont Koblinger
No

When decrypting and decompressing data, the main mcrypt process launches gzip or bzip2 to decompress the decrypted stream, but doesn't wait for this child to finish.

Example:

Create a 100MB file of zeros:
dd if=/dev/zero of=zeros bs=1048576 count=100

Compress it with bzip2 and encrypt:
mcrypt -p -k somekey <zeros>encrypted

Now decompress it, and test the output file after mcrypt has exited. Use this command:
mcrypt -d -p -k somekey <encrypted>restored; ls -l restored; sleep 1; ls -l restored; sleep 1; ls -l restored

You'll get an output similar to this one:
Stdin was decrypted.
-rw-r--r-- 1 egmont users 0 2007-04-23 19:00 restored
-rw-r--r-- 1 egmont users 83931136 2007-04-23 19:00 restored
-rw-r--r-- 1 egmont users 104857600 2007-04-23 19:00 restored

As seen, when mcrypt exits, the output file is still empty, and it is filled up later.

This makes it impossible to be used in shell scripts where the resulting file is processed further, e.g. copied to a remote machine...

Discussion