linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lasse Collin <lasse.collin@tukaani.org>
To: Baoquan He <bhe@redhat.com>
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, alain@knaff.lu,
	phillip@lougher.demon.co.uk, akpm@linux-foundation.org,
	keescook@chromium.org, bp@alien8.de, vgoyal@redhat.com
Subject: Re: About support XZ-compressed kernel on x86
Date: Fri, 19 Feb 2016 22:19:00 +0200	[thread overview]
Message-ID: <20160219221900.24b73913@tukaani.org> (raw)
In-Reply-To: <20160218004817.GA2704@x1.redhat.com>

On 2016-02-18 Baoquan He wrote:
> OK. I still don't understand below snippet taken from misc.c. As you
> said overwriting happened when the write position quickly approaches
> the read position. how could it happpen if the input pointer is moving
> faster than the output pointer?
> 
> 
>  * The output pointer can only overrun the input pointer if the input
>  * pointer is moving faster than the output pointer.  A condition only
>  * triggered by data whose compressed form is larger than the
>  * uncompressed
>  * form.

That paragraph is confusing, I agree. Here is a slightly clearer
wording:

 * The output pointer can only overrun the input pointer if, at some
 * point in the decompression process, the input pointer is moving
 * faster than the output pointer.  This condition can only be
 * triggered by data whose compressed form is larger than the
 * uncompressed form.

I'm afraid it's still not good enough.

Example: Imagine a decompressor whose decompressor loop, on each
iteration, first reads exactly one input byte and then writes at least
one output byte, until all the data has been decompressed. In this case
the input pointer never moves faster than the output pointer (they can
move at the same speed though).

This kind of decompressor would need no safety margin for in-place
decompression: After reading the last input byte, the decompressor
would write one or more output bytes of which the last one would be at
the same position as the last input byte was. If the output pointer
overtook the input pointer at any point, the last input byte would make
the decompressor write past the end of the buffer. That is, the output
pointer overtaking the input pointer would be a clear sign that the
input file is corrupt: Since the input pointer cannot move faster than
the output pointer, the input pointer cannot catch up with the output
pointer so that the last output byte wouldn't be written past the end
of the buffer.

I hope the above example is clear enough; I'm not able to word it
better right now. I don't recommend putting the above example in
misc.c, but maybe the example helps in figuring out a better wording
for the existing text in misc.c.

In most decompressors, the input pointer moves faster than the output
pointer in certain common situations (like file format headers), thus
some decompressor-specific safety margin is needed.

-- 
Lasse Collin  |  IRC: Larhzu @ IRCnet & Freenode

      reply	other threads:[~2016-02-19 20:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-12 15:34 About support XZ-compressed kernel on x86 Baoquan He
2016-02-12 15:41 ` Baoquan He
2016-02-13 18:57 ` Lasse Collin
2016-02-14 13:31   ` Baoquan He
2016-02-15 20:26     ` Lasse Collin
2016-02-16 13:20       ` Baoquan He
2016-02-17 17:57         ` Lasse Collin
2016-02-18  0:48           ` Baoquan He
2016-02-19 20:19             ` Lasse Collin [this message]

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=20160219221900.24b73913@tukaani.org \
    --to=lasse.collin@tukaani.org \
    --cc=akpm@linux-foundation.org \
    --cc=alain@knaff.lu \
    --cc=bhe@redhat.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillip@lougher.demon.co.uk \
    --cc=vgoyal@redhat.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;
as well as URLs for NNTP newsgroup(s).