LZMA encode fix

This commit is contained in:
Joshua Granick
2015-06-27 12:37:18 -07:00
parent 362de4fd6a
commit b31b27e323
2 changed files with 10 additions and 8 deletions

View File

@@ -32,7 +32,7 @@ namespace nme
{ {
SizeT input_buffer_size = buffer_size(input_buffer); SizeT input_buffer_size = buffer_size(input_buffer);
Byte* input_buffer_data = (Byte *)buffer_data(input_buffer); Byte* input_buffer_data = (Byte *)buffer_data(input_buffer);
SizeT output_buffer_size = input_buffer_size + 1024; SizeT output_buffer_size = input_buffer_size + input_buffer_size / 5 + (1 << 16);
Byte* output_buffer_data = (Byte *)malloc(output_buffer_size); Byte* output_buffer_data = (Byte *)malloc(output_buffer_size);
SizeT props_size = 100; SizeT props_size = 100;
Byte* props_data = (Byte *)malloc(props_size); Byte* props_data = (Byte *)malloc(props_size);

View File

@@ -63,10 +63,10 @@ namespace lime {
SizeT inputBufferSize = data->Length (); SizeT inputBufferSize = data->Length ();
Byte* inputBufferData = data->Data (); Byte* inputBufferData = data->Data ();
result->Resize (inputBufferSize + inputBufferSize / 5 + (1 << 16)); Bytes tempBuffer = Bytes (inputBufferSize + inputBufferSize / 5 + (1 << 16));
SizeT outputBufferSize = result->Length (); SizeT outputBufferSize = tempBuffer.Length ();
Byte* outputBufferData = result->Data (); Byte* outputBufferData = tempBuffer.Data ();
SizeT propsSize = 100; SizeT propsSize = 100;
Byte* propsData = (Byte *)malloc (propsSize); Byte* propsData = (Byte *)malloc (propsSize);
Int64 uncompressedLength = inputBufferSize; Int64 uncompressedLength = inputBufferSize;
@@ -81,12 +81,14 @@ namespace lime {
ISzAlloc allocSmall = { LZMA_alloc, LZMA_free }; ISzAlloc allocSmall = { LZMA_alloc, LZMA_free };
ISzAlloc allocBig = { LZMA_alloc, LZMA_free }; ISzAlloc allocBig = { LZMA_alloc, LZMA_free };
LzmaEncode (outputBufferData + propsSize + 8, &outputBufferSize, inputBufferData, inputBufferSize, &props, propsData, &propsSize, props.writeEndMark, &progress, &allocSmall, &allocBig); LzmaEncode (outputBufferData, &outputBufferSize, inputBufferData, inputBufferSize, &props, propsData, &propsSize, props.writeEndMark, &progress, &allocSmall, &allocBig);
memcpy (outputBufferData, propsData, propsSize);
WRITE_LE64 (outputBufferData + propsSize, uncompressedLength);
result->Resize (outputBufferSize + propsSize + 8); result->Resize (outputBufferSize + propsSize + 8);
Byte* resultData = result->Data ();
memcpy (resultData, propsData, propsSize);
WRITE_LE64 (resultData + propsSize, uncompressedLength);
memcpy (resultData + propsSize + 8, outputBufferData, outputBufferSize);
free (propsData); free (propsData);