drop workaround for malformed PNGs

while at it, read the data in single pass as is done in the TIFF image
format handler for an example

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2020-08-16 04:11:21 +03:00
parent 70c523fb13
commit b1e1f18970

View file

@ -123,21 +123,9 @@ static void iod_read_fn(png_structp png_ptr, png_bytep data, png_size_t length)
QPngHandlerPrivate *d = (QPngHandlerPrivate *)png_get_io_ptr(png_ptr);
QIODevice *in = d->q->device();
if (d->state == QPngHandlerPrivate::ReadingEnd && !in->isSequential() && (in->size() - in->pos()) < 4 && length == 4) {
// Workaround for certain malformed PNGs that lack the final crc bytes
uchar endcrc[4] = { 0xae, 0x42, 0x60, 0x82 };
memcpy(data, endcrc, 4);
in->seek(in->size());
return;
}
while (length) {
int nr = in->read((char*)data, length);
if (nr <= 0) {
png_error(png_ptr, "Read Error");
break;
}
length -= nr;
int nr = in->read((char*)data, length);
if (nr != length) {
png_error(png_ptr, "Read Error");
}
}