faxcompr: return meaningful errors

And optionally forward them to the caller instead of concealing them.

Unify err and ret in a single variable.
This commit is contained in:
Luca Barbato 2013-06-03 11:11:38 +02:00
parent f32aefcf34
commit a3b2b83f01

View File

@ -137,20 +137,20 @@ static int decode_group3_1d_line(AVCodecContext *avctx, GetBitContext *gb,
*runs++ = run; *runs++ = run;
if (runs >= runend) { if (runs >= runend) {
av_log(avctx, AV_LOG_ERROR, "Run overrun\n"); av_log(avctx, AV_LOG_ERROR, "Run overrun\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (pix_left <= run) { if (pix_left <= run) {
if (pix_left == run) if (pix_left == run)
break; break;
av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n");
return -1; return AVERROR_INVALIDDATA;
} }
pix_left -= run; pix_left -= run;
run = 0; run = 0;
mode = !mode; mode = !mode;
} else if ((int)t == -1) { } else if ((int)t == -1) {
av_log(avctx, AV_LOG_ERROR, "Incorrect code\n"); av_log(avctx, AV_LOG_ERROR, "Incorrect code\n");
return -1; return AVERROR_INVALIDDATA;
} }
} }
*runs++ = 0; *runs++ = 0;
@ -171,7 +171,7 @@ static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
int cmode = get_vlc2(gb, ccitt_group3_2d_vlc.table, 9, 1); int cmode = get_vlc2(gb, ccitt_group3_2d_vlc.table, 9, 1);
if (cmode == -1) { if (cmode == -1) {
av_log(avctx, AV_LOG_ERROR, "Incorrect mode VLC\n"); av_log(avctx, AV_LOG_ERROR, "Incorrect mode VLC\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (!cmode) { //pass mode if (!cmode) { //pass mode
run_off += *ref++; run_off += *ref++;
@ -180,7 +180,7 @@ static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
run_off += *ref++; run_off += *ref++;
if (offs > width) { if (offs > width) {
av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n");
return -1; return AVERROR_INVALIDDATA;
} }
saved_run += run; saved_run += run;
} else if (cmode == 1) { //horizontal mode } else if (cmode == 1) { //horizontal mode
@ -191,7 +191,7 @@ static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
t = get_vlc2(gb, ccitt_vlc[mode].table, 9, 2); t = get_vlc2(gb, ccitt_vlc[mode].table, 9, 2);
if (t == -1) { if (t == -1) {
av_log(avctx, AV_LOG_ERROR, "Incorrect code\n"); av_log(avctx, AV_LOG_ERROR, "Incorrect code\n");
return -1; return AVERROR_INVALIDDATA;
} }
run += t; run += t;
if (t < 64) if (t < 64)
@ -200,32 +200,31 @@ static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
*runs++ = run + saved_run; *runs++ = run + saved_run;
if (runs >= runend) { if (runs >= runend) {
av_log(avctx, AV_LOG_ERROR, "Run overrun\n"); av_log(avctx, AV_LOG_ERROR, "Run overrun\n");
return -1; return AVERROR_INVALIDDATA;
} }
saved_run = 0; saved_run = 0;
offs += run; offs += run;
if (offs > width || run > width) { if (offs > width || run > width) {
av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n");
return -1; return AVERROR_INVALIDDATA;
} }
mode = !mode; mode = !mode;
} }
} else if (cmode == 9 || cmode == 10) { } else if (cmode == 9 || cmode == 10) {
av_log(avctx, AV_LOG_ERROR, avpriv_report_missing_feature(avctx, "Special modes support");
"Special modes are not supported (yet)\n"); return AVERROR_PATCHWELCOME;
return -1;
} else { //vertical mode } else { //vertical mode
run = run_off - offs + (cmode - 5); run = run_off - offs + (cmode - 5);
run_off -= *--ref; run_off -= *--ref;
offs += run; offs += run;
if (offs > width || run > width) { if (offs > width || run > width) {
av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n");
return -1; return AVERROR_INVALIDDATA;
} }
*runs++ = run + saved_run; *runs++ = run + saved_run;
if (runs >= runend) { if (runs >= runend) {
av_log(avctx, AV_LOG_ERROR, "Run overrun\n"); av_log(avctx, AV_LOG_ERROR, "Run overrun\n");
return -1; return AVERROR_INVALIDDATA;
} }
saved_run = 0; saved_run = 0;
mode = !mode; mode = !mode;
@ -280,12 +279,11 @@ int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t *src, int srcsize,
int *runs, *ref = NULL, *runend; int *runs, *ref = NULL, *runend;
int ret; int ret;
int runsize = avctx->width + 2; int runsize = avctx->width + 2;
int err = 0;
runs = av_malloc(runsize * sizeof(runs[0])); runs = av_malloc(runsize * sizeof(runs[0]));
ref = av_malloc(runsize * sizeof(ref[0])); ref = av_malloc(runsize * sizeof(ref[0]));
if (!runs || !ref) { if (!runs || !ref) {
err = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail; goto fail;
} }
ref[0] = avctx->width; ref[0] = avctx->width;
@ -297,10 +295,8 @@ int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t *src, int srcsize,
if (compr == TIFF_G4) { if (compr == TIFF_G4) {
ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend, ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend,
ref); ref);
if (ret < 0) { if (ret < 0)
err = -1;
goto fail; goto fail;
}
} else { } else {
int g3d1 = (compr == TIFF_G3) && !(opts & 1); int g3d1 = (compr == TIFF_G3) && !(opts & 1);
if (compr != TIFF_CCITT_RLE && if (compr != TIFF_CCITT_RLE &&
@ -315,6 +311,9 @@ int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t *src, int srcsize,
if (compr == TIFF_CCITT_RLE) if (compr == TIFF_CCITT_RLE)
align_get_bits(&gb); align_get_bits(&gb);
} }
if (avctx->err_recognition & AV_EF_EXPLODE && ret < 0)
goto fail;
if (ret < 0) { if (ret < 0) {
put_line(dst, stride, avctx->width, ref); put_line(dst, stride, avctx->width, ref);
} else { } else {
@ -323,8 +322,9 @@ int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t *src, int srcsize,
} }
dst += stride; dst += stride;
} }
ret = 0;
fail: fail:
av_free(runs); av_free(runs);
av_free(ref); av_free(ref);
return err; return ret;
} }