Coverage Report

Created: 2026-04-29 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/network/access/qdecompresshelper_p.h
Line
Count
Source
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
24
QT_BEGIN_NAMESPACE
25
26
class QIODevice;
27
class QDecompressHelper
28
{
29
public:
30
    enum ContentEncoding {
31
        None,
32
        Deflate,
33
        GZip,
34
        Brotli,
35
        Zstandard,
36
    };
37
38
0
    QDecompressHelper() = default;
39
    Q_NETWORK_EXPORT ~QDecompressHelper();
40
41
    Q_NETWORK_EXPORT bool setEncoding(QByteArrayView contentEncoding);
42
43
    Q_NETWORK_EXPORT bool isCountingBytes() const;
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
57
    Q_NETWORK_EXPORT void clear();
58
59
    Q_NETWORK_EXPORT void setDecompressedSafetyCheckThreshold(qint64 threshold);
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
66
private:
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;
103
    size_t brotliUnconsumedAmount = 0;
104
#endif
105
};
106
107
QT_END_NAMESPACE
108
109
#endif // DECOMPRESS_HELPER_P_H