Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gzip decompression quine

444 views
Skip to first unread message

Caspian Maclean

unread,
Jun 7, 2004, 1:05:19 AM6/7/04
to
Hi, there have been some discussions in the past
about whether it's possible to have a file in gzip

format or another compression format that

decompresses to itself. I've made one, the direct

link is:
http://www.beautiful-weddings.com/caspian/selfgz.gz

(The domain's for my mum's website) and there is
an index page with links to notes about it at:

http://caspian.arts-centre.net/

Treating gzip files as a programs that output the

result, here is the pseudocode with code addresses

and output addresses:

addr pseudocode output
000: begin
010: unc(15)
015: begin ;0
025: unc(15) ;10
030: nop10
040: copy(8,15),(7,15), unc(30) ;15,25
050: nop10 ;30
060: copy(8,15),(7,15), unc(30) ;40
070: nop10 ;50
080: nop10
090: nop10
100: copy(20,20),(10,10), unc(20) ;60,70,80
110: nop10 ;90
120: copy(20,20),(10,10), unc(20) ;100
130: copy(20,20),(10,10), unc(20) ;110,120,130
140: data-for-crc ;140
150: copy(5,10),(5,10), unc(20) ;150
160: copy(5,10),(5,10), unc(20) ;160
170: copy(10,20),(10,20), unc(0) ;170
180: end ;180
190: copy(10,20),(10,20), unc(0) ;190,200
200: end
210:

unc(n) is a header for n uncompressed bytes.

copy(length, dist) repeats "length" bytes from a

position starting "dist" bytes before the new
copy.

nop10 outputs nothing.
--
Caspian Maclean

Phil Carmody

unread,
Jun 7, 2004, 10:43:19 AM6/7/04
to
Caspian Maclean <cjm_u...@yahoo.co.nz> writes:

> Hi, there have been some discussions in the past
> about whether it's possible to have a file in gzip
> format or another compression format that
> decompresses to itself. I've made one,


bash-2.05b$ wget http://www.beautiful-weddings.com/caspian/selfgz.gz
bash-2.05b$ cp selfgz.gz selfgz2.gz
bash-2.05b$ gunzip selfgz2.gz
bash-2.05b$ cmp selfgz.gz selfgz2


Brilliant!

I tried and failed myself. I was hoping that an iterative approach
would work, a la Floyd, but it didn't.

Hearty congratulations!

Phil

--
1st bug in MS win2k source code found after 20 minutes: scanline.cpp
2nd and 3rd bug found after 10 more minutes: gethost.c
Both non-exploitable. (The 2nd/3rd ones might be, depending on the CRTL)

Matt Mahoney

unread,
Jun 7, 2004, 12:11:15 PM6/7/04
to

"Caspian Maclean" <cjm_u...@yahoo.co.nz> wrote in message
news:40c3...@news.orcon.net.nz...

> Hi, there have been some discussions in the past
> about whether it's possible to have a file in gzip
>
> format or another compression format that
>
> decompresses to itself. I've made one, the direct
>
> link is:
> http://www.beautiful-weddings.com/caspian/selfgz.gz

This is very clever. I like it. I've seen something similar done with a C
program that prints itself.

I wonder what the shortest such file is. An empty .gz file will
"uncompress" to itself but that doesn't really count since you get an error
message and the .gz extension isn't removed.

-- Matt Mahoney


Mark Adler

unread,
Jun 7, 2004, 1:05:22 PM6/7/04
to
Caspian Maclean <cjm_u...@yahoo.co.nz> wrote in message news:<40c3...@news.orcon.net.nz>...
> Hi, there have been some discussions in the past
> about whether it's possible to have a file in gzip
> format or another compression format that
> decompresses to itself. I've made one, the direct
> link is:
> http://www.beautiful-weddings.com/caspian/selfgz.gz

Most impressive! selfgz.gz is exactly what you say it is. I didn't
think it was possible. Good job.

mark

Severian

unread,
Jun 7, 2004, 11:30:32 PM6/7/04
to
On 7 Jun 2004 17:05:19 +1200, Caspian Maclean <cjm_u...@yahoo.co.nz>
wrote:

