On Tue, May 18, 2021 at 03:31:28AM -0400, Jeff King wrote:
Does this have to use the same-size buffer? We could read and check
smaller chunks, like:
while (count > 0) {
static unsigned char chunk[1024];
unsigned int chunk_len = sizeof(chunk) < count ? sizeof(chunk) : count;
ssize_t ret = read_in_full(f->check_fd, chunk, chunk_len);
if (ret < 0)
...
if (ret != count)
...
if (memcmp(buf, chunk, chunk_len))
...
buf += chunk_len;
count -= chunk_len;
}
That should be "ret != chunk_len" in the middle conditional, of course.
In case you do go this route (I typed this straight into my email, so
other bugs may be lurking. But I noticed that one. :) ).
-Peff