mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-11-29 04:54:49 +08:00
initrd: fix lz4 decompress with initrd
During testing initrd (>2G) support, find decompress/lz4 does not work with initrd at all. decompress_* should support: 1. inbuf[]/outbuf[] for kernel preboot. 2. inbuf[]/flush() for initramfs 3. fill()/flush() for initrd. in the unlz4 does not handle case 3, as input len is passed as 0, and it failed in first try. Fix that add one extra if (fill) checking, and get out if EOF from the fill(). Signed-off-by: Yinghai Lu <yinghai@kernel.org> Cc: Kyungsik Lee <kyungsik.lee@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
fa5a7a41a6
commit
4d4b866aee
@ -83,13 +83,20 @@ STATIC inline int INIT unlz4(u8 *input, int in_len,
|
|||||||
if (posp)
|
if (posp)
|
||||||
*posp = 0;
|
*posp = 0;
|
||||||
|
|
||||||
if (fill)
|
if (fill) {
|
||||||
fill(inp, 4);
|
size = fill(inp, 4);
|
||||||
|
if (size < 4) {
|
||||||
|
error("data corrupted");
|
||||||
|
goto exit_2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
chunksize = get_unaligned_le32(inp);
|
chunksize = get_unaligned_le32(inp);
|
||||||
if (chunksize == ARCHIVE_MAGICNUMBER) {
|
if (chunksize == ARCHIVE_MAGICNUMBER) {
|
||||||
inp += 4;
|
if (!fill) {
|
||||||
size -= 4;
|
inp += 4;
|
||||||
|
size -= 4;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error("invalid header");
|
error("invalid header");
|
||||||
goto exit_2;
|
goto exit_2;
|
||||||
@ -100,29 +107,44 @@ STATIC inline int INIT unlz4(u8 *input, int in_len,
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
if (fill)
|
if (fill) {
|
||||||
fill(inp, 4);
|
size = fill(inp, 4);
|
||||||
|
if (size == 0)
|
||||||
|
break;
|
||||||
|
if (size < 4) {
|
||||||
|
error("data corrupted");
|
||||||
|
goto exit_2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
chunksize = get_unaligned_le32(inp);
|
chunksize = get_unaligned_le32(inp);
|
||||||
if (chunksize == ARCHIVE_MAGICNUMBER) {
|
if (chunksize == ARCHIVE_MAGICNUMBER) {
|
||||||
inp += 4;
|
if (!fill) {
|
||||||
size -= 4;
|
inp += 4;
|
||||||
|
size -= 4;
|
||||||
|
}
|
||||||
if (posp)
|
if (posp)
|
||||||
*posp += 4;
|
*posp += 4;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
inp += 4;
|
|
||||||
size -= 4;
|
|
||||||
|
|
||||||
if (posp)
|
if (posp)
|
||||||
*posp += 4;
|
*posp += 4;
|
||||||
|
|
||||||
if (fill) {
|
if (!fill) {
|
||||||
|
inp += 4;
|
||||||
|
size -= 4;
|
||||||
|
} else {
|
||||||
if (chunksize > lz4_compressbound(uncomp_chunksize)) {
|
if (chunksize > lz4_compressbound(uncomp_chunksize)) {
|
||||||
error("chunk length is longer than allocated");
|
error("chunk length is longer than allocated");
|
||||||
goto exit_2;
|
goto exit_2;
|
||||||
}
|
}
|
||||||
fill(inp, chunksize);
|
size = fill(inp, chunksize);
|
||||||
|
if (size < chunksize) {
|
||||||
|
error("data corrupted");
|
||||||
|
goto exit_2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifdef PREBOOT
|
#ifdef PREBOOT
|
||||||
if (out_len >= uncomp_chunksize) {
|
if (out_len >= uncomp_chunksize) {
|
||||||
@ -149,18 +171,17 @@ STATIC inline int INIT unlz4(u8 *input, int in_len,
|
|||||||
if (posp)
|
if (posp)
|
||||||
*posp += chunksize;
|
*posp += chunksize;
|
||||||
|
|
||||||
size -= chunksize;
|
if (!fill) {
|
||||||
|
size -= chunksize;
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
break;
|
break;
|
||||||
else if (size < 0) {
|
else if (size < 0) {
|
||||||
error("data corrupted");
|
error("data corrupted");
|
||||||
goto exit_2;
|
goto exit_2;
|
||||||
|
}
|
||||||
|
inp += chunksize;
|
||||||
}
|
}
|
||||||
|
|
||||||
inp += chunksize;
|
|
||||||
if (fill)
|
|
||||||
inp = inp_start;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user