#include <libbz3.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv) {
FILE * fp = fopen(argv[1], "rb");
fseek(fp, 0, SEEK_END);
size_t size = ftell(fp);
fseek(fp, 0, SEEK_SET);
volatile uint8_t * buffer = malloc(size);
fread(buffer, 1, size, fp);
fclose(fp);
if(size < 64) {
return 0;
}
size_t orig_size = *(size_t *)buffer;
if (orig_size >= 0x10000000) {
return 0;
}
uint8_t * outbuf = malloc(orig_size);
int bzerr = bz3_decompress(buffer + sizeof(size_t), outbuf, size - sizeof(size_t), &orig_size);
if (bzerr != BZ3_OK) {
printf("bz3_decompress() failed with error code %d", bzerr);
return 1;
}
printf("OK, %d => %d", size, orig_size);
free(outbuf);
free(buffer);
return 0;
}