From 1821d21f5b9b922fb95f348ffde0a4f5916f1bb9 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Thu, 6 Dec 2012 19:42:17 +0400 Subject: [PATCH] Prevent imread from illegal memory access (Bug #2602) The change is based on pull request #211. --- modules/highgui/src/grfmt_jpeg.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/highgui/src/grfmt_jpeg.cpp b/modules/highgui/src/grfmt_jpeg.cpp index 20421ce255..6ecf2d6542 100644 --- a/modules/highgui/src/grfmt_jpeg.cpp +++ b/modules/highgui/src/grfmt_jpeg.cpp @@ -229,12 +229,16 @@ bool JpegDecoder::readHeader() if( m_f ) jpeg_stdio_src( &state->cinfo, m_f ); } - jpeg_read_header( &state->cinfo, TRUE ); - m_width = state->cinfo.image_width; - m_height = state->cinfo.image_height; - m_type = state->cinfo.num_components > 1 ? CV_8UC3 : CV_8UC1; - result = true; + if (state->cinfo.src != 0) + { + jpeg_read_header( &state->cinfo, TRUE ); + + m_width = state->cinfo.image_width; + m_height = state->cinfo.image_height; + m_type = state->cinfo.num_components > 1 ? CV_8UC3 : CV_8UC1; + result = true; + } } if( !result )