@@ -519,7+536,10 @@ static inline int APESIGN(int32_t x) {
return (x < 0) - (x > 0);
}
return (x < 0) - (x > 0);
}
-static av_always_inline int predictor_update_filter(APEPredictor *p, const int decoded, const int filter, const int delayA, const int delayB, const int adaptA, const int adaptB)
+static av_always_inline int predictor_update_filter(APEPredictor *p,
+ const int decoded, const int filter,
+ const int delayA, const int delayB,
+ const int adaptA, const int adaptB)
{
int32_t predictionA, predictionB, sign;
{
int32_t predictionA, predictionB, sign;
@@ -563,7+583,7 @@ static av_always_inline int predictor_update_filter(APEPredictor *p, const int d
return p->filterA[filter];
}
return p->filterA[filter];
}
-static void predictor_decode_stereo(APEContext *ctx, int count)
+static void predictor_decode_stereo(APEContext *ctx, int count)
{
APEPredictor *p = &ctx->predictor;
int32_t *decoded0 = ctx->decoded0;
{
APEPredictor *p = &ctx->predictor;
int32_t *decoded0 = ctx->decoded0;
@@ -571,9+591,11 @@ static void predictor_decode_stereo(APEContext * ctx, int count)
-static void ape_unpack_stereo(APEContext *ctx, int count)
+static void ape_unpack_stereo(APEContext *ctx, int count)
{
int32_t left, right;
int32_t *decoded0 = ctx->decoded0;
{
int32_t left, right;
int32_t *decoded0 = ctx->decoded0;
@@ -789,7+816,7 @@ static void ape_unpack_stereo(APEContext * ctx, int count)
}
}
}
}
-static int ape_decode_frame(AVCodecContext *avctx,
+static int ape_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
void *data, int *data_size,
AVPacket *avpkt)
{
@@ -797,49+824,65 @@ static int ape_decode_frame(AVCodecContext * avctx,
int buf_size = avpkt->size;
APEContext *s = avctx->priv_data;
int16_t *samples = data;
int buf_size = avpkt->size;
APEContext *s = avctx->priv_data;
int16_t *samples = data;
- int nblocks;
- int i, n;
+ uint32_t nblocks;
+ int i;
int blockstodecode;
int bytes_used;
int blockstodecode;
int bytes_used;
- if (buf_size == 0 && !s->samples) {
- *data_size = 0;
- return 0;
- }
-
/* should not happen but who knows */
if (BLOCKS_PER_LOOP * 2 * avctx->channels > *data_size) {
/* should not happen but who knows */
if (BLOCKS_PER_LOOP * 2 * avctx->channels > *data_size) {
- av_log (avctx, AV_LOG_ERROR, "Packet size is too big to be handled in lavc! (max is %d where you have %d)\n", *data_size, s->samples * 2 * avctx->channels);
- return -1;
+ av_log (avctx, AV_LOG_ERROR, "Output buffer is too small.\n");
+ return AVERROR(EINVAL);
}
}
+ /* this should never be negative, but bad things will happen if it is, so