diff options
author | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2013-07-29 00:05:43 +0200 |
---|---|---|
committer | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2013-07-29 00:05:43 +0200 |
commit | 2c046c718aefbc9f8223e22f85bb119da4fea04d (patch) | |
tree | d0e6b85dd37863b56bcc07588797b8b543a475e4 /libavcodec/pnmdec.c | |
parent | 768e40b451a459fefaceed6b1b3d6e70c93596ac (diff) | |
download | ffmpeg-2c046c718aefbc9f8223e22f85bb119da4fea04d.tar.gz |
Revert "Avoid overflows when reading pgm files with maxval != 255 and != 65535."
The patch worked on little endian because pgm decoding was broken
but it was not correct in any way.
This reverts commit 7651c0e49b1f6e66120ef32570a87e3f09224574.
Diffstat (limited to 'libavcodec/pnmdec.c')
-rw-r--r-- | libavcodec/pnmdec.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index 96ed83e55d..d0c72954aa 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -35,7 +35,6 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, int i, j, n, linesize, h, upgrade = 0, is_mono = 0; unsigned char *ptr; int components, sample_len, ret; - unsigned int maskval = 0; s->bytestream_start = s->bytestream = (uint8_t *)buf; @@ -76,10 +75,8 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, n = avctx->width; components=1; sample_len=8; - if (s->maxval < 255) { + if (s->maxval < 255) upgrade = 1; - maskval = (2 << av_log2(s->maxval)) - 1; - } goto do_read; case AV_PIX_FMT_GRAY8A: n = avctx->width * 2; @@ -91,10 +88,8 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, n = avctx->width * 2; components=1; sample_len=16; - if (s->maxval < 65535) { + if (s->maxval < 65535) upgrade = 2; - maskval = (2 << av_log2(s->maxval)) - 1; - } goto do_read; case AV_PIX_FMT_MONOWHITE: case AV_PIX_FMT_MONOBLACK: @@ -141,11 +136,11 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, else if (upgrade == 1) { unsigned int j, f = (255 * 128 + s->maxval / 2) / s->maxval; for (j = 0; j < n; j++) - ptr[j] = ((s->bytestream[j] & maskval) * f + 64) >> 7; + ptr[j] = (s->bytestream[j] * f + 64) >> 7; } else if (upgrade == 2) { unsigned int j, v, f = (65535 * 32768 + s->maxval / 2) / s->maxval; for (j = 0; j < n / 2; j++) { - v = av_be2ne16(((uint16_t *)s->bytestream)[j]) & maskval; + v = av_be2ne16(((uint16_t *)s->bytestream)[j]); ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15; } } |