Before
9b3c46a081a9f01559082bf7a154fc6be1e06c18 every call to
ff_jpegls_decode_picture() allocated and freed a JLSState. This commit
instead put said structure into the context of the JPEG-LS decoder to
avoid said allocation. But said function can also be called from other
MJPEG-based decoders and their contexts doesn't contain said structure,
leading to segfaults. This commit fixes this: The JLSState is now
allocated on the first call to ff_jpegls_decode_picture() and stored in
the context.
Found-by: Michael Niedermayer <michael@niedermayer.cc>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-typedef struct JpegLSDecodeContext {
- MJpegDecodeContext mjpeg;
- JLSState state;
-} JpegLSDecodeContext;
-
/**
* Decode LSE block with initialization parameters
*/
/**
* Decode LSE block with initialization parameters
*/
{
int i, t = 0;
uint8_t *zero, *last, *cur;
{
int i, t = 0;
uint8_t *zero, *last, *cur;
- JLSState *const state = &((JpegLSDecodeContext*)s)->state;
+ JLSState *state = s->jls_state;
int off = 0, stride = 1, width, shift, ret = 0;
int decoded_height = 0;
int off = 0, stride = 1, width, shift, ret = 0;
int decoded_height = 0;
+ if (!state) {
+ state = av_malloc(sizeof(*state));
+ if (!state)
+ return AVERROR(ENOMEM);
+ s->jls_state = state;
+ }
zero = av_mallocz(s->picture_ptr->linesize[0]);
if (!zero)
return AVERROR(ENOMEM);
zero = av_mallocz(s->picture_ptr->linesize[0]);
if (!zero)
return AVERROR(ENOMEM);
.long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_JPEGLS,
.long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_JPEGLS,
- .priv_data_size = sizeof(JpegLSDecodeContext),
+ .priv_data_size = sizeof(MJpegDecodeContext),
.init = ff_mjpeg_decode_init,
.close = ff_mjpeg_decode_end,
.receive_frame = ff_mjpeg_receive_frame,
.init = ff_mjpeg_decode_init,
.close = ff_mjpeg_decode_end,
.receive_frame = ff_mjpeg_receive_frame,
reset_icc_profile(s);
av_freep(&s->hwaccel_picture_private);
reset_icc_profile(s);
av_freep(&s->hwaccel_picture_private);
+ av_freep(&s->jls_state);
typedef struct MJpegDecodeContext {
AVClass *class;
AVCodecContext *avctx;
typedef struct MJpegDecodeContext {
AVClass *class;
AVCodecContext *avctx;
enum AVPixelFormat hwaccel_sw_pix_fmt;
enum AVPixelFormat hwaccel_pix_fmt;
void *hwaccel_picture_private;
enum AVPixelFormat hwaccel_sw_pix_fmt;
enum AVPixelFormat hwaccel_pix_fmt;
void *hwaccel_picture_private;
+ struct JLSState *jls_state;
} MJpegDecodeContext;
int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table,
} MJpegDecodeContext;
int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table,