From dcab3a06ab872a6a71a34d91c711118f1956c677 Mon Sep 17 00:00:00 2001 From: Mirco Miranda Date: Sat, 19 Nov 2022 10:14:16 +0000 Subject: [PATCH] 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. --- src/imageformats/raw.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/imageformats/raw.cpp b/src/imageformats/raw.cpp index fba2d8c..ad34018 100644 --- a/src/imageformats/raw.cpp +++ b/src/imageformats/raw.cpp @@ -111,10 +111,20 @@ public: } virtual int read(void *ptr, size_t sz, size_t nmemb) override { - auto read = m_device->read(reinterpret_cast(ptr), sz * nmemb); - if (read < 1) { + qint64 read = 0; + if (sz == 0) { return 0; } + auto data = reinterpret_cast(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