From b31b27e3236d89e964fc98f959eef32f8642c2b2 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sat, 27 Jun 2015 12:37:18 -0700 Subject: [PATCH] LZMA encode fix --- legacy/project/src/common/Lzma.cpp | 2 +- project/src/utils/LZMA.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/legacy/project/src/common/Lzma.cpp b/legacy/project/src/common/Lzma.cpp index fdf20d50c..d563c396a 100644 --- a/legacy/project/src/common/Lzma.cpp +++ b/legacy/project/src/common/Lzma.cpp @@ -32,7 +32,7 @@ namespace nme { SizeT input_buffer_size = buffer_size(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); SizeT props_size = 100; Byte* props_data = (Byte *)malloc(props_size); diff --git a/project/src/utils/LZMA.cpp b/project/src/utils/LZMA.cpp index bdc33260d..5a7c8c41d 100644 --- a/project/src/utils/LZMA.cpp +++ b/project/src/utils/LZMA.cpp @@ -63,10 +63,10 @@ namespace lime { SizeT inputBufferSize = data->Length (); Byte* inputBufferData = data->Data (); - result->Resize (inputBufferSize + inputBufferSize / 5 + (1 << 16)); + Bytes tempBuffer = Bytes (inputBufferSize + inputBufferSize / 5 + (1 << 16)); - SizeT outputBufferSize = result->Length (); - Byte* outputBufferData = result->Data (); + SizeT outputBufferSize = tempBuffer.Length (); + Byte* outputBufferData = tempBuffer.Data (); SizeT propsSize = 100; Byte* propsData = (Byte *)malloc (propsSize); Int64 uncompressedLength = inputBufferSize; @@ -81,12 +81,14 @@ namespace lime { ISzAlloc allocSmall = { 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); - - memcpy (outputBufferData, propsData, propsSize); - WRITE_LE64 (outputBufferData + propsSize, uncompressedLength); + LzmaEncode (outputBufferData, &outputBufferSize, inputBufferData, inputBufferSize, &props, propsData, &propsSize, props.writeEndMark, &progress, &allocSmall, &allocBig); 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);