aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/pnm.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2008-09-14 15:50:59 +0000
committerJustin Ruggles <justin.ruggles@gmail.com>2008-09-14 15:50:59 +0000
commit0605f5c86bb54f51d9f0cfd728a92bc2f6982449 (patch)
treeb08bc6e60df2c65690082355fbec8b106c1407a8 /libavcodec/pnm.c
parent8840ce92f7b75fcdfe87278bf12433e2bea4d777 (diff)
downloadffmpeg-0605f5c86bb54f51d9f0cfd728a92bc2f6982449.tar.gz
Return error when trying to decode non-grayscale 16-bit PNM images.
Fixes issue 566. Originally committed as revision 15321 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/pnm.c')
-rw-r--r--libavcodec/pnm.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c
index 587b703bed..be831ddbc0 100644
--- a/libavcodec/pnm.c
+++ b/libavcodec/pnm.c
@@ -106,7 +106,13 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){
else
avctx->pix_fmt = PIX_FMT_GRAY8;
} else if (depth == 3) {
+ if (maxval < 256) {
avctx->pix_fmt = PIX_FMT_RGB24;
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n");
+ avctx->pix_fmt = PIX_FMT_NONE;
+ return -1;
+ }
} else if (depth == 4) {
avctx->pix_fmt = PIX_FMT_RGB32;
} else {
@@ -127,10 +133,16 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){
if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
pnm_get(s, buf1, sizeof(buf1));
s->maxval = atoi(buf1);
- if(s->maxval >= 256 && avctx->pix_fmt == PIX_FMT_GRAY8) {
+ if (s->maxval >= 256) {
+ if (avctx->pix_fmt == PIX_FMT_GRAY8) {
avctx->pix_fmt = PIX_FMT_GRAY16BE;
if (s->maxval != 65535)
avctx->pix_fmt = PIX_FMT_GRAY16;
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n");
+ avctx->pix_fmt = PIX_FMT_NONE;
+ return -1;
+ }
}
}
/* more check if YUV420 */