Kudos!

That is cool as all hell, and much more intellectually interesting
than the recent summer run of quacks.

--
Sev

Guenther von Knakspott

unread,
Jun 8, 2004, 2:07:01 PM6/8/04
to
Caspian Maclean <cjm_u...@yahoo.co.nz> wrote in message news:<40c3...@news.orcon.net.nz>...

Wow! Maclean rules.

Dirk Stoecker

unread,
Jun 9, 2004, 8:12:31 AM6/9/04
to
Hi,

> Hi, there have been some discussions in the past
> about whether it's possible to have a file in gzip
> format or another compression format that
> decompresses to itself. I've made one, the direct
> link is:
> http://www.beautiful-weddings.com/caspian/selfgz.gz

Nice piece of work!

Thought when we have this, can you make a second version, which includes
the filename. It seems some extractors require the extracted file to have
extension .gz to detect it as gzip again. This file could be a stress
tester for virus checkers then, as detection of these large gain 4GB files
is much easier than detection of your little beast. I will need updating
my Amiga virus checker as well ;-)

Ciao
--
____ _ _ ____ _ _ _ _ ____
| | | | | | \ / | | | the cool Gremlin from Bischofswerda
| __ | ____| | \/ | | | WWW: http://www.dstoecker.de/
| | | | | | | | PGP key available on www page.
|____| _|_ |____| _|_ _|_ |____| I hope AMIGA never stops making fun!

ntojzan

unread,
Jun 9, 2004, 5:01:28 PM6/9/04
to
Dirk Stoecker <ne...@dstoecker.de> wrote in message news:<Pine.LNX.4.58.04...@kgins2.geo.tu-dresden.de>...

> I will need updating
> my Amiga virus checker as well ;-)

Wow! Amiga? Is there still a community? (I gave up all the hope 3 years ago)

Re.

Caspian Maclean

unread,
Jun 11, 2004, 2:18:47 AM6/11/04
to
Dirk Stoecker <ne...@dstoecker.de> wrote in
news:Pine.LNX.4.58.04...@kgins2.geo.tu-dresden.de:

> Hi,

>> Hi, there have been some discussions in the past
>> about whether it's possible to have a file in gzip
>> format or another compression format that
>> decompresses to itself. I've made one, the direct
>> link is:
>> http://www.beautiful-weddings.com/caspian/selfgz.gz

> Nice piece of work!

Thanks to everyone for all the encouragement.

> Thought when we have this, can you make a second version, which
> includes the filename. It seems some extractors require the extracted
> file to have extension .gz to detect it as gzip again. This file could
> be a stress tester for virus checkers then, as detection of these
> large gain 4GB files is much easier than detection of your little
> beast. I will need updating my Amiga virus checker as well ;-)

Good idea, but I don't want to spend much time on it right away.
I might do that eventually if no one else does first. It's quite
simple in theory, but the helper programs I used were on a hard
disk that failed, and I haven't set up a new working linux system
to run them on yet. Solving the checksum by hand in particular
would be very tedious.

> Ciao

--
Caspian Maclean

Thomas Richter

unread,
Jun 11, 2004, 4:46:42 AM6/11/04
to
Hi,

> Wow! Amiga? Is there still a community? (I gave up all the hope 3 years ago)

Well, smaller than an epsilon that tends to zero. There are still some
die-hards like Dirk (that's not supposed to sound negative, Dirk.)
I personally gave up around two years ago when my system broke down.

So long,
Thomas

edmund.gri...@gmail.com

unread,
Jul 12, 2019, 4:09:11 AM7/12/19
to
The gzip quine described above, selfgz.gz, has 210 bytes. Here's a shorter one, with 112 bytes:

( echo H4sIAEMHJV0CA5Pv5mCIeLzKnIGZgYHh/38GEYbX/+WxiDl1 ;
echo KB5hIIJ1TXfrBNeU3DznNGYG78SS1AKgEchsAEthdGVwAAAA ) |
base64 -d | gunzip > quine.gz
zcat quine.gz | diff - quine.gz

There is probably an even shorter one.

There's a good discussion of the theory of LZ quines here: https://research.swtch.com/zip
0 new messages