qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Daan De Meyer <daan.j.demeyer@gmail.com>
Cc: qemu-devel@nongnu.org, "Gerd Hoffmann" <kraxel@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	qemu-arm@nongnu.org
Subject: Re: [PATCH] Add support for zboot images compressed with zstd
Date: Fri, 10 Oct 2025 11:05:43 +0100	[thread overview]
Message-ID: <CAFEAcA-iQkqxR5jPtGC1EAtcH4FYD5y71x6RFSWC3vP05krScw@mail.gmail.com> (raw)
In-Reply-To: <20251008191716.3005164-1-daan.j.demeyer@gmail.com>

On Wed, 8 Oct 2025 at 20:17, Daan De Meyer <daan.j.demeyer@gmail.com> wrote:
>
> Signed-off-by: Daan De Meyer <daan.j.demeyer@gmail.com>
> ---
>  hw/arm/boot.c       |  2 +-
>  hw/core/loader.c    | 36 ++++++++++++++++++++++++------------
>  hw/nvram/fw_cfg.c   |  2 +-
>  include/hw/loader.h |  2 +-
>  4 files changed, 27 insertions(+), 15 deletions(-)
>
> diff --git a/hw/arm/boot.c b/hw/arm/boot.c
> index e77d8679d8..c0dec0343a 100644
> --- a/hw/arm/boot.c
> +++ b/hw/arm/boot.c
> @@ -826,7 +826,7 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
>      ssize_t size;
>
>      /* On aarch64, it's the bootloader's job to uncompress the kernel. */
> -    size = load_image_gzipped_buffer(filename, LOAD_IMAGE_MAX_GUNZIP_BYTES,
> +    size = load_image_gzipped_buffer(filename, LOAD_IMAGE_MAX_DECOMPRESSED_BYTES,
>                                       &buffer);

I would either not bother renaming this constant, or else do
it in a preliminary patch of its own in the series. (That
makes the part of the patch which is making the functional
change easier to read and review.)

> @@ -882,14 +887,6 @@ ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
>          return 0;
>      }
>
> -    if (strcmp(header->compression_type, "gzip") != 0) {
> -        fprintf(stderr,
> -                "unable to handle EFI zboot image with \"%.*s\" compression\n",
> -                (int)sizeof(header->compression_type) - 1,
> -                header->compression_type);
> -        return -1;
> -    }
> -
>      ploff = ldl_le_p(&header->payload_offset);
>      plsize = ldl_le_p(&header->payload_size);
>
> @@ -898,8 +895,23 @@ ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
>          return -1;
>      }
>
> -    data = g_malloc(LOAD_IMAGE_MAX_GUNZIP_BYTES);
> -    bytes = gunzip(data, LOAD_IMAGE_MAX_GUNZIP_BYTES, *buffer + ploff, plsize);
> +    data = g_malloc(LOAD_IMAGE_MAX_DECOMPRESSED_BYTES);
> +
> +    if (strcmp(header->compression_type, "gzip") == 0) {
> +        bytes = gunzip(data, LOAD_IMAGE_MAX_DECOMPRESSED_BYTES, *buffer + ploff, plsize);
> +#ifdef CONFIG_ZSTD
> +    } else if (strcmp(header->compression_type, "zstd") == 0) {
> +        size_t ret = ZSTD_decompress(data, LOAD_IMAGE_MAX_DECOMPRESSED_BYTES, *buffer + ploff, plsize);
> +        bytes = ZSTD_isError(ret) ? -1 : (ssize_t) ret;
> +#endif
> +    } else {
> +        fprintf(stderr,
> +                "unable to handle EFI zboot image with \"%.*s\" compression\n",
> +                (int)sizeof(header->compression_type) - 1,
> +                header->compression_type);
> +        return -1;

Moving the "unrecognized compression type" error path down to
here means that we have moved it below the g_malloc() of the
data buffer, so we now need to g_free() to avoid a leak.

> +    }
> +
>      if (bytes < 0) {
>          fprintf(stderr, "failed to decompress EFI zboot image\n");
>          g_free(data);

Otherwise I think this looks OK.

thanks
-- PMM


  reply	other threads:[~2025-10-10 10:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-08 19:17 [PATCH] Add support for zboot images compressed with zstd Daan De Meyer
2025-10-10 10:05 ` Peter Maydell [this message]
2025-10-10 11:53   ` Alex Bennée
2025-10-10 12:09     ` Peter Maydell
2025-10-10 16:01       ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFEAcA-iQkqxR5jPtGC1EAtcH4FYD5y71x6RFSWC3vP05krScw@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=daan.j.demeyer@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).