Skip to content

Commit 4ad45af

Browse files
committed
Merge pull request opencv#9253 from jbms:fix/image-decoding-tempfile
2 parents 37a7e08 + 2be955a commit 4ad45af

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

modules/imgcodecs/src/loadsave.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,15 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
651651
if( !f )
652652
return 0;
653653
size_t bufSize = buf.cols*buf.rows*buf.elemSize();
654-
fwrite( buf.ptr(), 1, bufSize, f );
655-
fclose(f);
654+
if( fwrite( buf.ptr(), 1, bufSize, f ) != bufSize )
655+
{
656+
fclose( f );
657+
CV_Error( CV_StsError, "failed to write image data to temporary file" );
658+
}
659+
if( fclose(f) != 0 )
660+
{
661+
CV_Error( CV_StsError, "failed to write image data to temporary file" );
662+
}
656663
decoder->setSource(filename);
657664
}
658665

0 commit comments

Comments
 (0)