mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
QOI: add failsafe if data is shorter than header
This commit is contained in:
@@ -47,14 +47,14 @@ struct QOIHeader {
|
|||||||
|
|
||||||
bool QOIHandler::canDecode(Data *data)
|
bool QOIHandler::canDecode(Data *data)
|
||||||
{
|
{
|
||||||
QOIHeader header;
|
if (data->getSize() < sizeof(QOIHeader)) {
|
||||||
const unsigned char *buffer = (const unsigned char *) data->getData();
|
return false;
|
||||||
memcpy(header.magic, buffer, 4 * sizeof(char));
|
}
|
||||||
memcpy(&header.width, buffer + offsetof(QOIHeader, width), sizeof(uint32_t));
|
|
||||||
memcpy(&header.height, buffer + offsetof(QOIHeader, height), sizeof(uint32_t));
|
|
||||||
|
|
||||||
bool magicOk = strcmp(header.magic, "qoif") == 0;
|
QOIHeader *header = (QOIHeader *) data->getData();
|
||||||
return magicOk && header.width > 0 && header.height > 0;
|
bool magicOk = strncmp(header->magic, "qoif", 4) == 0;
|
||||||
|
|
||||||
|
return magicOk && header->width > 0 && header->height > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QOIHandler::canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat)
|
bool QOIHandler::canEncode(PixelFormat rawFormat, EncodedFormat encodedFormat)
|
||||||
|
|||||||
Reference in New Issue
Block a user