From dfbd18e9aa12cd8018e387f7fe191c5ed69fda06 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Fri, 5 Jul 2024 07:53:28 +0200 Subject: [PATCH] Merge pull request #25864 from vrabaud:legacy Make sure all the lines of a JPEG are read #25864 In case of corrupted JPEG, imread would still return a JPEG of the proper size (as indicated by the header) but with some uninitialized values. I do not have a short reproducer I can add as a test as this was found by our fuzzers. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch --- modules/imgcodecs/src/grfmt_jpeg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/imgcodecs/src/grfmt_jpeg.cpp b/modules/imgcodecs/src/grfmt_jpeg.cpp index 98019cc48a..a3a7f70c3c 100644 --- a/modules/imgcodecs/src/grfmt_jpeg.cpp +++ b/modules/imgcodecs/src/grfmt_jpeg.cpp @@ -499,7 +499,7 @@ bool JpegDecoder::readData( Mat& img ) for( int iy = 0 ; iy < m_height; iy ++ ) { uchar* data = img.ptr(iy); - jpeg_read_scanlines( cinfo, &data, 1 ); + if (jpeg_read_scanlines( cinfo, &data, 1 ) != 1) return false; } } else @@ -510,7 +510,7 @@ bool JpegDecoder::readData( Mat& img ) for( int iy = 0 ; iy < m_height; iy ++ ) { uchar* data = img.ptr(iy); - jpeg_read_scanlines( cinfo, buffer, 1 ); + if (jpeg_read_scanlines( cinfo, buffer, 1 ) != 1) return false; if( color ) {