Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdecompresshelper_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef DECOMPRESS_HELPER_P_H
6#define DECOMPRESS_HELPER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the Network Access API. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/qtnetworkexports.h>
20#include <QtNetwork/private/qbytedatabuffer_p.h>
21
22#include <memory>
23
24QT_BEGIN_NAMESPACE
25
26class QIODevice;
28{
29public:
37
38 QDecompressHelper() = default;
40
41 Q_NETWORK_EXPORT bool setEncoding(QByteArrayView contentEncoding);
42
44 Q_NETWORK_EXPORT void setCountingBytesEnabled(bool shouldCount);
45
46 Q_NETWORK_EXPORT qint64 uncompressedSize() const;
47
48 Q_NETWORK_EXPORT bool hasData() const;
49 Q_NETWORK_EXPORT void feed(const QByteArray &data);
50 Q_NETWORK_EXPORT void feed(QByteArray &&data);
51 Q_NETWORK_EXPORT void feed(const QByteDataBuffer &buffer);
52 Q_NETWORK_EXPORT void feed(QByteDataBuffer &&buffer);
53 Q_NETWORK_EXPORT qsizetype read(char *data, qsizetype maxSize);
54
55 Q_NETWORK_EXPORT bool isValid() const;
56
58
60
61 Q_NETWORK_EXPORT static bool isSupportedEncoding(QByteArrayView encoding);
62 Q_NETWORK_EXPORT static QByteArrayList acceptedEncoding();
63
64 Q_NETWORK_EXPORT QString errorString() const;
65
66private:
67 bool isPotentialArchiveBomb() const;
68 bool hasDataInternal() const;
69 qsizetype readInternal(char *data, qsizetype maxSize);
70
71 bool countInternal();
72 bool countInternal(const QByteArray &data);
73 bool countInternal(const QByteDataBuffer &buffer);
74
75 bool setEncoding(ContentEncoding ce);
76 qint64 encodedBytesAvailable() const;
77
78 qsizetype readZLib(char *data, qsizetype maxSize);
79 qsizetype readBrotli(char *data, qsizetype maxSize);
80 qsizetype readZstandard(char *data, qsizetype maxSize);
81
82 QByteDataBuffer compressedDataBuffer;
83 QByteDataBuffer decompressedDataBuffer;
84 const qsizetype MaxDecompressedDataBufferSize = 10 * 1024 * 1024;
85 bool decoderHasData = false;
86
87 bool countDecompressed = false;
88 std::unique_ptr<QDecompressHelper> countHelper;
89
90 QString errorStr;
91
92 // Used for calculating the ratio
93 qint64 archiveBombCheckThreshold = 10 * 1024 * 1024;
94 qint64 totalUncompressedBytes = 0;
95 qint64 totalCompressedBytes = 0;
96 qint64 totalBytesRead = 0;
97
98 ContentEncoding contentEncoding = None;
99
100 void *decoderPointer = nullptr;
101#if QT_CONFIG(brotli)
102 const uint8_t *brotliUnconsumedDataPtr = nullptr;
104#endif
105};
106
107QT_END_NAMESPACE
108
109#endif // DECOMPRESS_HELPER_P_H
Q_NETWORK_EXPORT void setCountingBytesEnabled(bool shouldCount)
Q_NETWORK_EXPORT bool setEncoding(QByteArrayView contentEncoding)
Q_NETWORK_EXPORT void feed(const QByteArray &data)
QDecompressHelper()=default
Q_NETWORK_EXPORT bool isValid() const
static Q_NETWORK_EXPORT bool isSupportedEncoding(QByteArrayView encoding)
Q_NETWORK_EXPORT bool hasData() const
Q_NETWORK_EXPORT void setDecompressedSafetyCheckThreshold(qint64 threshold)
Q_NETWORK_EXPORT void feed(QByteArray &&data)
Q_NETWORK_EXPORT bool isCountingBytes() const
Q_NETWORK_EXPORT ~QDecompressHelper()
Q_NETWORK_EXPORT void clear()