diff mbox series

[1/2] test: compression: check with trailing garbage in input

Message ID 20221228225352.38364-1-brandon.maier@collins.com
State Accepted
Commit 43b059884ae1c52a197529b3ac81046d582fb60f
Delegated to: Tom Rini
Headers show
Series [1/2] test: compression: check with trailing garbage in input | expand

Commit Message

Brandon Maier Dec. 28, 2022, 10:53 p.m. UTC
The Linux kernel appends 4 bytes to the end of compressed kernel Images
containing the uncompressed image size. They are used to make
self-decompressing Images easier. However for archs that don't support
self-decompression, like ARM64, U-Boot must be able to decompress the
image with the garbage data.

The existing decompressors already support this. This unit test was
added while working on zstd support as upstream zstd will error if there
is garbage data in the input buffer, and special care was needed to
support this.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
---
 test/compression.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Simon Glass Dec. 29, 2022, 10:38 p.m. UTC | #1
On Wed, 28 Dec 2022 at 16:54, Brandon Maier <brandon.maier@collins.com> wrote:
>
> The Linux kernel appends 4 bytes to the end of compressed kernel Images
> containing the uncompressed image size. They are used to make
> self-decompressing Images easier. However for archs that don't support
> self-decompression, like ARM64, U-Boot must be able to decompress the
> image with the garbage data.
>
> The existing decompressors already support this. This unit test was
> added while working on zstd support as upstream zstd will error if there
> is garbage data in the input buffer, and special care was needed to
> support this.
>
> Signed-off-by: Brandon Maier <brandon.maier@collins.com>
> ---
>  test/compression.c | 9 +++++++++
>  1 file changed, 9 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Jan. 12, 2023, 3:19 p.m. UTC | #2
On Wed, Dec 28, 2022 at 04:53:51PM -0600, Brandon Maier wrote:

> The Linux kernel appends 4 bytes to the end of compressed kernel Images
> containing the uncompressed image size. They are used to make
> self-decompressing Images easier. However for archs that don't support
> self-decompression, like ARM64, U-Boot must be able to decompress the
> image with the garbage data.
> 
> The existing decompressors already support this. This unit test was
> added while working on zstd support as upstream zstd will error if there
> is garbage data in the input buffer, and special care was needed to
> support this.
> 
> Signed-off-by: Brandon Maier <brandon.maier@collins.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/test/compression.c b/test/compression.c
index 82e29c9b86b..6c2a43fbed7 100644
--- a/test/compression.c
+++ b/test/compression.c
@@ -350,6 +350,15 @@  static int run_test_internal(struct unit_test_state *uts, char *name,
 			buf->orig_size) == 0);
 	errcheck(((char *)buf->uncompressed_buf)[buf->orig_size] == 'A');
 
+	/* Uncompresses with trailing garbage in input buffer. */
+	memset(buf->uncompressed_buf, 'A', TEST_BUFFER_SIZE);
+	errcheck(uncompress(uts, buf->compressed_buf, buf->compressed_size + 4,
+			    buf->uncompressed_buf, buf->uncompressed_size,
+			    &buf->uncompressed_size) == 0);
+	errcheck(buf->uncompressed_size == buf->orig_size);
+	errcheck(memcmp(buf->orig_buf, buf->uncompressed_buf,
+			buf->orig_size) == 0);
+
 	/* Make sure compression does not over-run. */
 	memset(buf->compare_buf, 'A', TEST_BUFFER_SIZE);
 	ret = compress(uts, buf->orig_buf, buf->orig_size,