diff options
author | Gabe Black <gabeblack@google.com> | 2014-02-20 23:38:49 -0800 |
---|---|---|
committer | Isaac Christensen <isaac.christensen@se-eng.com> | 2014-09-25 20:26:04 +0200 |
commit | dbd006b0820098ab1bc042a16853db7131cf91af (patch) | |
tree | 7fbdb8b767be6e39c91dc86d5023894dc73072c1 /util/cbfstool/lzma/lzma.c | |
parent | 49c98dc42b706897e802af12d16349ff65a9bd43 (diff) |
cbfstool: Propogate compression errors back to the caller.
When compression fails for whatever reason, the caller should know about it
rather than blindly assuming it worked correctly. That can prevent half
compressed data from ending up in the image.
This is currently happening for a segment of depthcharge which is triggering
a failure in LZMA. The size of the "compressed" data is never set and is
recorded as zero, and that segment effectively isn't loaded during boot.
Change-Id: Idbff01f5413d030bbf5382712780bbd0b9e83bc7
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-on: https://chromium-review.googlesource.com/187364
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
(cherry picked from commit be48f3e41eaf0eaf6686c61c439095fc56883cec)
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
Reviewed-on: http://review.coreboot.org/6960
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Diffstat (limited to 'util/cbfstool/lzma/lzma.c')
-rw-r--r-- | util/cbfstool/lzma/lzma.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/util/cbfstool/lzma/lzma.c b/util/cbfstool/lzma/lzma.c index 7a6081557a..abd1bfd9b5 100644 --- a/util/cbfstool/lzma/lzma.c +++ b/util/cbfstool/lzma/lzma.c @@ -83,11 +83,11 @@ static struct ISeqOutStream os = { Write }; * @param out_len a pointer to the compressed length of in */ -void do_lzma_compress(char *in, int in_len, char *out, int *out_len) +int do_lzma_compress(char *in, int in_len, char *out, int *out_len) { if (in_len == 0) { ERROR("LZMA: Input length is zero.\n"); - return; + return -1; } struct CLzmaEncProps props; @@ -119,7 +119,7 @@ void do_lzma_compress(char *in, int in_len, char *out, int *out_len) int res = LzmaEnc_SetProps(p, &props); if (res != SZ_OK) { ERROR("LZMA: LzmaEnc_SetProps failed.\n"); - return; + return -1; } unsigned char propsEncoded[LZMA_PROPS_SIZE + 8]; @@ -127,7 +127,7 @@ void do_lzma_compress(char *in, int in_len, char *out, int *out_len) res = LzmaEnc_WriteProperties(p, propsEncoded, &propsSize); if (res != SZ_OK) { ERROR("LZMA: LzmaEnc_WriteProperties failed.\n"); - return; + return -1; } instream.p = in; @@ -144,17 +144,18 @@ void do_lzma_compress(char *in, int in_len, char *out, int *out_len) res = LzmaEnc_Encode(p, &os, &is, 0, &LZMAalloc, &LZMAalloc); if (res != SZ_OK) { ERROR("LZMA: LzmaEnc_Encode failed %d.\n", res); - return; + return -1; } *out_len = outstream.pos; + return 0; } -void do_lzma_uncompress(char *dst, int dst_len, char *src, int src_len) +int do_lzma_uncompress(char *dst, int dst_len, char *src, int src_len) { if (src_len <= LZMA_PROPS_SIZE + 8) { ERROR("LZMA: Input length is too small.\n"); - return; + return -1; } uint64_t out_sizemax = get_64(&src[LZMA_PROPS_SIZE]); @@ -162,7 +163,7 @@ void do_lzma_uncompress(char *dst, int dst_len, char *src, int src_len) if (out_sizemax > (size_t) dst_len) { ERROR("Not copying %d bytes to %d-byte buffer!\n", (unsigned int)out_sizemax, dst_len); - return; + return -1; } enum ELzmaStatus status; @@ -179,6 +180,8 @@ void do_lzma_uncompress(char *dst, int dst_len, char *src, int src_len) if (res != SZ_OK) { ERROR("Error while decompressing.\n"); - return; + return -1; } + + return 0; } |