mirror of
https://github.com/opencv/opencv.git
synced 2025-06-08 01:53:19 +08:00
Fix temporary file removal in imdecode for tiff
The TiffDecoder keeps an open file handle. As a consequence the file cannot be removed before the TiffDecoder closes the file.
This commit is contained in:
parent
e884bbabcb
commit
84e1712659
@ -514,8 +514,14 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
|
|||||||
|
|
||||||
if( !decoder->readHeader() )
|
if( !decoder->readHeader() )
|
||||||
{
|
{
|
||||||
if( !filename.empty() )
|
decoder.release();
|
||||||
remove(filename.c_str());
|
if ( !filename.empty() )
|
||||||
|
{
|
||||||
|
if ( remove(filename.c_str()) != 0 )
|
||||||
|
{
|
||||||
|
CV_Error( CV_StsError, "unable to remove temporary file" );
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,8 +562,14 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool code = decoder->readData( *data );
|
bool code = decoder->readData( *data );
|
||||||
if( !filename.empty() )
|
decoder.release();
|
||||||
remove(filename.c_str());
|
if ( !filename.empty() )
|
||||||
|
{
|
||||||
|
if ( remove(filename.c_str()) != 0 )
|
||||||
|
{
|
||||||
|
CV_Error( CV_StsError, "unable to remove temporary file" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( !code )
|
if( !code )
|
||||||
{
|
{
|
||||||
|
@ -890,6 +890,19 @@ TEST(Imgcodecs_Tiff, decode_multipage)
|
|||||||
CV_GrfmtReadTifMultiPage test; test.safe_run();
|
CV_GrfmtReadTifMultiPage test; test.safe_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Imgcodecs_Tiff, imdecode_no_exception_temporary_file_removed)
|
||||||
|
{
|
||||||
|
cvtest::TS& ts = *cvtest::TS::ptr();
|
||||||
|
string input = string(ts.get_data_path()) + "../cv/shared/lena.png";
|
||||||
|
cv::Mat img = cv::imread(input);
|
||||||
|
ASSERT_FALSE(img.empty());
|
||||||
|
|
||||||
|
std::vector<uchar> buf;
|
||||||
|
EXPECT_NO_THROW(cv::imencode(".tiff", img, buf));
|
||||||
|
|
||||||
|
EXPECT_NO_THROW(cv::imdecode(buf, IMREAD_UNCHANGED));
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_WEBP
|
#ifdef HAVE_WEBP
|
||||||
|
Loading…
Reference in New Issue
Block a user