Tests for Pnm.hpp, Pnm operator>> input robustness
This commit is contained in:
@@ -87,8 +87,25 @@ namespace OpenVulkano
|
||||
if (val > 6) throw std::runtime_error("Malformed PNM header!");
|
||||
pnmHeader.ascii = val < 4;
|
||||
pnmHeader.color = static_cast<ColorMode>(val - 3);
|
||||
inStream >> pnmHeader.width >> pnmHeader.height;
|
||||
inStream >> pnmHeader.maxValue;
|
||||
|
||||
if (!(inStream >> pnmHeader.width >> pnmHeader.height))
|
||||
{
|
||||
throw std::runtime_error("Malformed PNM header: Unable to read width and height!");
|
||||
}
|
||||
if (pnmHeader.width == 0 || pnmHeader.height == 0)
|
||||
{
|
||||
throw std::runtime_error("Malformed PNM header: Width and height must be positive!");
|
||||
}
|
||||
|
||||
if (!(inStream >> pnmHeader.maxValue))
|
||||
{
|
||||
throw std::runtime_error("Malformed PNM header: Unable to read maxValue!");
|
||||
}
|
||||
if (pnmHeader.maxValue == 0 || pnmHeader.maxValue > 65535)
|
||||
{
|
||||
throw std::runtime_error("Malformed PNM header: Invalid maxValue (must be between 1 and 65535)!");
|
||||
}
|
||||
|
||||
inStream.get();
|
||||
return inStream;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user