From: Pierre-Anthony Lemieux <pal@sandflow.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 2/3] avcodec/jpeg2000htdec: Consolidate jpeg2000 spec bits in jpeg2000_bitbuf_refill_backwards()
Date: Fri, 4 Aug 2023 18:41:24 -0700
Message-ID: <CAF_7JxBCTq3N_-LMQEpdnbtzQNHAjzq9xp8Z6b8Ede+bENqFYQ@mail.gmail.com> (raw)
In-Reply-To: <20230802000135.26482-2-michael@niedermayer.cc>
On Tue, Aug 1, 2023 at 5:02 PM Michael Niedermayer
<michael@niedermayer.cc> wrote:
>
> Code should make more sense now
>
> Fixes: out of array access
> Fixes: 58299/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6627570448465920
>
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
> libavcodec/jpeg2000htdec.c | 13 +++----------
> 1 file changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
> index 2b082b3b2f..3985783f3a 100644
> --- a/libavcodec/jpeg2000htdec.c
> +++ b/libavcodec/jpeg2000htdec.c
> @@ -159,21 +159,14 @@ static int jpeg2000_bitbuf_refill_backwards(StateVars *buffer, const uint8_t *ar
> */
> position -= 4;
Can't we get rid of this line and the comment above, and instead
replace `int32_t position = buffer->pos;` with `int32_t position =
buffer->pos - 4;`?
LGTM otherwise.
>
> - tmp = AV_RB32(&array[position + 1]);
> -
> - if (buffer->pos < 4){
> - /* mask un-needed bits if we are close to input end */
> - uint64_t mask = (1ull << (buffer->pos + 1) * 8) - 1;
> - tmp &= mask;
> - }
> -
> /**
> * Unstuff bits. Load a temporary byte, which precedes the position we
> * currently at, to ensure that we can also un-stuff if the stuffed bit is
> * the bottom most bits.
> */
> - tmp <<= 8;
> - tmp |= array[buffer->pos + 1];
> +
> + for(int i = FFMAX(0, position + 1); i <= buffer->pos + 1; i++)
> + tmp = 256*tmp + array[i];
>
> if ((tmp & 0x7FFF000000) > 0x7F8F000000) {
> tmp &= 0x7FFFFFFFFF;
> --
> 2.17.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-08-05 1:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-02 0:01 [FFmpeg-devel] [PATCH 1/3] avcodec/jpeg2000htdec: Avoid freeing uninitialized pointers in ff_jpeg2000_decode_htj2k() Michael Niedermayer
2023-08-02 0:01 ` [FFmpeg-devel] [PATCH 2/3] avcodec/jpeg2000htdec: Consolidate jpeg2000 spec bits in jpeg2000_bitbuf_refill_backwards() Michael Niedermayer
2023-08-05 1:41 ` Pierre-Anthony Lemieux [this message]
2023-08-05 15:52 ` Michael Niedermayer
2023-08-02 0:01 ` [FFmpeg-devel] [PATCH 3/3] avcodec/jpeg2000htdec: Check m Michael Niedermayer
2023-08-05 1:19 ` Pierre-Anthony Lemieux
2023-08-05 16:30 ` Michael Niedermayer
2023-08-06 16:28 ` Pierre-Anthony Lemieux
2023-08-11 0:04 ` Pierre-Anthony Lemieux
2023-08-03 8:20 ` [FFmpeg-devel] [PATCH 1/3] avcodec/jpeg2000htdec: Avoid freeing uninitialized pointers in ff_jpeg2000_decode_htj2k() Tomas Härdin
2023-08-03 15:36 ` Michael Niedermayer
2023-08-03 20:50 ` Tomas Härdin
2023-08-03 20:58 ` Pierre-Anthony Lemieux
2023-08-04 3:36 ` Caleb Etemesi
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=CAF_7JxBCTq3N_-LMQEpdnbtzQNHAjzq9xp8Z6b8Ede+bENqFYQ@mail.gmail.com \
--to=pal@sandflow.com \
--cc=ffmpeg-devel@ffmpeg.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
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git