public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gao, Liming" <liming.gao@intel.com>
To: "Song, BinX" <binx.song@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [PATCH] MdeModulePkg: Fix BrotliCustomDecompressLib potential issue
Date: Wed, 12 Apr 2017 06:31:33 +0000	[thread overview]
Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D71D395@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <559D2DF22BC9A3468B4FA1AA547F0EF10255AC9B@shsmsx102.ccr.corp.intel.com>

Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: Song, BinX
>Sent: Friday, April 07, 2017 2:52 PM
>To: edk2-devel@lists.01.org
>Cc: Gao, Liming <liming.gao@intel.com>
>Subject: [PATCH] MdeModulePkg: Fix BrotliCustomDecompressLib potential
>issue
>
>- Fix BrotliCustomDecompressLib potential issue
>
>Cc: Liming Gao <liming.gao@intel.com>
>Contributed-under: TianoCore Contribution Agreement 1.0
>Signed-off-by: Bell Song <binx.song@intel.com>
>---
> .../Library/BrotliCustomDecompressLib/BrotliDecompress.c     |  1 +
> MdeModulePkg/Library/BrotliCustomDecompressLib/dec/decode.c  | 12
>++++++++----
> 2 files changed, 9 insertions(+), 4 deletions(-)
>
>diff --git
>a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c
>b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c
>index 2c2648a..a303921 100644
>---
>a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c
>+++
>b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c
>@@ -126,6 +126,7 @@ BrotliDecompress (
>   BrotliState *  BroState;
>   VOID *         Temp;
>
>+  TotalOut = 0;
>   AvailableOut = FILE_BUFFER_SIZE;
>   Result = BROTLI_RESULT_ERROR;
>   BroState = BrotliCreateState(BrAlloc, BrFree, BuffInfo);
>diff --git
>a/MdeModulePkg/Library/BrotliCustomDecompressLib/dec/decode.c
>b/MdeModulePkg/Library/BrotliCustomDecompressLib/dec/decode.c
>index 1ebab3c..c49fab9 100644
>--- a/MdeModulePkg/Library/BrotliCustomDecompressLib/dec/decode.c
>+++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/dec/decode.c
>@@ -802,6 +802,7 @@ static BROTLI_INLINE uint32_t ReadBlockLength(const
>HuffmanCode* table,
>   uint32_t code;
>   uint32_t nbits;
>   code = ReadSymbol(table, br);
>+  if (code >= BROTLI_NUM_BLOCK_LEN_SYMBOLS) code =
>BROTLI_NUM_BLOCK_LEN_SYMBOLS - 1;
>   nbits = kBlockLengthPrefixCode[code].nbits; /* nbits == 2..24 */
>   return kBlockLengthPrefixCode[code].offset + BrotliReadBits(br, nbits);
> }
>@@ -872,13 +873,13 @@ static BROTLI_NOINLINE void
>InverseMoveToFrontTransform(
>   for (i = 0; i < v_len; ++i) {
>     int index = v[i];
>     uint8_t value = mtf[index];
>-    upper_bound |= v[i];
>+    upper_bound |= (uint32_t)v[i];
>     v[i] = value;
>     mtf[-1] = value;
>-    do {
>+    while (index > 0) {
>       index--;
>       mtf[index + 1] = mtf[index];
>-    } while (index >= 0);
>+    }
>   }
>   /* Remember amount of elements to be reinitialized. */
>   state->mtf_upper_bound = upper_bound;
>@@ -1498,6 +1499,7 @@ static BROTLI_INLINE BROTLI_BOOL
>ReadCommandInternal(
>       return BROTLI_FALSE;
>     }
>   }
>+  if (cmd_code >= BROTLI_NUM_COMMAND_SYMBOLS) cmd_code =
>BROTLI_NUM_COMMAND_SYMBOLS - 1;
>   v = kCmdLut[cmd_code];
>   s->distance_code = v.distance_code;
>   s->distance_context = v.context;
>@@ -2209,7 +2211,9 @@ BrotliDecoderResult
>BrotliDecoderDecompressStream(
>         }
>         s->max_distance = s->max_backward_distance;
>         if (s->state == BROTLI_STATE_COMMAND_POST_WRITE_1) {
>-          memcpy(s->ringbuffer, s->ringbuffer_end, (size_t)s->pos);
>+          if (s->ringbuffer != 0) {
>+            memcpy(s->ringbuffer, s->ringbuffer_end, (size_t)s->pos);
>+          }
>           if (s->meta_block_remaining_len == 0) {
>             /* Next metablock, if any */
>             s->state = BROTLI_STATE_METABLOCK_DONE;
>--
>2.10.2.windows.1



      reply	other threads:[~2017-04-12  6:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-07  6:52 [PATCH] MdeModulePkg: Fix BrotliCustomDecompressLib potential issue Song, BinX
2017-04-12  6:31 ` Gao, Liming [this message]

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-list 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=4A89E2EF3DFEDB4C8BFDE51014F606A14D71D395@shsmsx102.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /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