1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Fix invalid PAM decoding

This fixes https://issues.oss-fuzz.com/issues/497290557
This commit is contained in:
Vincent Rabaud
2026-04-02 15:58:41 +02:00
parent 10e32c96f5
commit 12c90ff05b
+17
View File
@@ -481,6 +481,23 @@ bool PAMDecoder::readHeader()
}
} while (fieldtype != PAM_HEADER_ENDHDR);
if (selected_fmt != IMWRITE_PAM_FORMAT_NULL && flds_depth) {
if (selected_fmt == IMWRITE_PAM_FORMAT_BLACKANDWHITE && m_channels != 1) {
CV_Error(Error::StsError, "fmt is IMWRITE_PAM_FORMAT_BLACKANDWHITE but number of channels is not 1");
}
if (selected_fmt == IMWRITE_PAM_FORMAT_GRAYSCALE && m_channels != 1) {
CV_Error(Error::StsError, "fmt is IMWRITE_PAM_FORMAT_GRAYSCALE but number of channels is not 1");
}
if (selected_fmt == IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA && m_channels != 2) {
CV_Error(Error::StsError, "fmt is IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA but number of channels is not 2");
}
if (selected_fmt == IMWRITE_PAM_FORMAT_RGB && m_channels != 3) {
CV_Error(Error::StsError, "fmt is IMWRITE_PAM_FORMAT_RGB but number of channels is not 3");
}
if (selected_fmt == IMWRITE_PAM_FORMAT_RGB_ALPHA && m_channels != 4) {
CV_Error(Error::StsError, "fmt is IMWRITE_PAM_FORMAT_RGB_ALPHA but number of channels is not 4");
}
}
if (flds_endhdr && flds_height && flds_width && flds_depth && flds_maxval)
{
if (selected_fmt == IMWRITE_PAM_FORMAT_NULL)