From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id B8B9A45CB0 for ; Sun, 2 Apr 2023 22:17:53 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F47868BE6F; Mon, 3 Apr 2023 01:17:51 +0300 (EEST) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3A61E68BD00 for ; Mon, 3 Apr 2023 01:17:45 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 87C2EE0003 for ; Sun, 2 Apr 2023 22:17:44 +0000 (UTC) Date: Mon, 3 Apr 2023 00:17:43 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20230402221743.GQ1164690@pb2> References: <20230331152941.21879-1-pal@sandflow.com> <20230331152941.21879-2-pal@sandflow.com> MIME-Version: 1.0 In-Reply-To: <20230331152941.21879-2-pal@sandflow.com> Subject: Re: [FFmpeg-devel] [PATCH v1 2/3] avcodec/jpeg2000dec: add support for HTJ2K block decoding X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: multipart/mixed; boundary="===============9103981639979661685==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============9103981639979661685== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="xYeFQzU4VZLrHqxU" Content-Disposition: inline --xYeFQzU4VZLrHqxU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Mar 31, 2023 at 08:29:40AM -0700, pal@sandflow.com wrote: > From: caleb [...] > @@ -1113,8 +1117,29 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderC= ontext *s, Jpeg2000Tile *tile, > } > } > =20 > - if ((ret =3D get_bits(s, av_log2(newpasses1) + cblk->lbl= ock)) < 0) > - return ret; > + if (newpasses > 1 && s->is_htj2k) { > + // Retrieve pass lengths for each pass > + int href_passes =3D (cblk->npasses + newpasses - 1)= % 3; > + int segment_passes =3D newpasses - href_passes; > + int pass_bound =3D 2; > + int eb =3D 0; > + int extra_bit =3D newpasses > 2 ? 1 : 0; > + while (pass_bound <=3Dsegment_passes) { > + eb++; > + pass_bound +=3Dpass_bound; > + } something with av_log2() should be able to do this simpler [...] > +/** > + * Drops bits from lower bits in the bit buffer. buf contains the bit bu= ffers. > + * nbits is the number of bits to remove. > + */ > +av_always_inline > +static void jpeg2000_bitbuf_drop_bits_lsb(StateVars *buf, uint8_t nbits) > +{ > + if (buf->bits_left < nbits) { > + av_log(NULL, AV_LOG_ERROR, "Invalid bit read of %d, bits in buff= er are %d\n", nbits, buf->bits_left); > + av_assert0(0); [...] > +int > +ff_jpeg2000_decode_htj2k(const Jpeg2000DecoderContext *s, Jpeg2000Coding= Style *codsty, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, > + int width, int height, int magp, uint8_t roi_sh= ift) > +{ > + uint8_t p0 =3D 0; // Number of placeholder passes > + uint32_t Lcup; // Length of HT cleanup segment > + uint32_t Lref; // Length of Refinement segment > + uint32_t Scup; // HT cleanup segment suffix length > + uint32_t Pcup; // HT cleanup segment prefix length > + > + uint8_t S_blk; // Number of skipped magnitude bitplanes > + uint8_t pLSB; > + > + uint8_t *Dcup; // Byte of an HT cleanup segment > + uint8_t *Dref; // Byte of an HT refinement segment > + > + int z_blk; // Number of ht coding pass > + > + uint8_t empty_passes; > + > + StateVars mag_sgn; // Magnitude and Sign > + StateVars mel; // Adaptive run-length coding > + StateVars vlc; // Variable Length coding > + StateVars sig_prop; // Significance propagation > + > + MelDecoderState mel_state; > + > + int ret; > + > + /* Temporary buffers */ > + int32_t *sample_buf; > + uint8_t *block_states; > + > + int32_t n, val; // Post-processing > + > + int32_t M_b =3D magp; > + av_assert0(width <=3D 1024U && height <=3D 1024U); > + av_assert0(width * height <=3D 4096); > + av_assert0(width * height > 0); Has this decoder been tested with some fuzzer ? I see a bunch of asserts in it and i dont immedeatly see what would prevent= them from triggering thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB "I am not trying to be anyone's saviour, I'm trying to think about the future and not be sad" - Elon Musk --xYeFQzU4VZLrHqxU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZCn/AwAKCRBhHseHBAsP q8D4AKCMNo+kRVBgJy9xEqfwxbC/j6fIpgCfS78UYal30T27RF++yWxRCqqIKig= =hzNw -----END PGP SIGNATURE----- --xYeFQzU4VZLrHqxU-- --===============9103981639979661685== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============9103981639979661685==--