🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #87188

Re: About compression with NNTP

#87188
From: Michael Baeuerle
Date: Wed, 11 Nov 2015 12:15
74 lines
4197 bytes
Julien ÉLIE wrote:
> Michael Bäuerle wrote:
> > 
> >  From the 'inflateInit2()' documentation in zlib.h:
> > |
> > | [...] windowBits must be greater than or equal to the windowBits value
> > | provided to deflateInit2() while compressing, or it must be equal to
> > | 15 if deflateInit2() was not used.  If a compressed stream with a
> > | larger window size is given as input, inflate() will return with the
> > | error code Z_DATA_ERROR instead of trying to allocate a larger window.
> > 
> > Looks like the "intended way" to handle this is to use the zlib
> > container with the window size field in its header.
> > Because we want to use the raw format, the decompressor should always
> > use the maximum window size (-15), or it would not be able to handle
> > data that was compressed with arbitrary window size.
> 
> So it appears that implementations MUST use (-15) for the window size 
> given to inflateInit2() in order to ensure interoperability.

Yes (if the window size is not negotiated).

The RFC draft for the COMPRESS extension specify in chapter 3:
| 
| The windowBits value must be in the range -8 to -15, or else
| deflateInit2() uses the wrong format.

I read this as it's explicitly intended to not use the zlib container
(that would provide a window size field in its header).

> Or should it be said that the window size MUST be the highest 
> available?  (in absolute value, because in fact we take the lowest:  
> -15)

From zlib.h:
| 
| The windowBits parameter is the base two logarithm of the window size
| [...]
| windowBits can also be -8..-15 for raw deflate.  In this case,
| -windowBits determines the window size.

The sign should therefore only indicate the format and for the raw
format the maximum window size should calculate as:

   log₂(window size) = -windowBits

   2⁻⁽⁻¹⁵⁾ = 32Ki

> The documentation says "It should be in the range 8..15 for this 
> version of the library" so the number may change in future versions of 
> zlib... which could break existing implementations!

Agreed.

> And what happens if someone uses an implementation of DEFLATE other 
> than zlib?  Will zlib always be able to decode their compressed stream?

Not if a window larger than 32KiByte is used. But it looks like that
the algorithm defined as "DEFLATE" in RFC1951 has an implicit 32KiByte
window limit. Quoted from chapter 2:
| 
| [...]
| the LZ77 algorithm may use a reference to a duplicated string
| occurring in a previous block, up to 32K input bytes before.
| [...]
| The representation used in the "deflate" format limits distances to
| 32K bytes
| [...]

Implementations that support/use larger window sizes seem to exist, but
they use different names like "DEFLATE64":
<http://deflate64.com/deflate64-vs-deflate-compression/>

Technical Details
Message-ID: <AABWQxKexa4AACik.A1.flnews@WStation3.stz-e.de>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.(19219).mbox.7z!not-for-mail
References: <mvjp3s$n0u$1@news.trigofacile.com> <AABWN95ofdEAABgy.A1.flnews@WStation1.micha.freeshell.org> <AABWPOnx3uEAABCC.A1.flnews@WStation3.stz-e.de> <n1l1h4$4bb$1@news.trigofacile.com> <AABWPjINJkIAAAOH.A1.flnews@WStation1.micha.freeshell.org> <n1r2o7$qoj$1@news.trigofacile.com> <AABWQiV44igAADh2.A1.flnews@WStation3.stz-e.de> <n1tjrv$m5q$1@news.trigofacile.com>

Show Full Headers
Complete Article Headers
Message-ID: <AABWQxKexa4AACik.A1.flnews@WStation3.stz-e.de>
Subject: Re: About compression with NNTP
Date: Wed, 11 Nov 2015 13:15:48 +0100
From: Michael Baeuerle <michael.baeuerle@stz-e.de>
References: <mvjp3s$n0u$1@news.trigofacile.com> <AABWN95ofdEAABgy.A1.flnews@WStation1.micha.freeshell.org> <AABWPOnx3uEAABCC.A1.flnews@WStation3.stz-e.de> <n1l1h4$4bb$1@news.trigofacile.com> <AABWPjINJkIAAAOH.A1.flnews@WStation1.micha.freeshell.org> <n1r2o7$qoj$1@news.trigofacile.com> <AABWQiV44igAADh2.A1.flnews@WStation3.stz-e.de> <n1tjrv$m5q$1@news.trigofacile.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.(19219).mbox.7z!not-for-mail
Newsgroups: news.software.nntp
Lines: 72
Reply-To: Michael Baeuerle <michael.baeuerle@gmx.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 51NkP9p23nJBdthobIub9Acpfbvv6Rv0GWQsGHFu5+lwWozuPZ
X-Orig-Path: not-for-mail
Cancel-Lock: sha1:j7LuP1lIckbTbkDwPXka67AGJB4= sha1:HSyW0PG/2xCgEc1k394qm++6IE8=
Injection-Date: Wed, 11 Nov 2015 12:15:48 -0000
User-Agent: flnews/0.12 (for GNU/Linux)
X-Received-Body-CRC: 4101203420
X-Received-Bytes: 4056