Commit dc78696e authored by Paul B Mahol's avatar Paul B Mahol

avcodec/qdrw: fix decoding odd size images for 2bpp and 4bpp

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 05aa53dc
...@@ -91,31 +91,27 @@ static int decode_rle_bpp2(AVCodecContext *avctx, AVFrame *p, GetByteContext *gb ...@@ -91,31 +91,27 @@ static int decode_rle_bpp2(AVCodecContext *avctx, AVFrame *p, GetByteContext *gb
if (code & 0x80 ) { /* run */ if (code & 0x80 ) { /* run */
pix = bytestream2_get_byte(gbc); pix = bytestream2_get_byte(gbc);
for (j = 0; j < 257 - code; j++) { for (j = 0; j < 257 - code; j++) {
out[pos++] = (pix & 0xC0) >> 6; if (pos < offset)
out[pos++] = (pix & 0x30) >> 4; out[pos++] = (pix & 0xC0) >> 6;
out[pos++] = (pix & 0x0C) >> 2; if (pos < offset)
out[pos++] = (pix & 0x03); out[pos++] = (pix & 0x30) >> 4;
if (pos >= offset) { if (pos < offset)
pos -= offset; out[pos++] = (pix & 0x0C) >> 2;
pos++; if (pos < offset)
} out[pos++] = (pix & 0x03);
if (pos >= offset)
return AVERROR_INVALIDDATA;
} }
left -= 2; left -= 2;
} else { /* copy */ } else { /* copy */
for (j = 0; j < code + 1; j++) { for (j = 0; j < code + 1; j++) {
pix = bytestream2_get_byte(gbc); pix = bytestream2_get_byte(gbc);
out[pos++] = (pix & 0xC0) >> 6; if (pos < offset)
out[pos++] = (pix & 0x30) >> 4; out[pos++] = (pix & 0xC0) >> 6;
out[pos++] = (pix & 0x0C) >> 2; if (pos < offset)
out[pos++] = (pix & 0x03); out[pos++] = (pix & 0x30) >> 4;
if (pos >= offset) { if (pos < offset)
pos -= offset; out[pos++] = (pix & 0x0C) >> 2;
pos++; if (pos < offset)
} out[pos++] = (pix & 0x03);
if (pos >= offset)
return AVERROR_INVALIDDATA;
} }
left -= 1 + (code + 1); left -= 1 + (code + 1);
} }
...@@ -147,27 +143,19 @@ static int decode_rle_bpp4(AVCodecContext *avctx, AVFrame *p, GetByteContext *gb ...@@ -147,27 +143,19 @@ static int decode_rle_bpp4(AVCodecContext *avctx, AVFrame *p, GetByteContext *gb
if (code & 0x80 ) { /* run */ if (code & 0x80 ) { /* run */
pix = bytestream2_get_byte(gbc); pix = bytestream2_get_byte(gbc);
for (j = 0; j < 257 - code; j++) { for (j = 0; j < 257 - code; j++) {
out[pos++] = (pix & 0xF0) >> 4; if (pos < offset)
out[pos++] = pix & 0xF; out[pos++] = (pix & 0xF0) >> 4;
if (pos >= offset) { if (pos < offset)
pos -= offset; out[pos++] = pix & 0xF;
pos++;
}
if (pos >= offset)
return AVERROR_INVALIDDATA;
} }
left -= 2; left -= 2;
} else { /* copy */ } else { /* copy */
for (j = 0; j < code + 1; j++) { for (j = 0; j < code + 1; j++) {
pix = bytestream2_get_byte(gbc); pix = bytestream2_get_byte(gbc);
out[pos++] = (pix & 0xF0) >> 4; if (pos < offset)
out[pos++] = pix & 0xF; out[pos++] = (pix & 0xF0) >> 4;
if (pos >= offset) { if (pos < offset)
pos -= offset; out[pos++] = pix & 0xF;
pos++;
}
if (pos >= offset)
return AVERROR_INVALIDDATA;
} }
left -= 1 + (code + 1); left -= 1 + (code + 1);
} }
......
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