mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
Make sure AVIF decoder is destroyed in case of failure
This commit is contained in:
parent
8b47361873
commit
44c254c09d
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <avif/avif.h>
|
#include <avif/avif.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <opencv2/core/utils/configuration.private.hpp>
|
#include <opencv2/core/utils/configuration.private.hpp>
|
||||||
#include "opencv2/imgproc.hpp"
|
#include "opencv2/imgproc.hpp"
|
||||||
@ -159,16 +160,16 @@ size_t AvifDecoder::signatureLength() const { return kAvifSignatureSize; }
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AvifDecoder::checkSignature(const String &signature) const {
|
bool AvifDecoder::checkSignature(const String &signature) const {
|
||||||
avifDecoder *decoder = avifDecoderCreate();
|
std::unique_ptr<avifDecoder, decltype(&avifDecoderDestroy)> decoder(
|
||||||
|
avifDecoderCreate(), avifDecoderDestroy);
|
||||||
if (!decoder) return false;
|
if (!decoder) return false;
|
||||||
OPENCV_AVIF_CHECK_STATUS(
|
OPENCV_AVIF_CHECK_STATUS(
|
||||||
avifDecoderSetIOMemory(
|
avifDecoderSetIOMemory(
|
||||||
decoder, reinterpret_cast<const uint8_t *>(signature.c_str()),
|
decoder.get(), reinterpret_cast<const uint8_t *>(signature.c_str()),
|
||||||
signature.size()),
|
signature.size()),
|
||||||
decoder);
|
decoder);
|
||||||
decoder->io->sizeHint = 1e9;
|
decoder->io->sizeHint = 1e9;
|
||||||
const avifResult status = avifDecoderParse(decoder);
|
const avifResult status = avifDecoderParse(decoder.get());
|
||||||
avifDecoderDestroy(decoder);
|
|
||||||
return (status == AVIF_RESULT_OK || status == AVIF_RESULT_TRUNCATED_DATA);
|
return (status == AVIF_RESULT_OK || status == AVIF_RESULT_TRUNCATED_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user