<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thanks a lot to all of you, that is very helpful to know.<br>
<br>
It was obvious the checksum could be wrong in this case, but I wasn't
sure if it could explain decompression errors as well.<br>
<br>
<br>
Mark Adler wrote:
<blockquote cite="mid:1889AAAF-B52A-4A32-B20B-9E20471273DE@madler.net"
 type="cite">
  <pre wrap="">On Sep 2, 2010, at 11:03 AM, Gary Cameron wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">if parts of the data in the source buffer being compressed is still "active" and changing during the compression, could this cause a decompression failure?
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Gary,

Yes.

This code in deflate.c is the only thing that accesses the source buffer:

    if (strm->state->wrap == 1) {
        strm->adler = adler32(strm->adler, strm->next_in, len);
    }
    else if (strm->state->wrap == 2) {
        strm->adler = crc32(strm->adler, strm->next_in, len);
    }
    zmemcpy(buf, strm->next_in, len);

So the buffer is accessed twice: first to compute a check value, and second to copy the data.  If the source buffer is changed between those two, then the check value will not match the data, and an error will be reported when decompressing.

When this happens, the compressed data is not itself corrupted.  The only problem is a mismatch between an earlier check value and later data.

This deflate sensitivity to volatile input data can be solved thusly:

    zmemcpy(buf, strm->next_in, len);
    if (strm->state->wrap == 1) {
        strm->adler = adler32(strm->adler, buf, len);
    }
    else if (strm->state->wrap == 2) {
        strm->adler = crc32(strm->adler, buf, len);
    }

I have just made that change for the next version.

Mark


_______________________________________________
Zlib-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Zlib-devel@madler.net">Zlib-devel@madler.net</a>
<a class="moz-txt-link-freetext" href="http://mail.madler.net/mailman/listinfo/zlib-devel_madler.net">http://mail.madler.net/mailman/listinfo/zlib-devel_madler.net</a>
  </pre>
</blockquote>
<br>
</body>
</html>