bsdiff icon indicating copy to clipboard operation
bsdiff copied to clipboard

bsdiff with zlib instead of bz2

Open balix-microej opened this issue 4 years ago • 2 comments

Hello,

Is bsdiff compatible with other compression libraries?

I need a version with zlib, so I tried replacing bz2 write/read with zlib equivalent.

bsdiff seems to work however when running bspatch the sanity check fails every time:

		/* Sanity-check */
		if (ctrl[0]<0 || ctrl[0]>INT_MAX ||
			ctrl[1]<0 || ctrl[1]>INT_MAX ||
			newpos+ctrl[0]>newsize)
			return -1;

I don't understand why but the values in the ctrl array are way too high are negative.

This is what I got by running a debug session:

(gdb) p ctrl
$1 = {2248591341461585215, -5979881847581223336, -7917639821140655946}

Opposed to the bz2 version which can give something like this:

(gdb) p ctrl
$4 = {0, 3000, 589}

Is there any advice to adapt bsdiff for a different compression method?

Thanks,

Benjamin

PS: here are the stream functions I adapted to zlib:

static int bz2_read(const struct bspatch_stream* stream, void* buffer, int length)
{
	int bytes;
	gzFile* gz;

	gz = (gzFile*) stream->opaque;
	bytes = gzread(*gz, buffer, length);
	if (0 == bytes) {
		return -1;
	}

	return 0;
}

static int bz2_write(struct bsdiff_stream* stream, const void* buffer, int size)
{
	int bytes;
	gzFile* gz;

	gz = (gzFile*) stream->opaque;
	bytes = gzwrite(*gz, buffer, size);
	if (0 == bytes) {
		return -1;
	}

	return 0;
}

balix-microej avatar Jul 01 '21 07:07 balix-microej

Hello @balix-microej, did you perhaps find a solution to your issue? I was hoping to do the same. Kind regards

rikkeskov avatar Mar 19 '24 08:03 rikkeskov

Hello @rikkeskov

I don't exactly remember what was the issue but I eventually ended up using deflate() and inflate() zlib functions to implement the write and read backend.

Best regards,

Benjamin

balix-microej avatar Mar 19 '24 14:03 balix-microej