* [PATCH] Fix cryptoapi deflate not handling PAGE_SIZE chunks.
@ 2005-07-18 3:26 Nigel Cunningham
2005-07-31 3:40 ` Herbert Xu
0 siblings, 1 reply; 4+ messages in thread
From: Nigel Cunningham @ 2005-07-18 3:26 UTC (permalink / raw)
To: Herbert Xu; +Cc: Linux Kernel Mailing List
Hi Herbert.
Here's a resend of a patch I'm using in Suspend2's new cryptoapi
support, which is needed for us to successfully compress pages using
deflate. It's along the lines of the existing fix in the decompression
code.
Regards,
Nigel
diff -ruNp 190-cryptoapi-deflate.patch-old/crypto/deflate.c 190-cryptoapi-deflate.patch-new/crypto/deflate.c
--- 190-cryptoapi-deflate.patch-old/crypto/deflate.c 2005-06-20 11:46:49.000000000 +1000
+++ 190-cryptoapi-deflate.patch-new/crypto/deflate.c 2005-07-04 23:14:20.000000000 +1000
@@ -143,8 +143,15 @@ static int deflate_compress(void *ctx, c
ret = zlib_deflate(stream, Z_FINISH);
if (ret != Z_STREAM_END) {
- ret = -EINVAL;
- goto out;
+ if (!(ret == Z_OK && !stream->avail_in && !stream->avail_out)) {
+ ret = -EINVAL;
+ goto out;
+ } else {
+ u8 zerostuff = 0;
+ stream->next_out = &zerostuff;
+ stream->avail_out = 1;
+ ret = zlib_deflate(stream, Z_FINISH);
+ }
}
ret = 0;
*dlen = stream->total_out;
--
Evolution.
Enumerate the requirements.
Consider the interdependencies.
Calculate the probabilities.
Be amazed that people believe it happened.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Fix cryptoapi deflate not handling PAGE_SIZE chunks.
2005-07-18 3:26 [PATCH] Fix cryptoapi deflate not handling PAGE_SIZE chunks Nigel Cunningham
@ 2005-07-31 3:40 ` Herbert Xu
2005-07-31 5:14 ` Nigel Cunningham
0 siblings, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2005-07-31 3:40 UTC (permalink / raw)
To: Nigel Cunningham; +Cc: Linux Kernel Mailing List
On Mon, Jul 18, 2005 at 01:26:35PM +1000, Nigel Cunningham wrote:
>
> Here's a resend of a patch I'm using in Suspend2's new cryptoapi
> support, which is needed for us to successfully compress pages using
> deflate. It's along the lines of the existing fix in the decompression
> code.
>
> diff -ruNp 190-cryptoapi-deflate.patch-old/crypto/deflate.c 190-cryptoapi-deflate.patch-new/crypto/deflate.c
> --- 190-cryptoapi-deflate.patch-old/crypto/deflate.c 2005-06-20 11:46:49.000000000 +1000
> +++ 190-cryptoapi-deflate.patch-new/crypto/deflate.c 2005-07-04 23:14:20.000000000 +1000
> @@ -143,8 +143,15 @@ static int deflate_compress(void *ctx, c
>
> ret = zlib_deflate(stream, Z_FINISH);
> if (ret != Z_STREAM_END) {
> - ret = -EINVAL;
> - goto out;
> + if (!(ret == Z_OK && !stream->avail_in && !stream->avail_out)) {
> + ret = -EINVAL;
> + goto out;
> + } else {
> + u8 zerostuff = 0;
> + stream->next_out = &zerostuff;
> + stream->avail_out = 1;
> + ret = zlib_deflate(stream, Z_FINISH);
> + }
> }
> ret = 0;
> *dlen = stream->total_out;
Hi Nigel, I need a bit more information about this patch.
Do you have a specific input stream that requires a fix like
this?
Thanks,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Fix cryptoapi deflate not handling PAGE_SIZE chunks.
2005-07-31 3:40 ` Herbert Xu
@ 2005-07-31 5:14 ` Nigel Cunningham
2005-07-31 5:49 ` Herbert Xu
0 siblings, 1 reply; 4+ messages in thread
From: Nigel Cunningham @ 2005-07-31 5:14 UTC (permalink / raw)
To: Herbert Xu; +Cc: Linux Kernel Mailing List
Hi.
On Sun, 2005-07-31 at 13:40, Herbert Xu wrote:
> On Mon, Jul 18, 2005 at 01:26:35PM +1000, Nigel Cunningham wrote:
> >
> > Here's a resend of a patch I'm using in Suspend2's new cryptoapi
> > support, which is needed for us to successfully compress pages using
> > deflate. It's along the lines of the existing fix in the decompression
> > code.
> >
> > diff -ruNp 190-cryptoapi-deflate.patch-old/crypto/deflate.c 190-cryptoapi-deflate.patch-new/crypto/deflate.c
> > --- 190-cryptoapi-deflate.patch-old/crypto/deflate.c 2005-06-20 11:46:49.000000000 +1000
> > +++ 190-cryptoapi-deflate.patch-new/crypto/deflate.c 2005-07-04 23:14:20.000000000 +1000
> > @@ -143,8 +143,15 @@ static int deflate_compress(void *ctx, c
> >
> > ret = zlib_deflate(stream, Z_FINISH);
> > if (ret != Z_STREAM_END) {
> > - ret = -EINVAL;
> > - goto out;
> > + if (!(ret == Z_OK && !stream->avail_in && !stream->avail_out)) {
> > + ret = -EINVAL;
> > + goto out;
> > + } else {
> > + u8 zerostuff = 0;
> > + stream->next_out = &zerostuff;
> > + stream->avail_out = 1;
> > + ret = zlib_deflate(stream, Z_FINISH);
> > + }
> > }
> > ret = 0;
> > *dlen = stream->total_out;
>
> Hi Nigel, I need a bit more information about this patch.
> Do you have a specific input stream that requires a fix like
> this?
Yes, Suspend2 if the user selects deflate as their compressor. The
output data will be PAGE_SIZE chunks, but deflate sometimes thinks it
has an extra byte to give us back.
I agree that it's ugly and don't recall using it when I had gzip support
in an earlier version of Suspend2. Are you thinking there might be a
better way? If so, I can dig out the old (non crypto api) code.
Regards,
Nigel
--
Evolution.
Enumerate the requirements.
Consider the interdependencies.
Calculate the probabilities.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Fix cryptoapi deflate not handling PAGE_SIZE chunks.
2005-07-31 5:14 ` Nigel Cunningham
@ 2005-07-31 5:49 ` Herbert Xu
0 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2005-07-31 5:49 UTC (permalink / raw)
To: Nigel Cunningham; +Cc: Linux Kernel Mailing List
On Sun, Jul 31, 2005 at 03:14:02PM +1000, Nigel Cunningham wrote:
>
> Yes, Suspend2 if the user selects deflate as their compressor. The
> output data will be PAGE_SIZE chunks, but deflate sometimes thinks it
> has an extra byte to give us back.
Are you saying that you're feeding it PAGE_SIZE chunks and it's
giving you back something bigger than a page? That is expected
since the nature of compression in general is that not everything
is compressible. Data streams which are not compressible will
end up bigger than what you start with.
What would be a bug is if you feed it something that's
deflateBound^-1(PAGE_SIZE) bytes long and it spits back
something that's longer than a page.
> I agree that it's ugly and don't recall using it when I had gzip support
> in an earlier version of Suspend2. Are you thinking there might be a
> better way? If so, I can dig out the old (non crypto api) code.
Well if you could give me a snippet of code that actually uses this
stuff to compress pages then I might have a better idea of what it's
trying to do.
Thanks,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-07-31 5:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-18 3:26 [PATCH] Fix cryptoapi deflate not handling PAGE_SIZE chunks Nigel Cunningham
2005-07-31 3:40 ` Herbert Xu
2005-07-31 5:14 ` Nigel Cunningham
2005-07-31 5:49 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox