LZMA: Add a version of ulzma which takes the input and output buffer sizes.
This version is used to implement the version which doesn't. BUG=chromium:270897 TEST=Built into depthcharge and booted on pit. BRANCH=None Change-Id: I8935024aca0849bc939263d7fc3036c586e63c68 Signed-off-by: Gabe Black <gabeblack@google.com> Reviewed-on: https://gerrit.chromium.org/gerrit/65510 Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Stefan Reinauer <reinauer@google.com> Tested-by: Gabe Black <gabeblack@chromium.org> Commit-Queue: Gabe Black <gabeblack@chromium.org>
This commit is contained in:
parent
23e866da20
commit
465d167ad2
2 changed files with 26 additions and 6 deletions
|
|
@ -30,10 +30,18 @@
|
|||
#ifndef _LZMA_H
|
||||
#define _LZMA_H
|
||||
|
||||
/* decompresses the data stream at src to dst, determining its length from
|
||||
/* Decompresses the data stream at src to dst. The sizes of the source and
|
||||
* destination buffers are in srcn and dstn.
|
||||
*
|
||||
* Returns the decompressed size, or 0 on error
|
||||
*/
|
||||
unsigned long ulzman(const unsigned char *src, unsigned long srcn,
|
||||
unsigned char *dst, unsigned long dstn);
|
||||
|
||||
/* Decompresses the data stream at src to dst, determining its length from
|
||||
* the data stream itself.
|
||||
*
|
||||
* returns the decompressed size, or 0 on error
|
||||
* Returns the decompressed size, or 0 on error
|
||||
*/
|
||||
unsigned long ulzma(const unsigned char *src, unsigned char *dst);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,11 @@
|
|||
#include <string.h>
|
||||
#include "lzmadecode.c"
|
||||
|
||||
unsigned long ulzma(const unsigned char * src, unsigned char * dst)
|
||||
unsigned long ulzman(const unsigned char *src, unsigned long srcn,
|
||||
unsigned char *dst, unsigned long dstn)
|
||||
{
|
||||
unsigned char properties[LZMA_PROPERTIES_SIZE];
|
||||
const int data_offset = LZMA_PROPERTIES_SIZE + 8;
|
||||
UInt32 outSize;
|
||||
SizeT inProcessed;
|
||||
SizeT outProcessed;
|
||||
|
|
@ -27,7 +29,12 @@ unsigned long ulzma(const unsigned char * src, unsigned char * dst)
|
|||
|
||||
memcpy(properties, src, LZMA_PROPERTIES_SIZE);
|
||||
memcpy(&outSize, src + LZMA_PROPERTIES_SIZE, sizeof(outSize));
|
||||
if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK) {
|
||||
if (outSize > dstn) {
|
||||
printf("lzma: Output truncated.\n");
|
||||
return 0;
|
||||
}
|
||||
if (LzmaDecodeProperties(&state.Properties, properties,
|
||||
LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK) {
|
||||
printf("lzma: Incorrect stream properties.\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -37,11 +44,16 @@ unsigned long ulzma(const unsigned char * src, unsigned char * dst)
|
|||
return 0;
|
||||
}
|
||||
state.Probs = (CProb *)scratchpad;
|
||||
res = LzmaDecode(&state, src + LZMA_PROPERTIES_SIZE + 8, (SizeT)0xffffffff, &inProcessed,
|
||||
dst, outSize, &outProcessed);
|
||||
res = LzmaDecode(&state, src + data_offset, srcn - data_offset,
|
||||
&inProcessed, dst, outSize, &outProcessed);
|
||||
if (res != 0) {
|
||||
printf("lzma: Decoding error = %d\n", res);
|
||||
return 0;
|
||||
}
|
||||
return outSize;
|
||||
}
|
||||
|
||||
unsigned long ulzma(const unsigned char *src, unsigned char *dst)
|
||||
{
|
||||
return ulzman(src, (unsigned long)(-1), dst, (unsigned long)(-1));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue