summaryrefslogtreecommitdiff
path: root/libavcodec/faxcompr.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2015-08-13 17:01:11 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2015-08-13 17:01:11 +0200
commita4f9bb228bb34f0cfa4b55b207c19604b1e36818 (patch)
treec59539802e49ea817f44a94ec55979088bf9d4fa /libavcodec/faxcompr.c
parentdd1b4ed6d98f1f4dd566a28ec5ade00712f9c27c (diff)
avcodec/faxcompr: Support uncompressed escapes in decode_group3_1d_line()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec/faxcompr.c')
-rw-r--r--libavcodec/faxcompr.c73
1 files changed, 71 insertions, 2 deletions
diff --git a/libavcodec/faxcompr.c b/libavcodec/faxcompr.c
index 8c17c6e106..01f3e2a949 100644
--- a/libavcodec/faxcompr.c
+++ b/libavcodec/faxcompr.c
@@ -149,8 +149,77 @@ static int decode_group3_1d_line(AVCodecContext *avctx, GetBitContext *gb,
run = 0;
mode = !mode;
} else if ((int)t == -1) {
- av_log(avctx, AV_LOG_ERROR, "Incorrect code\n");
- return AVERROR_INVALIDDATA;
+ if (show_bits(gb, 12) == 15) {
+ int eob = 0;
+ int newmode;
+ int saved_run = 0;
+ skip_bits(gb, 12);
+
+ do {
+ int cwi, k;
+ int cw = 0;
+ int codes[2];
+ do {
+ cwi = show_bits(gb, 11);
+ if (!cwi) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid uncompressed codeword\n");
+ return AVERROR_INVALIDDATA;
+ }
+ cwi = 10 - av_log2(cwi);
+ skip_bits(gb, cwi + 1);
+ if (cwi > 5) {
+ newmode = get_bits1(gb);
+ eob = 1;
+ cwi -= 6;
+ }
+ cw += cwi;
+ } while(cwi == 5);
+
+ codes[0] = cw;
+ codes[1] = !eob;
+
+ for (k = 0; k < 2; k++) {
+ if (codes[k]) {
+ if (mode == k) {
+ *runs++ = saved_run;
+ if (runs >= runend) {
+ av_log(avctx, AV_LOG_ERROR, "uncompressed run overrun\n");
+ return AVERROR_INVALIDDATA;
+ }
+ if (pix_left <= saved_run) {
+ av_log(avctx, AV_LOG_ERROR, "uncompressed run went out of bounds\n");
+ return AVERROR_INVALIDDATA;
+ }
+ pix_left -= saved_run;
+ saved_run = 0;
+ mode = !mode;
+ }
+ saved_run += codes[k];
+ }
+ }
+ } while (!eob);
+ *runs++ = saved_run;
+ if (runs >= runend) {
+ av_log(avctx, AV_LOG_ERROR, "uncompressed run overrun\n");
+ return AVERROR_INVALIDDATA;
+ }
+ if (pix_left <= saved_run) {
+ if (pix_left == saved_run)
+ break;
+ av_log(avctx, AV_LOG_ERROR, "uncompressed run went out of boundsE\n");
+ return AVERROR_INVALIDDATA;
+ }
+ pix_left -= saved_run;
+ saved_run = 0;
+ mode = !mode;
+ if (newmode != mode) { //FIXME CHECK
+ *runs++ = 0;
+ mode = newmode;
+ }
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "Incorrect code\n");
+ return AVERROR_INVALIDDATA;
+ }
}
}
*runs++ = 0;