examples/decompress-file.c does not work in the practice
asarubbo opened this issue · comments
Hello,
apart what reported in #93 and while I also understand that examples/decompress-file.c is a demonstration, I'm unable to make it working, here is a POC:
$ echo "test" > test.txt
$ bzip3 test.txt
$ bz3cat test.txt.bz3
test
$ time decompress-file test.txt.bz3 OUTPUT
bz3_decompress() failed with error code -4
real 0m5.813s
user 0m0.890s
sys 0m4.920s
Do you get the same output or I'm doing something wrong?
Thanks
NOTE: It takes 5.8 seconds only when decompress-file.c is compiled with asan.
decompress-file.c
decompressed things produced by compress-file.c
reason: when you use the bzip3 CLI tool, it can work as a filter (... | bzip3 -b 128 | ...
), so the size is not known upfront. The high level api knows the size upfront, so the formats differ.
decompress-file.c
decompressed things produced bycompress-file.c
Thanks for the explanation, that works for me.
However a crafted bz3 file, can cause an overflow in decompress-file.c
not in the library. If you think you may want to fix this issue (because, afterall, give demonstration code that overflows is not the best scenario) I can file a separate bug.
yes, you can break the example code. you can break it by e.g. cross-endian execution, by giving it file names that don't exist, etc... - this is not the point of demonstration code. to my understanding, it has to be as simple without obscuring it with guard rails to not introduce any confusion as possible.
[...]
it does not contain all the necessary error checks