fix endianess bug in LZMA decoding

This commit is contained in:
Joel Dice 2012-06-06 12:58:24 -06:00
parent ba6ca031bb
commit 165986841e
4 changed files with 35 additions and 7 deletions

View File

@ -328,7 +328,7 @@ ifeq ($(platform),darwin)
version-script-flag =
lflags = $(common-lflags) -ldl -framework CoreFoundation
ifeq (,$(shell ld -v | grep cctools))
ifeq (,$(shell ld -v 2>&1 | grep cctools))
lflags += -Wl,-compatibility_version,1.0.0
endif

View File

@ -13,6 +13,19 @@
using namespace vm;
namespace {
int32_t
read4(const uint8_t* in)
{
return (static_cast<int32_t>(in[3]) << 24)
| (static_cast<int32_t>(in[2]) << 16)
| (static_cast<int32_t>(in[1]) << 8)
| (static_cast<int32_t>(in[0]) );
}
} // namespace
namespace vm {
uint8_t*
@ -22,8 +35,7 @@ decodeLZMA(System* s, Allocator* a, uint8_t* in, unsigned inSize,
const unsigned PropHeaderSize = 5;
const unsigned HeaderSize = 13;
int32_t outSize32;
memcpy(&outSize32, in + PropHeaderSize, 4);
int32_t outSize32 = read4(in + PropHeaderSize);
expect(s, outSize32 >= 0);
SizeT outSizeT = outSize32;

View File

@ -41,6 +41,15 @@ extern "C" {
namespace {
int32_t
read4(const uint8_t* in)
{
return (static_cast<int32_t>(in[3]) << 24)
| (static_cast<int32_t>(in[2]) << 16)
| (static_cast<int32_t>(in[1]) << 8)
| (static_cast<int32_t>(in[0]) );
}
void*
myAllocate(void*, size_t size)
{
@ -127,8 +136,7 @@ main(int ac, const char** av)
SizeT inSize = SYMBOL(end) - SYMBOL(start);
int32_t outSize32;
memcpy(&outSize32, SYMBOL(start) + PropHeaderSize, 4);
int32_t outSize32 = read4(SYMBOL(start) + PropHeaderSize);
SizeT outSize = outSize32;
uint8_t* out = static_cast<uint8_t*>(malloc(outSize));

View File

@ -17,6 +17,15 @@
namespace {
int32_t
read4(const uint8_t* in)
{
return (static_cast<int32_t>(in[3]) << 24)
| (static_cast<int32_t>(in[2]) << 16)
| (static_cast<int32_t>(in[1]) << 8)
| (static_cast<int32_t>(in[0]) );
}
void*
myAllocate(void*, size_t size)
{
@ -100,8 +109,7 @@ main(int argc, const char** argv)
if (encode) {
outSize = size * 2;
} else {
int32_t outSize32;
memcpy(&outSize32, data + PropHeaderSize, 4);
int32_t outSize32 = read4(data + PropHeaderSize);
if (outSize32 >= 0) {
outSize = outSize32;
} else if (argc == 5) {