From: Daniel Hazelton <dhazelton@enter.net>
To: Mark Adler <madler@alumni.caltech.edu>
Cc: Satyam Sharma <satyam.sharma@gmail.com>,
"Michael-Luke Jones" <mlj28@cam.ac.uk>,
lkml <linux-kernel@vger.kernel.org>,
dwmw2@infradead.org, jloup@gzip.org
Subject: Re: JFFS2 using 'private' zlib header (was [RFC] LZO de/compression support - take 6)
Date: Wed, 30 May 2007 19:26:25 -0400 [thread overview]
Message-ID: <200705301926.25546.dhazelton@enter.net> (raw)
In-Reply-To: <1084DBE5-D72F-4403-B231-66DA8FE6AC73@alumni.caltech.edu>
On Wednesday 30 May 2007 19:02:28 Mark Adler wrote:
> On May 30, 2007, at 6:30 AM, Satyam Sharma wrote:
> > [1] For your reference, here is the user code in question:
>
> ...
>
> > if (srclen > 2 && !(data_in[1] & PRESET_DICT) &&
> > ((data_in[0] & 0x0f) == Z_DEFLATED) &&
> > !(((data_in[0]<<8) + data_in[1]) % 31)) {
>
> The funny thing here is that the author felt compelled to use a
> #defined constant for the dictionary bit (PRESET_DICT), but had no
> problem with a numeric constant to isolate the compression method
> (0x0f), or for that matter extracting the window bits from the
> header. The easy way to avoid the use of an internal zlib header
> file here is to simply replace PRESET_DICT with 0x20. That constant
> will never change -- it is part of the definition of the zlib header
> in RFC 1950.
That was one of my original suggestions, though I personally downchecked it
(and believe I also did so in the mail with the suggestions) because of the
dislike of "Magic Numbers" in the kernel. However, I had only looked at a
small part of the JFFS2 code to see what it used zutil.h for - if it is using
said 'Magic Numbers' in the rest of the code, the consistent way to fix this
would be to replace the PRESET_DICT macro with the constant it stands for.
I've gotten a bit caught-up in extending the test-bed code I used to benchmark
Nitin's 'tinyLZO' implementation, but I will see about getting a patch
together to change JFFS2 in the manner Mark suggests. (Unless, of course,
someone gets to it before I do).
DRH
>
> The slightly more involved patch to avoid the problem is to let
> inflate() do all that work for you, including the integrity check on
> the zlib header (% 31). Also this corrects an error in the original
> code, which is that it continues to try to decompress after finding
> that a dictionary is needed or that the zlib header is invalid. In
> this version, a bad header simply returns an error:
>
> /* provide input data and output space */
> inf_strm.next_in = data_in;
> inf_strm.avail_in = srclen;
> inf_strm.next_out = cpage_out;
> inf_strm.avail_out = destlen;
>
> /* verify and skip zlib header (this updates next_in and
> avail_in) */
> inf_strm.zalloc = Z_NULL;
> inf_strm.zfree = Z_NULL;
> inf_strm.opaque = Z_NULL;
> if (zlib_inflateInit(&inf_strm) != Z_OK) {
> printk(KERN_WARNING "inflateInit failed\n");
> return 1;
> }
> ret = zlib_inflate(&inf_strm, Z_BLOCK);
> if (ret != Z_OK || (inf_strm.data_type & 0x80) == 0) {
> printk(KERN_WARNING "inflate failed on zlib header\n");
> return 1;
> }
> zlib_inflateEnd(&inf_strm);
>
> /* do raw inflate (no adler32) on deflate data after zlib header */
> inf_strm.zalloc = Z_NULL;
> inf_strm.zfree = Z_NULL;
> inf_strm.opaque = Z_NULL;
> if (zlib_inflateInit2(&inf_strm, -MAX_WBITS) != Z_OK) {
> printk(KERN_WARNING "inflateInit failed\n");
> return 1;
> }
> while ((ret = zlib_inflate ...
>
> Mark
next prev parent reply other threads:[~2007-05-30 23:26 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-28 14:34 [RFC] LZO de/compression support - take 6 Nitin Gupta
2007-05-28 14:40 ` Nitin Gupta
2007-05-28 14:49 ` Daniel Hazelton
2007-05-28 15:06 ` Nitin Gupta
2007-05-28 15:43 ` Adrian Bunk
2007-05-28 16:03 ` Nitin Gupta
2007-05-28 17:11 ` Adrian Bunk
2007-05-28 19:59 ` Daniel Hazelton
2007-05-28 20:18 ` Daniel Hazelton
2007-05-28 20:52 ` Daniel Hazelton
2007-05-29 5:55 ` Nitin Gupta
2007-05-29 8:08 ` Michael-Luke Jones
2007-05-29 11:40 ` Adrian Bunk
2007-05-29 12:03 ` Nitin Gupta
2007-05-29 13:13 ` Daniel Hazelton
2007-05-29 21:10 ` Jan Engelhardt
2007-05-29 21:26 ` Adrian Bunk
2007-05-30 5:31 ` Nitin Gupta
2007-05-30 13:56 ` Johannes Stezenbach
2007-05-30 14:24 ` Satyam Sharma
2007-05-28 15:30 ` Adrian Bunk
2007-05-28 15:47 ` Nitin Gupta
2007-05-28 15:55 ` Daniel Hazelton
2007-05-28 17:01 ` Adrian Bunk
2007-05-28 19:51 ` Daniel Hazelton
2007-05-28 15:49 ` Daniel Hazelton
2007-05-28 22:57 ` Bret Towe
2007-05-29 5:48 ` Nitin Gupta
2007-05-29 13:09 ` Daniel Hazelton
2007-05-28 22:53 ` Bret Towe
2007-05-28 22:58 ` Bret Towe
2007-05-29 5:58 ` Nitin Gupta
2007-05-29 20:14 ` Daniel Hazelton
2007-05-29 20:33 ` Daniel Hazelton
2007-05-29 21:48 ` Daniel Hazelton
2007-05-29 23:32 ` Daniel Hazelton
2007-05-30 5:19 ` Nitin Gupta
2007-05-29 8:17 ` Makefile question (was [RFC] LZO de/compression support - take 6) Michael-Luke Jones
2007-05-29 10:41 ` Satyam Sharma
2007-05-29 10:51 ` Michael-Luke Jones
2007-05-29 11:27 ` Satyam Sharma
2007-05-29 13:33 ` JFFS2 using 'private' zlib header " Michael-Luke Jones
2007-05-29 13:43 ` Daniel Hazelton
2007-05-29 15:15 ` Satyam Sharma
2007-05-29 16:20 ` Daniel Hazelton
2007-05-30 5:31 ` Mark Adler
2007-05-30 13:05 ` Daniel Hazelton
2007-05-30 13:30 ` Satyam Sharma
2007-05-30 23:02 ` Mark Adler
2007-05-30 23:26 ` Daniel Hazelton [this message]
2007-06-01 3:06 ` Daniel Hazelton
2007-06-01 17:24 ` Satyam Sharma
2007-05-30 13:41 ` Artem Bityutskiy
2007-05-30 15:46 ` Artem Bityutskiy
2007-05-30 16:12 ` Satyam Sharma
2007-05-30 16:43 ` Artem Bityutskiy
2007-05-29 20:48 ` [RFC] LZO de/compression support - take 6 Jan Engelhardt
2007-05-30 5:54 ` Nitin Gupta
2007-05-30 8:31 ` Jan Engelhardt
2007-05-30 10:47 ` Nitin Gupta
2007-05-31 12:34 ` Nitin Gupta
2007-05-31 18:21 ` Satyam Sharma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200705301926.25546.dhazelton@enter.net \
--to=dhazelton@enter.net \
--cc=dwmw2@infradead.org \
--cc=jloup@gzip.org \
--cc=linux-kernel@vger.kernel.org \
--cc=madler@alumni.caltech.edu \
--cc=mlj28@cam.ac.uk \
--cc=satyam.sharma@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox