QOI: add failsafe if data is shorter than header

This commit is contained in:
TotoEnF5
2026-07-16 10:29:49 +02:00
parent 34079d008c
commit 16b33a94aa
+7 -7
View File
@@ -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)