summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-03-12 19:29:10 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-03-20 15:21:46 +0000
commita86a06ef6389381b844a3fe7288a21e6fda9fe95 (patch)
tree230ef7762769b7bc7e88be3493be0f26464c6c8c /src
parent3801ffa680fa0fbcd1df7ca990330f7823adb29b (diff)
QEdidParser: Fix parsing of string descriptors with length less than 13
The EDID 1.4 spec states that string descriptors with length less than 13 are terminated with \n and padded with spaces. Since we sanitize the string by replacing non-printable characters with '-', we can't start out by replacing \n and \r with \0 to simulate a zero-terminated string, as these null bytes will then be replaced with '-'. And even if they were not, QQtring::fromLatin1(QByteArray) in Qt 6 will include any null bytes verbatim as Unicode null characters, so we'd still end up with a wrongly parsed string. We simplify the process by following the spec, truncating the byte array at the first occurrence of \n (without any check that the following bytes are pure padding), and then doing the non-printable character replacement. Change-Id: I9f4e77ddb7b1b759c08b94b29e28d8c148b5435f Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> (cherry picked from commit b4814163c78e396834ad54963073cf03449073db) Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/gui/util/qedidparser.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/gui/util/qedidparser.cpp b/src/gui/util/qedidparser.cpp
index 8af9ac8514..d1619acaca 100644
--- a/src/gui/util/qedidparser.cpp
+++ b/src/gui/util/qedidparser.cpp
@@ -269,16 +269,22 @@ QString QEdidParser::parseEdidString(const quint8 *data)
{
QByteArray buffer(reinterpret_cast<const char *>(data), 13);
- // Erase carriage return and line feed
- buffer = buffer.replace('\r', '\0').replace('\n', '\0');
+ for (int i = 0; i < buffer.size(); ++i) {
+ // If there are less than 13 characters in the string, the string
+ // is terminated with the ASCII code ‘0Ah’ (line feed) and padded
+ // with ASCII code ‘20h’ (space). See EDID 1.4, sections 3.10.3.1,
+ // 3.10.3.2, and 3.10.3.4.
+ if (buffer[i] == '\n') {
+ buffer.truncate(i);
+ break;
+ }
- // Replace non-printable characters with dash
- for (int i = 0; i < buffer.count(); ++i) {
+ // Replace non-printable characters with dash
if (buffer[i] < '\040' || buffer[i] > '\176')
buffer[i] = '-';
}
- return QString::fromLatin1(buffer.trimmed());
+ return QString::fromLatin1(buffer);
}
QT_END_NAMESPACE