History

avcodec/jpeg2000htdec: Check magp before using it in a shift

Fixes: shift exponent -1 is negative Fixes: 65378/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5457678193197056

Michael Niedermayer committed 2 years ago

Commit 19ad05e1 parent 63f56c91 file · +12 −4Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/jpeg2000dec.c+12−4
@@ -1886,7 +1886,7 @@ static inline void roi_scale_cblk(Jpeg2000Cblk *cblk, · 1885 unmodified lines
18861886 }
18871887 }
18881888
1889−static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
1889+static inline int tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
18901890 {
18911891 Jpeg2000T1Context t1;
18921892
@@ -1911,6 +1911,8 @@ static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile · 18 unmodified lines
19111911 int nb_precincts, precno;
19121912 Jpeg2000Band *band = rlevel->band + bandno;
19131913 int cblkno = 0, bandpos;
1914+ /* See Rec. ITU-T T.800, Equation E-2 */
1915+ int magp = quantsty->expn[subbandno] + quantsty->nguardbits - 1;
19141916
19151917 bandpos = bandno + (reslevelno > 0);
19161918
@@ -1918,6 +1920,11 @@ static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile · 1 unmodified line
19181920 band->coord[1][0] == band->coord[1][1])
19191921 continue;
19201922
1923+ if ((codsty->cblk_style & JPEG2000_CTSY_HTJ2K_F) && magp >= 31) {
1924+ avpriv_request_sample(s->avctx, "JPEG2000_CTSY_HTJ2K_F and magp >= 31");
1925+ return AVERROR_PATCHWELCOME;
1926+ }
1927+
19211928 nb_precincts = rlevel->num_precincts_x * rlevel->num_precincts_y;
19221929 /* Loop on precincts */
19231930 for (precno = 0; precno < nb_precincts; precno++) {
@@ -1928,8 +1935,6 @@ static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile · 4 unmodified lines
19281935 cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height;
19291936 cblkno++) {
19301937 int x, y, ret;
1931− /* See Rec. ITU-T T.800, Equation E-2 */
1932− int magp = quantsty->expn[subbandno] + quantsty->nguardbits - 1;
19331938
19341939 Jpeg2000Cblk *cblk = prec->cblk + cblkno;
19351940
@@ -1969,6 +1974,7 @@ static inline void tile_codeblocks(const Jpeg2000DecoderContext *s, Jpeg2000Tile · 33 unmodified lines
19691974 ff_dwt_decode(&comp->dwt, codsty->transform == FF_DWT97 ? (void*)comp->f_data : (void*)comp->i_data);
19701975
19711976 } /*end comp */
1977+ return 0;
19721978 }
19731979
19741980 #define WRITE_FRAME(D, PIXEL) \
@@ -2045,7 +2051,9 @@ static int jpeg2000_decode_tile(AVCodecContext *avctx, void *td, · 70 unmodified lines
20452051 AVFrame *picture = td;
20462052 Jpeg2000Tile *tile = s->tile + jobnr;
20472053
2048− tile_codeblocks(s, tile);
2054+ int ret = tile_codeblocks(s, tile);
2055+ if (ret < 0)
2056+ return ret;
20492057
20502058 /* inverse MCT transformation */
20512059 if (tile->codsty[0].mct)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t