From 7202e77c74028e7ce91830443f2fb9a4df78f746 Mon Sep 17 00:00:00 2001 From: Mirco Miranda Date: Mon, 17 Nov 2025 15:50:35 +0100 Subject: [PATCH] HDR: readHeader() sanity checks --- src/imageformats/hdr.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/imageformats/hdr.cpp b/src/imageformats/hdr.cpp index 105e953..7cae0c1 100644 --- a/src/imageformats/hdr.cpp +++ b/src/imageformats/hdr.cpp @@ -125,14 +125,16 @@ public: Header h; int cnt = 0; - int len; - QByteArray line(MAXLINE + 1, Qt::Uninitialized); + int len = 0; + QByteArray line(MAXLINE, char()); QByteArray format; // Parse header do { - len = device->readLine(line.data(), MAXLINE); - + len = device->readLine(line.data(), line.size()); + if (len < 0) { + break; + } if (line.startsWith("FORMAT=")) { format = line.mid(7, len - 7).trimmed(); } @@ -173,7 +175,11 @@ public: return h; } - len = device->readLine(line.data(), MAXLINE); + len = device->readLine(line.data(), line.size()); + if (len < 0) { + qCDebug(HDRPLUGIN) << "Invalid HDR file, error while reading the first line after the header"; + return h; + } line.resize(len); /*