@matheusbsbs / matheus-bagliano / commits / 5d6f3ef641
Fork 0

Corrected buffer overflow during automatic checkpoint in fast-import.

If we previously were using a delta but we needed to checkpoint the current packfile and switch to a new packfile we need to throw away the delta and compress the raw object by itself, as delta chains cannot span non-thin packfiles. Unfortunately the output buffer in this case needs to grow, as the size of the compressed object may be quite a bit larger than the size of the compressed delta. I've also avoided recompressing the object if we are checkpointing and we didn't use a delta. In this case the output buffer is the correct size and has already been populated with the right data, we just need to close out the current packfile and open a new one. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 15, 2007 at 23:40 UTC 5d6f3ef6413172388ee5e6090afe9802a30a59f0
1 file changed +10 -9
fast-import.c
+10 -9
@@ -847,16 +847,17 @@ static int store_object(
847 if (delta) {
848 free(delta);
849 delta = NULL;
850 +
851 + memset(&s, 0, sizeof(s));
852 + deflateInit(&s, zlib_compression_level);
853 + s.next_in = dat;
854 + s.avail_in = datlen;
855 + s.avail_out = deflateBound(&s, s.avail_in);
856 + s.next_out = out = xrealloc(out, s.avail_out);
857 + while (deflate(&s, Z_FINISH) == Z_OK)
858 + /* nothing */;
859 + deflateEnd(&s);
860 }
851 - memset(&s, 0, sizeof(s));
852 - deflateInit(&s, zlib_compression_level);
853 - s.next_in = dat;
854 - s.avail_in = datlen;
855 - s.avail_out = deflateBound(&s, s.avail_in);
856 - s.next_out = out;
857 - while (deflate(&s, Z_FINISH) == Z_OK)
858 - /* nothing */;
859 - deflateEnd(&s);
861 }
862
863 e->type = type;