On Thu, Nov 12, 2026 at 12:33:56PM -0300, Julio Faracco wrote:
> dmg_uncompress_lzfse_do() treated any non-zero lzfse_decode_buffer()
> return as success. A crafted DMG can declare a larger chunk output size
> than its LZFSE stream decodes to, leaking the unzeroed tail of
> uncompressed_chunk to the guest as sector data -- a heap disclosure.
> 
> lzfse_decode_buffer() returns the destination capacity both for an
> exact-size and a too-small destination, so decode with one extra byte of
> capacity (allocated in dmg_open()): an exact stream returns avail_out, a
> short or oversized one does not. Require out_size == avail_out. Decoding
> in place also avoids a per-chunk g_malloc()/memcpy() of up to 64 MiB in
> the read path.
> 
> zlib and bzip2 chunk paths already enforce this; LZFSE did not.
> 
> Fixes: CVE-2026-116483
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4662
> Reported-by: oxsignal <[email protected]>
> Signed-off-by: Julio Faracco <[email protected]>
> ---
>  block/dmg-lzfse.c | 27 +++++++++++++++++++--------
>  block/dmg.c       |  8 +++++++-
>  2 files changed, 26 insertions(+), 9 deletions(-)
> 
> diff --git a/block/dmg-lzfse.c b/block/dmg-lzfse.c
> index 4ea0b9b20d..b1acd87135 100644
> --- a/block/dmg-lzfse.c
> +++ b/block/dmg-lzfse.c
> @@ -33,16 +33,27 @@
>  static int dmg_uncompress_lzfse_do(char *next_in, unsigned int avail_in,
>                                     char *next_out, unsigned int avail_out)
>  {

The +1 approach could cause bugs in the future. block/dmg.h does not
document that avail_out + 1 bytes may be written to next_out:

  typedef int BdrvDmgUncompressFunc(char *next_in, unsigned int avail_in,
                                    char *next_out, unsigned int avail_out);

I would rather avoid the dangerous +1 even if it means oversized
compressed inputs are not detected. So how about only checking that the
return value from lzfse_decode_buffer() is out_size and returning -1 if
it is smaller?

Stefan


Reply via email to