Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/package/source/zipapi/MemoryByteGrabber.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
#ifndef INCLUDED_PACKAGE_SOURCE_ZIPAPI_MEMORYBYTEGRABBER_HXX
20
#define INCLUDED_PACKAGE_SOURCE_ZIPAPI_MEMORYBYTEGRABBER_HXX
21
22
#include <com/sun/star/uno/Sequence.h>
23
24
class MemoryByteGrabber final
25
{
26
    const sal_Int8 *mpBuffer;
27
    sal_Int32 mnCurrent, mnEnd;
28
public:
29
    MemoryByteGrabber ( const css::uno::Sequence < sal_Int8 > & rBuffer )
30
0
    : mpBuffer ( rBuffer.getConstArray() )
31
0
    , mnCurrent ( 0 )
32
0
    , mnEnd ( rBuffer.getLength() )
33
0
    {
34
0
    }
35
    MemoryByteGrabber ( const sal_Int8* pBuffer, sal_Int32 nBufLen )
36
516k
    : mpBuffer ( pBuffer )
37
516k
    , mnCurrent ( 0 )
38
516k
    , mnEnd ( nBufLen )
39
516k
    {
40
516k
    }
41
    MemoryByteGrabber(css::uno::Sequence<sal_Int8> &&) = delete;
42
43
411k
    const sal_Int8 * getCurrentPos () const { return mpBuffer + mnCurrent; }
44
45
411k
    sal_Int32 remainingSize() const { return mnEnd - mnCurrent; }
46
47
    // XInputStream chained
48
49
    /// @throws css::io::NotConnectedException
50
    /// @throws css::io::BufferSizeExceededException
51
    /// @throws css::io::IOException
52
    /// @throws css::uno::RuntimeException
53
    void skipBytes( sal_Int32 nBytesToSkip )
54
2.69M
    {
55
2.69M
        mnCurrent += nBytesToSkip;
56
2.69M
    }
57
58
    sal_Int8 ReadUInt8()
59
23.7k
    {
60
23.7k
        if (mnCurrent + 1 > mnEnd)
61
0
            return 0;
62
23.7k
        sal_uInt8 nInt8 = mpBuffer[mnCurrent++];
63
23.7k
        return nInt8;
64
23.7k
    }
65
66
    // XSeekable chained...
67
    sal_Int16 ReadInt16()
68
4.74M
    {
69
4.74M
        if (mnCurrent + 2 > mnEnd )
70
500k
            return 0;
71
4.24M
        sal_Int16 nInt16  =   mpBuffer[mnCurrent++] & 0xFF;
72
4.24M
        nInt16 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
73
4.24M
        return nInt16;
74
4.74M
    }
75
76
    sal_Int16 ReadUInt16()
77
3.10M
    {
78
3.10M
        if (mnCurrent + 2 > mnEnd )
79
500k
            return 0;
80
2.60M
        sal_uInt16 nInt16  =  mpBuffer[mnCurrent++] & 0xFF;
81
2.60M
        nInt16 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
82
2.60M
        return nInt16;
83
3.10M
    }
84
85
    sal_Int32 ReadInt32()
86
2.05M
    {
87
2.05M
        if (mnCurrent + 4 > mnEnd )
88
15
            return 0;
89
90
2.05M
        sal_Int32 nInt32  =   mpBuffer[mnCurrent++] & 0xFF;
91
2.05M
        nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
92
2.05M
        nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 16;
93
2.05M
        nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 24;
94
2.05M
        return nInt32;
95
2.05M
    }
96
97
    sal_uInt32 ReadUInt32()
98
2.88M
    {
99
2.88M
        if (mnCurrent + 4 > mnEnd )
100
0
            return 0;
101
102
2.88M
        sal_uInt32 nInt32  =   mpBuffer [mnCurrent++] & 0xFF;
103
2.88M
        nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 8;
104
2.88M
        nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 16;
105
2.88M
        nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 24;
106
2.88M
        return nInt32;
107
2.88M
    }
108
109
    sal_uInt64 ReadUInt64()
110
1.17k
    {
111
1.17k
        if (mnCurrent + 8 > mnEnd)
112
23
            return 0;
113
114
1.15k
        sal_uInt64 nInt64 = mpBuffer[mnCurrent++] & 0xFF;
115
1.15k
        nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 8;
116
1.15k
        nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 16;
117
1.15k
        nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 24;
118
1.15k
        nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 32;
119
1.15k
        nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 40;
120
1.15k
        nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 48;
121
1.15k
        nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 56;
122
1.15k
        return nInt64;
123
1.17k
    }
124
};
125
126
#endif
127
128
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */