All of lore.kernel.org
 help / color / mirror / Atom feed
From: sudhakar <sudhakar@linux.ibm.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: daniel.kiper@oracle.com, Lidong Chen <lidong.chen@oracle.com>,
	ross.philipson@oracle.com
Subject: Re: [PATCH] lib/LzmaEnc: Validate 'len' before subtracting
Date: Tue, 10 Jun 2025 23:28:13 +0530	[thread overview]
Message-ID: <108faa16e09d71c22bde78ca460c5887@linux.ibm.com> (raw)
In-Reply-To: <20250610174742.3320770-1-lidong.chen@oracle.com>

On 2025-06-10 23:17, Lidong Chen via Grub-devel wrote:
> In LzmaEnc_CodeOneBlock(), both GetOptimumFast() and GetOptimum()
> returns a value of greater or equal to 1, which is assigned to
> 'len'. But since LZMA_MATCH_LEN_MIN == 2, 'len' should be validated
> before performing "len - LZMA_MATCH_LEN_MIN" to avoid underflow
> when 'len' equals to 1.
> 
> Fixed: CID 51508
> 
> Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
> ---
>  grub-core/lib/LzmaEnc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/grub-core/lib/LzmaEnc.c b/grub-core/lib/LzmaEnc.c
> index 52b331558..d74e96303 100644
> --- a/grub-core/lib/LzmaEnc.c
> +++ b/grub-core/lib/LzmaEnc.c
> @@ -1880,6 +1880,11 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p,
> Bool useLimits, UInt32 maxPackSize
>          UInt32 posSlot, lenToPosState;
>          RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
>          p->state = kMatchNextStates[p->state];
> +	if (len < LZMA_MATCH_LEN_MIN)
> +	  {
> +	    p->result = SZ_ERROR_DATA;
> +	    return CheckErrors(p);
> +	  }

Hi Lidong Chen,

please fix the indentation issue in if condition.

thanks,
sudhakar

>          LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN,
> posState, !p->fastMode, p->ProbPrices);
>          pos -= LZMA_NUM_REPS;
>          GetPosSlot(pos, posSlot);

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-10 17:47 [PATCH] lib/LzmaEnc: Validate 'len' before subtracting Lidong Chen via Grub-devel
2025-06-10 17:58 ` sudhakar [this message]
2025-06-10 18:13 ` Ross Philipson via Grub-devel
2025-06-11  1:19   ` Lidong Chen via Grub-devel

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=108faa16e09d71c22bde78ca460c5887@linux.ibm.com \
    --to=sudhakar@linux.ibm.com \
    --cc=daniel.kiper@oracle.com \
    --cc=grub-devel@gnu.org \
    --cc=lidong.chen@oracle.com \
    --cc=ross.philipson@oracle.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.