Coverage Report

Created: 2025-10-10 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/lzo-2.10/src/lzo2a_d.ch
Line
Count
Source
1
/* lzo2a_d.ch -- implementation of the LZO2A decompression algorithm
2
3
   This file is part of the LZO real-time data compression library.
4
5
   Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
6
   All Rights Reserved.
7
8
   The LZO library is free software; you can redistribute it and/or
9
   modify it under the terms of the GNU General Public License as
10
   published by the Free Software Foundation; either version 2 of
11
   the License, or (at your option) any later version.
12
13
   The LZO library is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
18
   You should have received a copy of the GNU General Public License
19
   along with the LZO library; see the file COPYING.
20
   If not, write to the Free Software Foundation, Inc.,
21
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23
   Markus F.X.J. Oberhumer
24
   <markus@oberhumer.com>
25
   http://www.oberhumer.com/opensource/lzo/
26
 */
27
28
29
#include "lzo1_d.ch"
30
31
32
/***********************************************************************
33
// decompress a block of data.
34
************************************************************************/
35
36
325k
#define _NEEDBYTE   NEED_IP(1)
37
325k
#define _NEXTBYTE   (*ip++)
38
39
LZO_PUBLIC(int)
40
DO_DECOMPRESS    ( const lzo_bytep in , lzo_uint  in_len,
41
                         lzo_bytep out, lzo_uintp out_len,
42
                         lzo_voidp wrkmem )
43
646
{
44
646
    lzo_bytep op;
45
646
    const lzo_bytep ip;
46
646
    const lzo_bytep m_pos;
47
48
646
    lzo_uint t;
49
646
    const lzo_bytep const ip_end = in + in_len;
50
#if defined(HAVE_ANY_OP)
51
    lzo_bytep const op_end = out + *out_len;
52
#endif
53
54
646
    lzo_uint32_t b = 0;     /* bit buffer */
55
646
    unsigned k = 0;         /* bits in bit buffer */
56
57
646
    LZO_UNUSED(wrkmem);
58
59
646
    op = out;
60
646
    ip = in;
61
62
2.28M
    while (TEST_IP_AND_TEST_OP)
63
2.28M
    {
64
2.28M
        NEEDBITS(1);
65
2.28M
        if (MASKBITS(1) == 0)
66
2.14M
        {
67
2.14M
            DUMPBITS(1);
68
            /* a literal */
69
2.14M
            NEED_IP(1); NEED_OP(1);
70
2.14M
            *op++ = *ip++;
71
2.14M
            continue;
72
2.14M
        }
73
145k
        DUMPBITS(1);
74
75
145k
        NEEDBITS(1);
76
145k
        if (MASKBITS(1) == 0)
77
85.7k
        {
78
85.7k
            DUMPBITS(1);
79
            /* a M1 match */
80
85.7k
            NEEDBITS(2);
81
85.7k
            t = M1_MIN_LEN + (lzo_uint) MASKBITS(2);
82
85.7k
            DUMPBITS(2);
83
85.7k
            NEED_IP(1); NEED_OP(t);
84
85.7k
            m_pos = op - 1 - *ip++;
85
85.7k
            assert(m_pos >= out); assert(m_pos < op);
86
85.7k
            TEST_LB(m_pos);
87
85.7k
            MEMCPY_DS(op,m_pos,t);
88
85.7k
            continue;
89
85.7k
        }
90
60.0k
        DUMPBITS(1);
91
92
60.0k
        NEED_IP(2);
93
60.0k
        t = *ip++;
94
60.0k
        m_pos = op;
95
60.0k
        m_pos -= (t & 31) | (((lzo_uint) *ip++) << 5);
96
60.0k
        t >>= 5;
97
60.0k
        if (t == 0)
98
24.8k
        {
99
#if (SWD_N >= 8192)
100
            NEEDBITS(1);
101
            t = MASKBITS(1);
102
            DUMPBITS(1);
103
            if (t == 0)
104
                t = 10 - 1;
105
            else
106
            {
107
                /* a M3 match */
108
                m_pos -= 8192;      /* t << 13 */
109
                t = M3_MIN_LEN - 1;
110
            }
111
#else
112
24.8k
            t = 10 - 1;
113
24.8k
#endif
114
24.8k
            NEED_IP(1);
115
42.0k
            while (*ip == 0)
116
17.1k
            {
117
17.1k
                t += 255;
118
17.1k
                ip++;
119
17.1k
                TEST_OV(t);
120
17.1k
                NEED_IP(1);
121
17.1k
            }
122
24.8k
            t += *ip++;
123
24.8k
        }
124
35.2k
        else
125
35.2k
        {
126
35.2k
#if defined(LZO_EOF_CODE)
127
35.2k
            if (m_pos == op)
128
646
                goto eof_found;
129
34.5k
#endif
130
34.5k
            t += 2;
131
34.5k
        }
132
60.0k
        assert(m_pos >= out); assert(m_pos < op);
133
59.3k
        TEST_LB(m_pos);
134
59.3k
        NEED_OP(t);
135
59.3k
        MEMCPY_DS(op,m_pos,t);
136
59.3k
    }
137
138
139
0
#if defined(LZO_EOF_CODE)
140
#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
141
    /* no EOF code was found */
142
    *out_len = pd(op, out);
143
    return LZO_E_EOF_NOT_FOUND;
144
#endif
145
146
646
eof_found:
147
646
    assert(t == 1);
148
646
#endif
149
646
    *out_len = pd(op, out);
150
646
    return (ip == ip_end ? LZO_E_OK :
151
646
           (ip < ip_end  ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
152
153
154
#if defined(HAVE_NEED_IP)
155
input_overrun:
156
    *out_len = pd(op, out);
157
    return LZO_E_INPUT_OVERRUN;
158
#endif
159
160
#if defined(HAVE_NEED_OP)
161
output_overrun:
162
    *out_len = pd(op, out);
163
    return LZO_E_OUTPUT_OVERRUN;
164
#endif
165
166
#if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
167
lookbehind_overrun:
168
    *out_len = pd(op, out);
169
    return LZO_E_LOOKBEHIND_OVERRUN;
170
#endif
171
646
}
172
173
174
/* vim:set ts=4 sw=4 et: */