[Zlib-devel] Compressing volatile data?
Mark Adler
madler at madler.net
Fri Sep 3 00:44:33 EDT 2010
On Sep 2, 2010, at 11:03 AM, Gary Cameron wrote:
> 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?
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
More information about the Zlib-devel
mailing list