From: Eric Biggers Date: Thu, 22 Nov 2012 21:15:22 +0000 (-0600) Subject: Allocate extra 8 bytes for uncompressd chunks X-Git-Tag: v1.2.0~3 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=9afc98eb22b4fd2b079207a6572621cde8510fa0;hp=e76cdf475d666be9c782465e970e177ecad7a434 Allocate extra 8 bytes for uncompressd chunks (Due to longest_match() possible reading off the edge of the buffer.) --- diff --git a/src/write.c b/src/write.c index 061f0e7b..653c212d 100644 --- a/src/write.c +++ b/src/write.c @@ -62,24 +62,15 @@ #include #endif - -static int do_fflush(FILE *fp) +static int fflush_and_ftruncate(FILE *fp, off_t size) { - int ret = fflush(fp); + int ret; + + ret = fflush(fp); if (ret != 0) { ERROR_WITH_ERRNO("Failed to flush data to output WIM file"); return WIMLIB_ERR_WRITE; } - return 0; -} - -static int fflush_and_ftruncate(FILE *fp, off_t size) -{ - int ret; - - ret = do_fflush(fp); - if (ret != 0) - return ret; ret = ftruncate(fileno(fp), size); if (ret != 0) { ERROR_WITH_ERRNO("Failed to truncate output WIM file to " @@ -833,7 +824,12 @@ static int main_writer_thread_proc(struct list_head *stream_list, for (size_t i = 0; i < ARRAY_LEN(msgs); i++) { for (size_t j = 0; j < MAX_CHUNKS_PER_MSG; j++) { msgs[i].compressed_chunks[j] = MALLOC(WIM_CHUNK_SIZE); - msgs[i].uncompressed_chunks[j] = MALLOC(WIM_CHUNK_SIZE); + + // The extra 8 bytes is because longest_match() in lz.c + // may read a little bit off the end of the uncompressed + // data. It doesn't need to be initialized--- we really + // just need to avoid accessing an unmapped page. + msgs[i].uncompressed_chunks[j] = MALLOC(WIM_CHUNK_SIZE + 8); if (msgs[i].compressed_chunks[j] == NULL || msgs[i].uncompressed_chunks[j] == NULL) {