Up until now, the SpeedHQ encoder called a wrong function for init: void ff_init_uni_ac_vlc(const uint8_t huff_size_ac[256], uint8_t *uni_ac_vlc_len); Yet the first argument actually used is of type RLTable; the size of said struct is less than 256 if the size of a pointer is four, leading to an access beyond the end of the RLTable. This commit fixes this by calling the actually intended function: init_uni_ac_vlc() from mpeg12enc.c. It was intended to use this function [1], yet doing so was forgotten when the patch was actually applied. [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-July/266187.html
Unified · Split
| @@ -626,7 +626,7 @@ OBJS-$(CONFIG_SONIC_DECODER) += sonic.o · 625 unmodified lines | ||
| 626 | 626 | OBJS-$(CONFIG_SONIC_ENCODER) += sonic.o |
| 627 | 627 | OBJS-$(CONFIG_SONIC_LS_ENCODER) += sonic.o |
| 628 | 628 | OBJS-$(CONFIG_SPEEDHQ_DECODER) += speedhq.o mpeg12.o mpeg12data.o simple_idct.o |
| 629 | −OBJS-$(CONFIG_SPEEDHQ_ENCODER) += speedhq.o mpeg12data.o speedhqenc.o | |
| 629 | +OBJS-$(CONFIG_SPEEDHQ_ENCODER) += speedhq.o mpeg12data.o mpeg12enc.o speedhqenc.o | |
| 630 | 630 | OBJS-$(CONFIG_SP5X_DECODER) += sp5xdec.o |
| 631 | 631 | OBJS-$(CONFIG_SRGC_DECODER) += mscc.o |
| 632 | 632 | OBJS-$(CONFIG_SRT_DECODER) += srtdec.o ass.o htmlsubtitles.o |
| @@ -37,6 +37,7 @@ void ff_mpeg12_common_init(MpegEncContext *s); · 36 unmodified lines | ||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | void ff_init_2d_vlc_rl(RLTable *rl, unsigned static_size, int flags); |
| 40 | +void ff_mpeg1_init_uni_ac_vlc(const RLTable *rl, uint8_t *uni_ac_vlc_len); | |
| 40 | 41 | |
| 41 | 42 | static inline int decode_dc(GetBitContext *gb, int component) |
| 42 | 43 | { |
| @@ -27,6 +27,7 @@ · 26 unmodified lines | ||
| 27 | 27 | |
| 28 | 28 | #include <stdint.h> |
| 29 | 29 | |
| 30 | +#include "config.h" | |
| 30 | 31 | #include "libavutil/attributes.h" |
| 31 | 32 | #include "libavutil/avassert.h" |
| 32 | 33 | #include "libavutil/log.h" |
| @@ -44,6 +45,7 @@ · 11 unmodified lines | ||
| 44 | 45 | #include "mpegvideo.h" |
| 45 | 46 | #include "profiles.h" |
| 46 | 47 | |
| 48 | +#if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER | |
| 47 | 49 | static const uint8_t svcd_scan_offset_placeholder[] = { |
| 48 | 50 | 0x10, 0x0E, 0x00, 0x80, 0x81, 0x00, 0x80, |
| 49 | 51 | 0x81, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| @@ -64,8 +66,9 @@ static uint8_t mpeg1_index_run[2][64]; · 14 unmodified lines | ||
| 64 | 66 | static int8_t mpeg1_max_level[2][64]; |
| 65 | 67 | |
| 66 | 68 | #define A53_MAX_CC_COUNT 0x1f |
| 69 | +#endif /* CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER */ | |
| 67 | 70 | |
| 68 | −static av_cold void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len) | |
| 71 | +av_cold void ff_mpeg1_init_uni_ac_vlc(const RLTable *rl, uint8_t *uni_ac_vlc_len) | |
| 69 | 72 | { |
| 70 | 73 | int i; |
| 71 | 74 | |
| @@ -100,6 +103,7 @@ static av_cold void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len) · 28 unmodified lines | ||
| 100 | 103 | } |
| 101 | 104 | } |
| 102 | 105 | |
| 106 | +#if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER | |
| 103 | 107 | static int find_frame_rate_index(MpegEncContext *s) |
| 104 | 108 | { |
| 105 | 109 | int i; |
| @@ -1045,8 +1049,8 @@ static av_cold void mpeg12_encode_init_static(void) · 939 unmodified lines | ||
| 1045 | 1049 | mpeg1_index_run[0][i] = ff_rl_mpeg1.index_run[0][i]; |
| 1046 | 1050 | } |
| 1047 | 1051 | |
| 1048 | − init_uni_ac_vlc(&ff_rl_mpeg1, uni_mpeg1_ac_vlc_len); | |
| 1049 | − init_uni_ac_vlc(&ff_rl_mpeg2, uni_mpeg2_ac_vlc_len); | |
| 1052 | + ff_mpeg1_init_uni_ac_vlc(&ff_rl_mpeg1, uni_mpeg1_ac_vlc_len); | |
| 1053 | + ff_mpeg1_init_uni_ac_vlc(&ff_rl_mpeg2, uni_mpeg2_ac_vlc_len); | |
| 1050 | 1054 | |
| 1051 | 1055 | /* build unified dc encoding tables */ |
| 1052 | 1056 | for (int i = -255; i < 256; i++) { |
| @@ -1222,3 +1226,4 @@ AVCodec ff_mpeg2video_encoder = { · 169 unmodified lines | ||
| 1222 | 1226 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, |
| 1223 | 1227 | .priv_class = &mpeg2_class, |
| 1224 | 1228 | }; |
| 1229 | +#endif /* CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER */ | |
| @@ -104,7 +104,7 @@ static av_cold void speedhq_init_static_data(void) · 103 unmodified lines | ||
| 104 | 104 | speedhq_chr_dc_uni[i + 255] = bits + (code << 8); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | − ff_init_uni_ac_vlc(&ff_rl_speedhq, uni_speedhq_ac_vlc_len); | |
| 107 | + ff_mpeg1_init_uni_ac_vlc(&ff_rl_speedhq, uni_speedhq_ac_vlc_len); | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | av_cold int ff_speedhq_encode_init(MpegEncContext *s) |