1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
From 540a693532841563dbca2ca263ddbb977d2bad6b Mon Sep 17 00:00:00 2001
From: Pino Toscano <pino@kde.org>
Date: Fri, 22 Nov 2024 20:15:24 +0100
Subject: [PATCH] k7zip: fix/simplify GetUi*() functions
Rather than taking the offset for the buffer passed in, directly pass
the buffer to the start of the data to read from.
This:
- fixes reading of 7zip files on certain architectures (32bit big
endian)
- simplifies the GetUi*() functions, which do not need to take offsets
into account
- fixes GetUi16() not using the offset for reading the 2nd byte;
it did not cause any issue as GetUi16() used to be always invoked
with offset=0
(cherry picked from commit 776efbfc5784cacfde2e0036452ddabd06cf4138)
---
src/k7zip.cpp | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/k7zip.cpp b/src/k7zip.cpp
index fd2517c..5fdb514 100644
--- a/src/k7zip.cpp
+++ b/src/k7zip.cpp
@@ -37,24 +37,24 @@ static const unsigned char k7zip_signature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1
// static const unsigned char XZ_HEADER_MAGIC[6] = { 0xFD, '7', 'z', 'X', 'Z', 0x00 };
/* clang-format off */
-static QChar GetUi16(const char *p, quint64 offset)
+static QChar GetUi16(const char *p)
{
- return QChar(static_cast<unsigned char>(p[offset + 0])
+ return QChar(static_cast<unsigned char>(p[0])
| (static_cast<unsigned char>(p[1]) << 8));
}
-static quint32 GetUi32(const char *p, quint64 offset)
+static quint32 GetUi32(const char *p)
{
- return (static_cast<unsigned char>(p[offset + 0])
- | (static_cast<unsigned char>(p[offset + 1]) << 8)
- | (static_cast<unsigned char>(p[offset + 2]) << 16)
- | (static_cast<unsigned char>(p[offset + 3]) << 24));
+ return (static_cast<unsigned char>(p[0])
+ | (static_cast<unsigned char>(p[1]) << 8)
+ | (static_cast<unsigned char>(p[2]) << 16)
+ | (static_cast<unsigned char>(p[3]) << 24));
}
-static quint64 GetUi64(const char *p, quint64 offset)
+static quint64 GetUi64(const char *p)
{
- return (GetUi32(p, offset)
- | (static_cast<quint64>(GetUi32(p, offset + 4)) << 32));
+ return (GetUi32(p)
+ | (static_cast<quint64>(GetUi32(p + 4)) << 32));
}
static quint32 lzma2_dic_size_from_prop(int p)
@@ -586,7 +586,7 @@ quint32 K7Zip::K7ZipPrivate::readUInt32()
return 0;
}
- quint32 res = GetUi32(buffer, pos);
+ quint32 res = GetUi32(buffer + pos);
pos += 4;
return res;
}
@@ -598,7 +598,7 @@ quint64 K7Zip::K7ZipPrivate::readUInt64()
return 0;
}
- quint64 res = GetUi64(buffer, pos);
+ quint64 res = GetUi64(buffer + pos);
pos += 8;
return res;
}
@@ -654,7 +654,7 @@ QString K7Zip::K7ZipPrivate::readString()
QString p;
for (int i = 0; i < len; i++, buf += 2) {
- p += GetUi16(buf, 0);
+ p += GetUi16(buf);
}
pos += rem + 2;
@@ -732,7 +732,7 @@ void K7Zip::K7ZipPrivate::readHashDigests(int numItems, QVector<bool> &digestsDe
for (int i = 0; i < numItems; i++) {
quint32 crc = 0;
if (digestsDefined[i]) {
- crc = GetUi32(buffer, pos);
+ crc = GetUi32(buffer + pos);
pos += 4;
}
digests.append(crc);
@@ -2345,10 +2345,10 @@ bool K7Zip::openArchive(QIODevice::OpenMode mode)
}*/
// get Start Header CRC
- quint32 startHeaderCRC = GetUi32(header, 8);
- quint64 nextHeaderOffset = GetUi64(header, 12);
- quint64 nextHeaderSize = GetUi64(header, 20);
- quint32 nextHeaderCRC = GetUi32(header, 28);
+ quint32 startHeaderCRC = GetUi32(header + 8);
+ quint64 nextHeaderOffset = GetUi64(header + 12);
+ quint64 nextHeaderSize = GetUi64(header + 20);
+ quint32 nextHeaderCRC = GetUi32(header + 28);
quint32 crc = crc32(0, (Bytef *)(header + 0xC), 20);
--
2.45.2
|