How can I force QuickBMS to ignore negative filesizes when compressing?

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
CommanderVideo
Posts: 9
Joined: Wed Nov 10, 2021 5:10 am

How can I force QuickBMS to ignore negative filesizes when compressing?

Post by CommanderVideo »

This game that I'm recompressing has a bunch of .ogg files, and when I use QuickBMS to try and compress it again after successfully decompressing it, some of the .ogg files end the compression process and give me the error:

Code: Select all

Error: there is an error with the decompression
       the returned output size is negative (-1)

This seems to be happening because the compressed file's size is larger than the original, decompressed filesize. Is there a way I can bypass this error and have QuickBMS compress the .ogg files regardless of their size?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: How can I force QuickBMS to ignore negative filesizes when compressing?

Post by aluigi »

you can set any desired output size in the following way:
xmath NEW_SIZE "SIZE * 2"
clog NAME OFFSET SIZE NEW_SIZE

What compression algorithm are you using?
All the *_compress algorithms in quickbms automatically set a slightly bigger output size but it's possible that it's not enough with some algorithms in some conditions.
CommanderVideo
Posts: 9
Joined: Wed Nov 10, 2021 5:10 am

Re: How can I force QuickBMS to ignore negative filesizes when compressing?

Post by CommanderVideo »

aluigi wrote:you can set any desired output size in the following way:
xmath NEW_SIZE "SIZE * 2"
clog NAME OFFSET SIZE NEW_SIZE

What compression algorithm are you using?
All the *_compress algorithms in quickbms automatically set a slightly bigger output size but it's possible that it's not enough with some algorithms in some conditions.

I'm using the lz77wii_compress 0x10 algorithm. It usually compresses things just fine, and it only seems to have these issues when compressing .ogg files. Also, if possible, I would prefer to have QuickBMS automatically determine the compressed filesize as usual and just ignore whether it's larger or smaller than the original file, rather than setting a specific size for the compressed files to be. Sorry if I'm asking for too much ;P
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: How can I force QuickBMS to ignore negative filesizes when compressing?

Post by aluigi »

Almost all the algorithms in quickbms directly decompress the data into the output buffer, lz77wii is one of the very few in which the output buffer is dynamically enlarged to fit the decompressed data.

Usually the algorithms for recompressing data have enough space for the newly compressed data but sometimes, like in your case, that may not be enough.
CommanderVideo
Posts: 9
Joined: Wed Nov 10, 2021 5:10 am

Re: How can I force QuickBMS to ignore negative filesizes when compressing?

Post by CommanderVideo »

aluigi wrote:Almost all the algorithms in quickbms directly decompress the data into the output buffer, lz77wii is one of the very few in which the output buffer is dynamically enlarged to fit the decompressed data.

Usually the algorithms for recompressing data have enough space for the newly compressed data but sometimes, like in your case, that may not be enough.

I see... is there a way to edit the algorithm/script so that there's enough space in that case?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: How can I force QuickBMS to ignore negative filesizes when compressing?

Post by aluigi »

I already gave you the code in my first answer.
CommanderVideo
Posts: 9
Joined: Wed Nov 10, 2021 5:10 am

Re: How can I force QuickBMS to ignore negative filesizes when compressing?

Post by CommanderVideo »

aluigi wrote:I already gave you the code in my first answer.

Oh, my bad :shock:

Anyways, I plugged the code into my script, but the output file was 0 KB.
I had my go at figuring out the problem, but whatever it is is beyond me.
The script i used is:

Code: Select all

get name FILENAME
get zsize asize
comtype lz77wii_compress 0x10
xmath NEW_SIZE "SIZE * 2"
clog name OFFSET SIZE NEW_SIZE

Is there anything wrong with this script?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: How can I force QuickBMS to ignore negative filesizes when compressing?

Post by aluigi »

get zsize asize
->
get size asize
CommanderVideo
Posts: 9
Joined: Wed Nov 10, 2021 5:10 am

Re: How can I force QuickBMS to ignore negative filesizes when compressing?

Post by CommanderVideo »

aluigi wrote:get zsize asize
->
get size asize


Thanks!