Re: [FFmpeg-devel] [PATCH] avcodec/jpeg2000dec: fix HT block decoder issue #10905

2024-05-18 Thread Michael Niedermayer
On Fri, May 17, 2024 at 08:00:16PM +, WATANABE Osamu wrote:
> Signed-off-by: Pierre-Anthony Lemieux 
> ---
> libavcodec/jpeg2000htdec.c   | 122 ---
> tests/ref/fate/jpeg2000dec-ds0_ht_01_b11 |   2 +-
> 2 files changed, 63 insertions(+), 61 deletions(-)
> 
> diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
> index fa704b665e..62f70c32a8 100644
> --- a/libavcodec/jpeg2000htdec.c
> +++ b/libavcodec/jpeg2000htdec.c
> @@ -196,7 +196,7 @@ static void jpeg2000_bitbuf_refill_forward(StateVars 
> *buffer, const uint8_t *arr
> while (buffer->bits_left < 32) {
> buffer->tmp = 0xFF;
> buffer->bits = (buffer->last == 0xFF) ? 7 : 8;
> -if (buffer->pos <= length) {
> +if (buffer->pos < length) {
> buffer->tmp = array[buffer->pos];
> buffer->pos += 1;
> buffer->last = buffer->tmp;
> @@ -508,17 +508,17 @@ static int jpeg2000_decode_sig_emb(const 
> Jpeg2000DecoderContext *s, MelDecoderSt
> }
> 
> av_always_inline
> -static int jpeg2000_get_state(int x1, int x2, int width, int shift_by,
> +static int jpeg2000_get_state(int x1, int x2, int stride, int shift_by,

the first whitespace seems to have been lost this makes git reject the patch

Applying: avcodec/jpeg2000dec: fix HT block decoder issue #10905
error: corrupt patch at line 20
error: could not build fake ancestor

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What does censorship reveal? It reveals fear. -- Julian Assange


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avcodec/jpeg2000dec: fix HT block decoder issue #10905

2024-05-17 Thread WATANABE Osamu
Signed-off-by: Pierre-Anthony Lemieux 
---
libavcodec/jpeg2000htdec.c   | 122 ---
tests/ref/fate/jpeg2000dec-ds0_ht_01_b11 |   2 +-
2 files changed, 63 insertions(+), 61 deletions(-)

diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
index fa704b665e..62f70c32a8 100644
--- a/libavcodec/jpeg2000htdec.c
+++ b/libavcodec/jpeg2000htdec.c
@@ -196,7 +196,7 @@ static void jpeg2000_bitbuf_refill_forward(StateVars 
*buffer, const uint8_t *arr
while (buffer->bits_left < 32) {
buffer->tmp = 0xFF;
buffer->bits = (buffer->last == 0xFF) ? 7 : 8;
-if (buffer->pos <= length) {
+if (buffer->pos < length) {
buffer->tmp = array[buffer->pos];
buffer->pos += 1;
buffer->last = buffer->tmp;
@@ -508,17 +508,17 @@ static int jpeg2000_decode_sig_emb(const 
Jpeg2000DecoderContext *s, MelDecoderSt
}

av_always_inline
-static int jpeg2000_get_state(int x1, int x2, int width, int shift_by,
+static int jpeg2000_get_state(int x1, int x2, int stride, int shift_by,
  const uint8_t *block_states)
{
-return (block_states[(x1 + 1) * (width + 2) + (x2 + 1)] >> shift_by) & 1;
+return (block_states[(x1 + 1) * stride + (x2 + 1)] >> shift_by) & 1;
}

av_always_inline
-static void jpeg2000_modify_state(int x1, int x2, int width,
- int value, uint8_t *block_states)
+static void jpeg2000_modify_state(int x1, int x2, int stride,
+  int value, uint8_t *block_states)
{
-block_states[(x1 + 1) * (width + 2) + (x2 + 1)] |= value;
+block_states[(x1 + 1) * stride + (x2 + 1)] |= value;
}

av_always_inline
@@ -528,8 +528,8 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
  StateVars *mel_stream, StateVars 
*vlc_stream,
  StateVars *mag_sgn_stream, const 
uint8_t *Dcup,
  uint32_t Lcup, uint32_t Pcup, 
uint8_t pLSB,
-  int width, int height, int32_t 
*sample_buf,
-  uint8_t *block_states)
+  int width, int height, const int 
stride,
+  int32_t *sample_buf, uint8_t 
*block_states)
{
uint16_t q  = 0; // Represents current quad position
uint16_t q1, q2;
@@ -958,32 +958,32 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
j1 = 2 * y;
j2 = 2 * x;

-sample_buf[j2 + (j1 * width)] = (int32_t)*mu;
-jpeg2000_modify_state(j1, j2, width, *sigma, block_states);
+sample_buf[j2 + (j1 * stride)] = (int32_t)*mu;
+jpeg2000_modify_state(j1, j2, stride, *sigma, block_states);
sigma += 1;
mu += 1;

x1 = y != quad_height - 1 || is_border_y == 0;
-sample_buf[j2 + ((j1 + 1) * width)] = ((int32_t)*mu) * x1;
-jpeg2000_modify_state(j1 + 1, j2, width, (*sigma) * x1, 
block_states);
+sample_buf[j2 + ((j1 + 1) * stride)] = ((int32_t)*mu) * x1;
+jpeg2000_modify_state(j1 + 1, j2, stride, (*sigma) * x1, 
block_states);
sigma += 1;
mu += 1;

x2 = x != quad_width - 1 || is_border_x == 0;
-sample_buf[(j2 + 1) + (j1 * width)] = ((int32_t)*mu) * x2;
-jpeg2000_modify_state(j1, j2 + 1, width, (*sigma) * x2, 
block_states);
+sample_buf[(j2 + 1) + (j1 * stride)] = ((int32_t)*mu) * x2;
+jpeg2000_modify_state(j1, j2 + 1, stride, (*sigma) * x2, 
block_states);
sigma += 1;
mu += 1;

x3 = x1 | x2;
-sample_buf[(j2 + 1) + (j1 + 1) * width] = ((int32_t)*mu) * x3;
-jpeg2000_modify_state(j1 + 1, j2 + 1, width, (*sigma) * x3, 
block_states);
+sample_buf[(j2 + 1) + (j1 + 1) * stride] = ((int32_t)*mu) * x3;
+jpeg2000_modify_state(j1 + 1, j2 + 1, stride, (*sigma) * x3, 
block_states);
sigma += 1;
mu += 1;
}
}
ret = 1;
-free:
+free:
av_freep(_n);
av_freep();
av_freep(_n);
@@ -992,39 +992,39 @@ free:

static void jpeg2000_calc_mbr(uint8_t *mbr, const uint16_t i, const uint16_t j,
  const uint32_t mbr_info, uint8_t causal_cond,
-  uint8_t *block_states, int width)
+  uint8_t *block_states, int stride)
{
int local_mbr = 0;

-local_mbr |= jpeg2000_get_state(i - 1, j - 1, width, HT_SHIFT_SIGMA, 
block_states);
-local_mbr |= jpeg2000_get_state(i - 1, j + 0, width, HT_SHIFT_SIGMA, 
block_states);
-local_mbr |= jpeg2000_get_state(i - 1, j + 1, width, HT_SHIFT_SIGMA, 
block_states);
+local_mbr |= jpeg2000_get_state(i - 1, j