Commit 329675cf authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'a1c525f7'

* commit 'a1c525f7':
  pcx: return meaningful error codes.
  tmv: return meaningful error codes.
  msrle: return meaningful error codes.
  cscd: return meaningful error codes.
  yadif: x86: fix build for compilers without aligned stack
  lavc: introduce the convenience function init_get_bits8
  lavc: check for overflow in init_get_bits

Conflicts:
	libavcodec/cscd.c
	libavcodec/pcx.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents a646ac8e a1c525f7
...@@ -68,18 +68,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, ...@@ -68,18 +68,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
int buf_size = avpkt->size; int buf_size = avpkt->size;
CamStudioContext *c = avctx->priv_data; CamStudioContext *c = avctx->priv_data;
AVFrame *picture = data; AVFrame *picture = data;
int ret;
if (buf_size < 2) { if (buf_size < 2) {
av_log(avctx, AV_LOG_ERROR, "coded frame too small\n"); av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
return -1; return AVERROR_INVALIDDATA;
} }
c->pic.reference = 3; c->pic.reference = 3;
c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE | c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE |
FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
if (avctx->reget_buffer(avctx, &c->pic) < 0) { if ((ret = avctx->reget_buffer(avctx, &c->pic)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1; return ret;
} }
// decompress data // decompress data
...@@ -98,12 +99,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, ...@@ -98,12 +99,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
break; break;
#else #else
av_log(avctx, AV_LOG_ERROR, "compiled without zlib support\n"); av_log(avctx, AV_LOG_ERROR, "compiled without zlib support\n");
return -1; return AVERROR(ENOSYS);
#endif #endif
} }
default: default:
av_log(avctx, AV_LOG_ERROR, "unknown compression\n"); av_log(avctx, AV_LOG_ERROR, "unknown compression\n");
return -1; return AVERROR_INVALIDDATA;
} }
// flip upside down, add difference frame // flip upside down, add difference frame
......
...@@ -366,25 +366,49 @@ static inline int check_marker(GetBitContext *s, const char *msg) ...@@ -366,25 +366,49 @@ static inline int check_marker(GetBitContext *s, const char *msg)
} }
/** /**
* Inititalize GetBitContext. * Initialize GetBitContext.
* @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger than the actual read bits * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes
* because some optimized bitstream readers read 32 or 64 bit at once and could read over the end * larger than the actual read bits because some optimized bitstream
* readers read 32 or 64 bit at once and could read over the end
* @param bit_size the size of the buffer in bits * @param bit_size the size of the buffer in bits
* @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
*/ */
static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer, static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
int bit_size) int bit_size)
{ {
int buffer_size = (bit_size+7)>>3; int buffer_size;
if (buffer_size < 0 || bit_size < 0) { int ret = 0;
if (bit_size > INT_MAX - 7 || bit_size < 0) {
buffer_size = bit_size = 0; buffer_size = bit_size = 0;
buffer = NULL; buffer = NULL;
ret = AVERROR_INVALIDDATA;
} }
buffer_size = (bit_size + 7) >> 3;
s->buffer = buffer; s->buffer = buffer;
s->size_in_bits = bit_size; s->size_in_bits = bit_size;
s->size_in_bits_plus8 = bit_size + 8; s->size_in_bits_plus8 = bit_size + 8;
s->buffer_end = buffer + buffer_size; s->buffer_end = buffer + buffer_size;
s->index = 0; s->index = 0;
return ret;
}
/**
* Initialize GetBitContext.
* @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes
* larger than the actual read bits because some optimized bitstream
* readers read 32 or 64 bit at once and could read over the end
* @param byte_size the size of the buffer in bytes
* @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
*/
static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer,
int byte_size)
{
if (byte_size > INT_MAX / 8)
return AVERROR_INVALIDDATA;
return init_get_bits(s, buffer, byte_size * 8);
} }
static inline void align_get_bits(GetBitContext *s) static inline void align_get_bits(GetBitContext *s)
......
...@@ -67,7 +67,7 @@ static av_cold int msrle_decode_init(AVCodecContext *avctx) ...@@ -67,7 +67,7 @@ static av_cold int msrle_decode_init(AVCodecContext *avctx)
break; break;
default: default:
av_log(avctx, AV_LOG_ERROR, "unsupported bits per sample\n"); av_log(avctx, AV_LOG_ERROR, "unsupported bits per sample\n");
return -1; return AVERROR_INVALIDDATA;
} }
avcodec_get_frame_defaults(&s->frame); avcodec_get_frame_defaults(&s->frame);
...@@ -88,15 +88,16 @@ static int msrle_decode_frame(AVCodecContext *avctx, ...@@ -88,15 +88,16 @@ static int msrle_decode_frame(AVCodecContext *avctx,
int buf_size = avpkt->size; int buf_size = avpkt->size;
MsrleContext *s = avctx->priv_data; MsrleContext *s = avctx->priv_data;
int istride = FFALIGN(avctx->width*avctx->bits_per_coded_sample, 32) / 8; int istride = FFALIGN(avctx->width*avctx->bits_per_coded_sample, 32) / 8;
int ret;
s->buf = buf; s->buf = buf;
s->size = buf_size; s->size = buf_size;
s->frame.reference = 3; s->frame.reference = 3;
s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
if (avctx->reget_buffer(avctx, &s->frame)) { if ((ret = avctx->reget_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1; return ret;
} }
if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) { if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) {
......
...@@ -147,8 +147,8 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, ...@@ -147,8 +147,8 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
if (p->data[0]) if (p->data[0])
avctx->release_buffer(avctx, p); avctx->release_buffer(avctx, p);
if (av_image_check_size(w, h, 0, avctx)) if ((ret = av_image_check_size(w, h, 0, avctx)) < 0)
return AVERROR_INVALIDDATA; return ret;
if (w != avctx->width || h != avctx->height) if (w != avctx->width || h != avctx->height)
avcodec_set_dimensions(avctx, w, h); avcodec_set_dimensions(avctx, w, h);
if ((ret = ff_get_buffer(avctx, p)) < 0) { if ((ret = ff_get_buffer(avctx, p)) < 0) {
......
...@@ -48,20 +48,21 @@ static int tmv_decode_frame(AVCodecContext *avctx, void *data, ...@@ -48,20 +48,21 @@ static int tmv_decode_frame(AVCodecContext *avctx, void *data,
unsigned char_cols = avctx->width >> 3; unsigned char_cols = avctx->width >> 3;
unsigned char_rows = avctx->height >> 3; unsigned char_rows = avctx->height >> 3;
unsigned x, y, fg, bg, c; unsigned x, y, fg, bg, c;
int ret;
if (tmv->pic.data[0]) if (tmv->pic.data[0])
avctx->release_buffer(avctx, &tmv->pic); avctx->release_buffer(avctx, &tmv->pic);
if (ff_get_buffer(avctx, &tmv->pic) < 0) { if ((ret = ff_get_buffer(avctx, &tmv->pic)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1; return ret;
} }
if (avpkt->size < 2*char_rows*char_cols) { if (avpkt->size < 2*char_rows*char_cols) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"Input buffer too small, truncated sample?\n"); "Input buffer too small, truncated sample?\n");
*got_frame = 0; *got_frame = 0;
return -1; return AVERROR_INVALIDDATA;
} }
tmv->pic.pict_type = AV_PICTURE_TYPE_I; tmv->pic.pict_type = AV_PICTURE_TYPE_I;
......
...@@ -31,8 +31,8 @@ pw_1: times 8 dw 1 ...@@ -31,8 +31,8 @@ pw_1: times 8 dw 1
SECTION .text SECTION .text
%macro CHECK 2 %macro CHECK 2
movu m2, [curq+mrefsq+%1] movu m2, [curq+t1+%1]
movu m3, [curq+prefsq+%2] movu m3, [curq+t0+%2]
mova m4, m2 mova m4, m2
mova m5, m2 mova m5, m2
pxor m4, m3 pxor m4, m3
...@@ -97,8 +97,8 @@ SECTION .text ...@@ -97,8 +97,8 @@ SECTION .text
%macro FILTER 3 %macro FILTER 3
.loop%1: .loop%1:
pxor m7, m7 pxor m7, m7
LOAD 0, [curq+mrefsq] LOAD 0, [curq+t1]
LOAD 1, [curq+prefsq] LOAD 1, [curq+t0]
LOAD 2, [%2] LOAD 2, [%2]
LOAD 3, [%3] LOAD 3, [%3]
mova m4, m3 mova m4, m3
...@@ -109,8 +109,8 @@ SECTION .text ...@@ -109,8 +109,8 @@ SECTION .text
mova [rsp+32], m1 mova [rsp+32], m1
psubw m2, m4 psubw m2, m4
ABS1 m2, m4 ABS1 m2, m4
LOAD 3, [prevq+mrefsq] LOAD 3, [prevq+t1]
LOAD 4, [prevq+prefsq] LOAD 4, [prevq+t0]
psubw m3, m0 psubw m3, m0
psubw m4, m1 psubw m4, m1
ABS1 m3, m5 ABS1 m3, m5
...@@ -119,8 +119,8 @@ SECTION .text ...@@ -119,8 +119,8 @@ SECTION .text
psrlw m2, 1 psrlw m2, 1
psrlw m3, 1 psrlw m3, 1
pmaxsw m2, m3 pmaxsw m2, m3
LOAD 3, [nextq+mrefsq] LOAD 3, [nextq+t1]
LOAD 4, [nextq+prefsq] LOAD 4, [nextq+t0]
psubw m3, m0 psubw m3, m0
psubw m4, m1 psubw m4, m1
ABS1 m3, m5 ABS1 m3, m5
...@@ -136,8 +136,8 @@ SECTION .text ...@@ -136,8 +136,8 @@ SECTION .text
psrlw m1, 1 psrlw m1, 1
ABS1 m0, m2 ABS1 m0, m2
movu m2, [curq+mrefsq-1] movu m2, [curq+t1-1]
movu m3, [curq+prefsq-1] movu m3, [curq+t0-1]
mova m4, m2 mova m4, m2
psubusb m2, m3 psubusb m2, m3
psubusb m3, m4 psubusb m3, m4
...@@ -164,12 +164,12 @@ SECTION .text ...@@ -164,12 +164,12 @@ SECTION .text
CHECK2 CHECK2
mova m6, [rsp+48] mova m6, [rsp+48]
cmp DWORD modem, 2 cmp DWORD r8m, 2
jge .end%1 jge .end%1
LOAD 2, [%2+mrefsq*2] LOAD 2, [%2+t1*2]
LOAD 4, [%3+mrefsq*2] LOAD 4, [%3+t1*2]
LOAD 3, [%2+prefsq*2] LOAD 3, [%2+t0*2]
LOAD 5, [%3+prefsq*2] LOAD 5, [%3+t0*2]
paddw m2, m4 paddw m2, m4
paddw m3, m5 paddw m3, m5
psrlw m2, 1 psrlw m2, 1
...@@ -208,17 +208,29 @@ SECTION .text ...@@ -208,17 +208,29 @@ SECTION .text
add prevq, mmsize/2 add prevq, mmsize/2
add curq, mmsize/2 add curq, mmsize/2
add nextq, mmsize/2 add nextq, mmsize/2
sub wd, mmsize/2 sub DWORD r4m, mmsize/2
jg .loop%1 jg .loop%1
%endmacro %endmacro
%macro YADIF 0 %macro YADIF 0
cglobal yadif_filter_line, 7, 7, 8, 16*5, dst, prev, cur, next, w, prefs, \ %if ARCH_X86_32
cglobal yadif_filter_line, 4, 6, 8, 80, dst, prev, cur, next, w, prefs, \
mrefs, parity, mode
%else
cglobal yadif_filter_line, 4, 7, 8, 80, dst, prev, cur, next, w, prefs, \
mrefs, parity, mode mrefs, parity, mode
test wq, wq %endif
cmp DWORD wm, 0
jle .ret jle .ret
movsxdifnidn prefsq, prefsd %if ARCH_X86_32
movsxdifnidn mrefsq, mrefsd mov r4, r5mp
mov r5, r6mp
DECLARE_REG_TMP 4,5
%else
movsxd r5, DWORD r5m
movsxd r6, DWORD r6m
DECLARE_REG_TMP 5,6
%endif
cmp DWORD paritym, 0 cmp DWORD paritym, 0
je .parity0 je .parity0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment