X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FLzmaCustomDecompressLib%2FLzmaDecompress.c;fp=MdeModulePkg%2FLibrary%2FLzmaCustomDecompressLib%2FLzmaDecompress.c;h=18577acf3814cde3df2075dce37270966557cd13;hp=8f7c242dcaa82198e2b76718371dcb25bb3f3992;hb=1436aea4d5707e672672a11bda72be2c63c936c3;hpb=7c7184e201a90a1d2376e615e55e3f4074731468 diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c b/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c index 8f7c242dca..18577acf38 100644 --- a/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c +++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c @@ -11,13 +11,12 @@ #include "Sdk/C/7zVersion.h" #include "Sdk/C/LzmaDec.h" -#define SCRATCH_BUFFER_REQUEST_SIZE SIZE_64KB +#define SCRATCH_BUFFER_REQUEST_SIZE SIZE_64KB -typedef struct -{ - ISzAlloc Functions; - VOID *Buffer; - UINTN BufferSize; +typedef struct { + ISzAlloc Functions; + VOID *Buffer; + UINTN BufferSize; } ISzAllocWithData; /** @@ -30,18 +29,18 @@ typedef struct **/ VOID * SzAlloc ( - CONST ISzAlloc *P, - size_t Size + CONST ISzAlloc *P, + size_t Size ) { - VOID *Addr; - ISzAllocWithData *Private; + VOID *Addr; + ISzAllocWithData *Private; - Private = (ISzAllocWithData*) P; + Private = (ISzAllocWithData *)P; if (Private->BufferSize >= Size) { - Addr = Private->Buffer; - Private->Buffer = (VOID*) ((UINT8*)Addr + Size); + Addr = Private->Buffer; + Private->Buffer = (VOID *)((UINT8 *)Addr + Size); Private->BufferSize -= Size; return Addr; } else { @@ -58,8 +57,8 @@ SzAlloc ( **/ VOID SzFree ( - CONST ISzAlloc *P, - VOID *Address + CONST ISzAlloc *P, + VOID *Address ) { // @@ -69,7 +68,7 @@ SzFree ( // } -#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8) +#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8) /** Get the size of the uncompressed buffer by parsing EncodeData header. @@ -79,17 +78,18 @@ SzFree ( @return The size of the uncompressed buffer. **/ UINT64 -GetDecodedSizeOfBuf( - UINT8 *EncodedData +GetDecodedSizeOfBuf ( + UINT8 *EncodedData ) { - UINT64 DecodedSize; - INTN Index; + UINT64 DecodedSize; + INTN Index; /* Parse header */ DecodedSize = 0; - for (Index = LZMA_PROPS_SIZE + 7; Index >= LZMA_PROPS_SIZE; Index--) - DecodedSize = LShiftU64(DecodedSize, 8) + EncodedData[Index]; + for (Index = LZMA_PROPS_SIZE + 7; Index >= LZMA_PROPS_SIZE; Index--) { + DecodedSize = LShiftU64 (DecodedSize, 8) + EncodedData[Index]; + } return DecodedSize; } @@ -143,15 +143,15 @@ LzmaUefiDecompressGetInfo ( { UInt64 DecodedSize; - ASSERT(SourceSize >= LZMA_HEADER_SIZE); + ASSERT (SourceSize >= LZMA_HEADER_SIZE); - DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source); + DecodedSize = GetDecodedSizeOfBuf ((UINT8 *)Source); if (DecodedSize > MAX_UINT32) { return RETURN_UNSUPPORTED; } *DestinationSize = (UINT32)DecodedSize; - *ScratchSize = SCRATCH_BUFFER_REQUEST_SIZE; + *ScratchSize = SCRATCH_BUFFER_REQUEST_SIZE; return RETURN_SUCCESS; } @@ -192,25 +192,25 @@ LzmaUefiDecompress ( SizeT EncodedDataSize; ISzAllocWithData AllocFuncs; - AllocFuncs.Functions.Alloc = SzAlloc; - AllocFuncs.Functions.Free = SzFree; - AllocFuncs.Buffer = Scratch; - AllocFuncs.BufferSize = SCRATCH_BUFFER_REQUEST_SIZE; - - DecodedBufSize = (SizeT)GetDecodedSizeOfBuf((UINT8*)Source); - EncodedDataSize = (SizeT) (SourceSize - LZMA_HEADER_SIZE); - - LzmaResult = LzmaDecode( - Destination, - &DecodedBufSize, - (Byte*)((UINT8*)Source + LZMA_HEADER_SIZE), - &EncodedDataSize, - Source, - LZMA_PROPS_SIZE, - LZMA_FINISH_END, - &Status, - &(AllocFuncs.Functions) - ); + AllocFuncs.Functions.Alloc = SzAlloc; + AllocFuncs.Functions.Free = SzFree; + AllocFuncs.Buffer = Scratch; + AllocFuncs.BufferSize = SCRATCH_BUFFER_REQUEST_SIZE; + + DecodedBufSize = (SizeT)GetDecodedSizeOfBuf ((UINT8 *)Source); + EncodedDataSize = (SizeT)(SourceSize - LZMA_HEADER_SIZE); + + LzmaResult = LzmaDecode ( + Destination, + &DecodedBufSize, + (Byte *)((UINT8 *)Source + LZMA_HEADER_SIZE), + &EncodedDataSize, + Source, + LZMA_PROPS_SIZE, + LZMA_FINISH_END, + &Status, + &(AllocFuncs.Functions) + ); if (LzmaResult == SZ_OK) { return RETURN_SUCCESS; @@ -218,4 +218,3 @@ LzmaUefiDecompress ( return RETURN_INVALID_PARAMETER; } } -