raw: LibRaw_QIODevice::read: fixed possible partial reading of an item

- If the size of an item is greater than 1 byte, it must be ensured that it is not partially read.
- In many readings, LibRAW gives an error if a partial number of items are read so I always try to read everything.
This commit is contained in:
Mirco Miranda 2022-11-19 10:14:16 +00:00 committed by Albert Astals Cid
parent 361f9e867e
commit dcab3a06ab

View File

@ -111,10 +111,20 @@ public:
}
virtual int read(void *ptr, size_t sz, size_t nmemb) override
{
auto read = m_device->read(reinterpret_cast<char *>(ptr), sz * nmemb);
if (read < 1) {
qint64 read = 0;
if (sz == 0) {
return 0;
}
auto data = reinterpret_cast<char*>(ptr);
for (qint64 r = 0, size = sz * nmemb; read < size; read += r) {
if (m_device->atEnd()) {
break;
}
r = m_device->read(data + read, size - read);
if (r < 1) {
break;
}
}
return read / sz;
}
virtual int eof() override