From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id E321C4DF5D for ; Thu, 8 Jan 2026 17:45:44 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'oycfAxVHwZYscpyNS2jsiJ2l6AxFCQB7+fY9soOjCw8=', expected b'dmXHxtYASA7lsEHvLqW8FWR8CTZwgD+ISsAiOuhi0vs=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1767894331; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=oycfAxVHwZYscpyNS2jsiJ2l6AxFCQB7+fY9soOjCw8=; b=0UvTjgZlCFvCvZgan9RVEYslZFh9nKECAYVQ9P9+8qp8FyYwds6i9TK+3Is32GR0wBDGM MemlAIHlwR8A2CxAYbllyzDrIwISR+06X+CqoJSE3WMUMbJ4UDdOcHXY9g/P5scjpwFeHNP Y1YDBaoPz+Xiqdt5V72UHiVd6VQiSumNInHamCieOjo+kJos4AT8q2QuW/S16x3JsnBIkXT p46Vbths7NxU4lr6VznjY+phLdpw4Tiq8Avp8Rn5hhlAYtc1b/ploHs9SooLX4uPrqucoQL DAlo6UlQ07sf+VhoRXJx5Hs4j1lzXEM8ryj4Fn8LyUfDXOC2Pbka6UfpVP5g== Received: from [172.20.0.4] (unknown [172.20.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id B29A7690D7B; Thu, 8 Jan 2026 19:45:31 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1767894316; b=uH5jKSyZ7bETNwuWLWXY4vo3jSwEnUSJ/ieLtTAcmjS+Gka2B/l6N6H4lTKX9Dh/n3tTc vL0d6u2w5Fnt/ExF3luQDXsyjfLjMDCR4lPLdfrD3N156+MuodmJReEB2ifJsGN2wJOzhbu fGVZG3bfk6IeQQTRE4v2LwwHarSX899mr/7piOzlom0Ajy824WSR+o0JGzh9GuPG3jMDli/ QCEXQe3S1f+9TwuLCPtbFkKZgUj8k69NmEaKPQSUIvwx5nhBp2Q4tO1WOq/KdRZFIbFFuv4 +Zk7F1xkgnn9Xpy+Pjzy5CuB5S3NlSogPWO0zU24+yi7OtdTjF4w+UKb+H1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1767894316; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=N7bjZzBR2khtDI8C6VZ2plE7WHpH+w4Bgpr2MLX40ew=; b=GzZOuqGaILcSNhylhz96JOHk+QgXQCY53+OxzB4DYXbEC4d1T2utIO1cNTDROdY/skZ1m YOszRH40EbCjkRtMmsJ1rSVgfjf8wnSd1KVMvo8vG8APZDIdE+nzjrd2bmdzYjK79MXGZFD EEZbThxX5V88oXbmKx7/rIfDmcEXu9uJNg50M+F7AP//IJWd6YP/hHMcv9j5MPbj9rUJe99 KL2XkUvpqrGxDV9d0XveWR7aFeCJVlaUJ7pS+eawriB2f95xhPFcBLiYOHvaJxna5ich5dF cceubxQLIS8Se1FBDtIid/sePRcsbnefNxN5HsrZMZ0O/5BXDqSAVsKKssBA== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1767894308; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=dmXHxtYASA7lsEHvLqW8FWR8CTZwgD+ISsAiOuhi0vs=; b=N05mEowXoaKtYEcgp1/CB0HpR4IalB7J6p1bzqnKs8Eblxrl3MiszCkevhGn0pjUeUFz9 UB1kuaCMFDTl/ubd6NDFSWZuXM1bAn4KuRMia+jsNmtVsa7w4QYCBuGoGXY81S65tSH078/ ri7s0Mn68VG+dkDik3Np0XMrOuuiTlGWfzU8Oix79mqicwVwC/Q0Sqn3tsCd2kcLno2iGpB cFoVFMNYYxPNUwZHeLR8BY0WIP8PtbfTcKBhOpFqBRBmDGhXZKq8isRHn7U+JHdg8zOOI81 L0e1Td3PmmHFiEAHMSpjlvuO9DTsmbIADYTcN3nOz0dGs485gKNHANwrZ6eg== Received: from f7c34508609e (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 803E3690D35 for ; Thu, 8 Jan 2026 19:45:08 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Thu, 08 Jan 2026 17:45:08 -0000 Message-ID: <176789430867.25.13450705881552954027@4457048688e7> Message-ID-Hash: NJXBMCM46FQDSP52QUXZD4TVGWF5VP52 X-Message-ID-Hash: NJXBMCM46FQDSP52QUXZD4TVGWF5VP52 X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PR] avcodec/jpeg2000dec: Fix M_b=31 and bpno = "-1" (PR #21413) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: michaelni via ffmpeg-devel Cc: michaelni Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21413 opened by michaelni URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21413 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21413.patch >>From fed570770877974aecb2ad2e5bfa51d659ed3276 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 8 Jan 2026 15:09:18 +0100 Subject: [PATCH 1/4] avcodec/jpeg2000dec: Print M_b value when asking for a sample Signed-off-by: Michael Niedermayer --- libavcodec/jpeg2000dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 276c0a6e43..c3be434d3a 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -2271,7 +2271,7 @@ static inline int tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile continue; if (M_b >= 31) { - avpriv_request_sample(s->avctx, "M_b >= 31"); + avpriv_request_sample(s->avctx, "M_b (%d) > 31", M_b); return AVERROR_PATCHWELCOME; } -- 2.49.1 >>From bfe7f5b4b31ee9a2cc37cd5c1a8d1b7009c984cf Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 8 Jan 2026 15:11:00 +0100 Subject: [PATCH 2/4] avcodec/jpeg2000dec: Print bpno level when erroring out Signed-off-by: Michael Niedermayer --- libavcodec/jpeg2000dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index c3be434d3a..583e85b712 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -2044,7 +2044,7 @@ static int decode_cblk(const Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *cod while (passno--) { if (bpno < 0 || bpno > 29) { - av_log(s->avctx, AV_LOG_ERROR, "bpno became invalid\n"); + av_log(s->avctx, AV_LOG_ERROR, "bpno (%d) became invalid\n", bpno); return AVERROR_INVALIDDATA; } switch(pass_t) { -- 2.49.1 >>From b9275a51326300e38a78d6c1aa1ee5cd51d7e825 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 8 Jan 2026 15:12:14 +0100 Subject: [PATCH 3/4] avcodec/jpeg2000dec: allow M_b == 31 Signed-off-by: Michael Niedermayer --- libavcodec/jpeg2000dec.c | 4 ++-- libavcodec/jpeg2000htdec.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 583e85b712..de548641d5 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -2100,7 +2100,7 @@ static int decode_cblk(const Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *cod for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int32_t sign, n, val; - const uint32_t mask = UINT32_MAX >> (M_b + 1); // bit mask for ROI detection + const uint32_t mask = (UINT32_MAX >> M_b) >> 1; // bit mask for ROI detection n = x + (y * t1->stride); val = t1->data[n]; @@ -2270,7 +2270,7 @@ static inline int tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile band->coord[1][0] == band->coord[1][1]) continue; - if (M_b >= 31) { + if (M_b > 31) { avpriv_request_sample(s->avctx, "M_b (%d) > 31", M_b); return AVERROR_PATCHWELCOME; } diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c index 54b37009c2..b92f0131a4 100644 --- a/libavcodec/jpeg2000htdec.c +++ b/libavcodec/jpeg2000htdec.c @@ -1219,7 +1219,7 @@ ff_jpeg2000_decode_htj2k(const Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c uint8_t *block_states = NULL; int32_t n, val; // Post-processing - const uint32_t mask = UINT32_MAX >> (M_b + 1); // bit mask for ROI detection + const uint32_t mask = (UINT32_MAX >> M_b) >> 1; // bit mask for ROI detection uint8_t num_rempass; -- 2.49.1 >>From 635916108731e63d05c00d0f8adfd40f4684b74f Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 8 Jan 2026 15:13:05 +0100 Subject: [PATCH 4/4] avcodec/jpeg2000dec: allow bpno of -1 Fixes: tickets/4663/levels30.jp2 The file decodes without error messages and no integer overflows The file before the broader M_b check did decode with error messages and integer overflows but also no visual artifacts Signed-off-by: Michael Niedermayer --- libavcodec/jpeg2000dec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index de548641d5..3572751429 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -1900,7 +1900,7 @@ static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bpno, int bandno, int vert_causal_ctx_csty_symbol) { - int mask = 3 << (bpno - 1), y0, x, y; + int mask = (3u << bpno)>>1, y0, x, y; for (y0 = 0; y0 < height; y0 += 4) for (x = 0; x < width; x++) @@ -1933,7 +1933,7 @@ static void decode_refpass(Jpeg2000T1Context *t1, int width, int height, int phalf; int y0, x, y; - phalf = 1 << (bpno - 1); + phalf = 1 << bpno; for (y0 = 0; y0 < height; y0 += 4) for (x = 0; x < width; x++) @@ -1942,11 +1942,11 @@ static void decode_refpass(Jpeg2000T1Context *t1, int width, int height, int flags_mask = (vert_causal_ctx_csty_symbol && y == y0 + 3) ? ~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE | JPEG2000_T1_SGN_S) : -1; int ctxno = ff_jpeg2000_getrefctxno(t1->flags[(y + 1) * t1->stride + x + 1] & flags_mask); - t1->data[(y) * t1->stride + x] |= phalf; + t1->data[(y) * t1->stride + x] |= phalf >> 1; if (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno)) - t1->data[(y) * t1->stride + x] |= phalf << 1; + t1->data[(y) * t1->stride + x] |= phalf; else { - t1->data[(y) * t1->stride + x] &= ~(phalf << 1); + t1->data[(y) * t1->stride + x] &= ~(phalf); } t1->flags[(y + 1) * t1->stride + x + 1] |= JPEG2000_T1_REF; @@ -2043,7 +2043,7 @@ static int decode_cblk(const Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *cod ff_mqc_initdec(&t1->mqc, cblk->data, 0, 1); while (passno--) { - if (bpno < 0 || bpno > 29) { + if (bpno < -1 || bpno > 29) { av_log(s->avctx, AV_LOG_ERROR, "bpno (%d) became invalid\n", bpno); return AVERROR_INVALIDDATA; } -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org