Git development
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>, zlib@gzip.org
Cc: Mark Brown <broonie@sirena.org.uk>, Jeff King <peff@peff.net>,
	Junio C Hamano <gitster@pobox.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: Valgrind updates
Date: Tue, 27 Jan 2009 10:55:40 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.00.0901271006060.3123@localhost.localdomain> (raw)
In-Reply-To: <alpine.DEB.1.00.0901271742430.3586@pacific.mpi-cbg.de>



On Tue, 27 Jan 2009, Johannes Schindelin wrote:
> 
> Come to think of it, the word "suppression" is probably a good indicator 
> that valgrind never claimed it would mark the zlib buffer as properly 
> initialized.

Hmm. The zlib faq has a note about zlib doing a conditional on 
uninitialized memory that doesn't matter, and that is what the suppression 
should be about (to avoid a warning about "Conditional jump or move 
depends on uninitialised value").

But that one is documented to not matter for the actual output (zlib 
FAQ#36).

It's possible that zlib really does leave padding bytes around that 
literally don't matter, and that don't get initialized. That really would 
be bad, because it means that the output of git wouldn't be repeatable. 
But I doubt this is the case - original git used to actually do the SHA1 
over the _compressed_ data, which was admittedly a totally and utterly 
broken design (and we fixed it), but it did work. Maybe it worked by luck, 
but I somehow doubt it.

Some googling did find this:

	http://mailman.few.vu.nl/pipermail/sysprog/2008-October/000298.html

which looks very similar: an uninitialized byte in the middle of a 
deflate() packet.

Anyway, I'm just going to Cc 'zlib@gzip.org', since this definitely is 
_not_ the same issue as in the FAQ, and we're not the only ones seeing it. 
For the zlib people: the code is literally this:

        /* Set it up */
        memset(&stream, 0, sizeof(stream));
        deflateInit(&stream, zlib_compression_level);
        size = 8 + deflateBound(&stream, len+hdrlen);
        compressed = xmalloc(size);

        /* Compress it */
        stream.next_out = compressed;
        stream.avail_out = size;

        /* First header.. */
        stream.next_in = (unsigned char *)hdr;
        stream.avail_in = hdrlen;
        while (deflate(&stream, 0) == Z_OK)
                /* nothing */;

        /* Then the data itself.. */
        stream.next_in = buf;
        stream.avail_in = len;
        ret = deflate(&stream, Z_FINISH);
        if (ret != Z_STREAM_END)
                die("unable to deflate new object %s (%d)", sha1_to_hex(sha1), ret);

        ret = deflateEnd(&stream);
        if (ret != Z_OK)
                die("deflateEnd on object %s failed (%d)", sha1_to_hex(sha1), ret);

        size = stream.total_out;

        if (write_buffer(fd, compressed, size) < 0)
                die("unable to write sha1 file");

and valgrind complains that the "write_buffer()" call will touch an 
uninitialized byte (just one byte, and in the _middle_ of the buffer, no 
less):

> Yet, the buffer in question is 195 bytes, stream.total_count (which 
> totally agrees with size - stream.avail_out) says it is 58 bytes, and 
> valgrind says that the byte with offset 51 is uninitialized.

The thing to note here is that what we are passing in to "write_buffer()" 
is _exactly_ what zlib deflated for us:

 - 'compressed' is the allocation, and is what we used to initialize 
   'stream.next_out' with (at the top of the code sequence above)

 - 'size' is gotten from 'stream.total_out' at the end of the compression.

Maybe the zlib people can tell us that we're idiots and the above is 
buggy, but maybe there is a real bug in zlib. Maybe it's triggered by our 
use of using two different input buffers to deflate() (ie we compress the 
header first, and then the body of the actual data, and put it all in one 
single output buffer), which may be unusual usage of zlib routines and may 
be why there aren't tons of reports of this.

(Our use of just depending on deflate() returning Z_BUF_ERROR after 
consuming all of the header data is probably also "unusual", but the 
manual explicitly says that it's not fatal and that deflate can be called 
again with more buffers).

Oh Gods of zlib, please hear our plea for clarification..

			Linus

  reply	other threads:[~2009-01-27 18:58 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-19  9:13 What's cooking in git.git (Jan 2009, #04; Mon, 19) Junio C Hamano
2009-01-19 11:54 ` Kjetil Barvik
2009-01-19 13:09   ` Johannes Schindelin
2009-01-19 13:08 ` Johannes Schindelin
2009-01-20  4:44   ` Jeff King
2009-01-20 13:51     ` valgrind patches, was " Johannes Schindelin
2009-01-20 14:19       ` Jeff King
2009-01-20 14:50         ` Johannes Schindelin
2009-01-20 15:04           ` [PATCH 1/2] Add valgrind support in test scripts Johannes Schindelin
2009-01-20 15:05             ` [PATCH 2/2] valgrind: ignore ldso errors Johannes Schindelin
2009-01-21  0:12             ` [PATCH 1/2] Add valgrind support in test scripts Jeff King
2009-01-21  0:41               ` Johannes Schindelin
2009-01-21  1:10               ` [PATCH 1/2 v2] " Johannes Schindelin
2009-01-21  1:11                 ` [INTERDIFF of PATCH " Johannes Schindelin
2009-01-21  8:48                 ` [PATCH " Junio C Hamano
2009-01-21 12:21                   ` Johannes Schindelin
2009-01-21 19:02                 ` Jeff King
2009-01-21 20:49                   ` Johannes Schindelin
2009-01-21 21:53                     ` Jeff King
2009-01-21 22:38                       ` Johannes Schindelin
2009-01-25 23:18                         ` [PATCH 0/3] Valgrind support Johannes Schindelin
2009-01-25 23:18                           ` [PATCH v3 1/3] Add valgrind support in test scripts Johannes Schindelin
2009-01-25 23:29                             ` Jeff King
2009-01-25 23:35                               ` Johannes Schindelin
2009-01-25 23:42                                 ` Jeff King
2009-01-25 23:19                           ` [PATCH v3 2/3] valgrind: ignore ldso and more libz errors Johannes Schindelin
2009-01-25 23:32                             ` Jeff King
2009-01-26  0:02                               ` Johannes Schindelin
2009-01-26  0:14                                 ` Jeff King
2009-01-25 23:20                           ` [PATCH 3/3] Valgrind support: check for more than just programming errors Johannes Schindelin
2009-01-25 23:42                             ` Jeff King
2009-01-26  0:43                               ` Johannes Schindelin
2009-01-21 22:31                     ` [PATCH] valgrind tests: be super-super paranoid when creating symlinks Johannes Schindelin
2009-01-20 23:24           ` valgrind patches, was Re: What's cooking in git.git (Jan 2009, #04; Mon, 19) Jeff King
2009-01-21  0:10             ` Johannes Schindelin
2009-01-21  0:15               ` Jeff King
2009-01-21  0:28                 ` Johannes Schindelin
2009-01-21  0:37                   ` Jeff King
2009-01-21  1:26                     ` Johannes Schindelin
2009-01-21  1:36                       ` [PATCH 2/2 v2] valgrind: ignore ldso errors Johannes Schindelin
2009-01-21 19:09                         ` Jeff King
2009-01-21 20:51                           ` Johannes Schindelin
2009-01-21 19:07                       ` valgrind patches, was Re: What's cooking in git.git (Jan 2009, #04; Mon, 19) Jeff King
2009-01-21 22:17                         ` Johannes Schindelin
2009-01-21 23:57                           ` Jeff King
2009-01-22  0:42                           ` Junio C Hamano
2009-01-22  0:59                             ` Jeff King
2009-01-22  5:02                               ` Johannes Schindelin
2009-01-22  5:39                                 ` Jeff King
2009-01-27  2:50                           ` Valgrind updates Johannes Schindelin
2009-01-27  3:38                             ` Linus Torvalds
2009-01-27  4:26                               ` Johannes Schindelin
2009-01-27  4:46                                 ` Johannes Schindelin
2009-01-27 13:14                                 ` Mark Brown
2009-01-27 16:54                                   ` Johannes Schindelin
2009-01-27 18:55                                     ` Linus Torvalds [this message]
2009-01-27 21:52                                       ` Johannes Schindelin
2009-01-29  1:56                                         ` Linus Torvalds
2009-01-29 14:22                                           ` Johannes Schindelin
2009-01-28 23:06                                       ` Mark Adler
2009-01-28 23:27                                         ` Johannes Schindelin
2009-01-29  0:15                                           ` Mark Adler
2009-01-29 14:14                                             ` Johannes Schindelin
2009-01-29 14:54                                               ` Johannes Schindelin
2009-01-27  4:48                               ` Jeff King
2009-01-27  9:31                                 ` Johannes Schindelin
2009-01-20  4:30 ` What's cooking in git.git (Jan 2009, #04; Mon, 19) Jeff King
2009-01-20  4:40 ` Jeff King
2009-01-20  7:04   ` Junio C Hamano
2009-01-20  7:55   ` Johannes Sixt
2009-01-20 14:18     ` Jeff King
2009-01-20  5:17 ` Boyd Stephen Smith Jr.
2009-01-20  8:57   ` Thomas Rast

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=alpine.LFD.2.00.0901271006060.3123@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=broonie@sirena.org.uk \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=zlib@gzip.org \
    /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