~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to storage/tokudb/ft-index/third_party/xz-4.999.9beta/src/liblzma/common/auto_decoder.c

  • Committer: Package Import Robot
  • Author(s): James Page, Otto Kekäläinen
  • Date: 2014-02-17 16:51:52 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140217165152-k315d3175g865kkx
Tags: 5.5.35-1
[ Otto Kekäläinen ]
* New upstream release, fixing the following security issues:
  - Buffer overflow in client/mysql.cc (Closes: #737597).
    - CVE-2014-0001
  - http://www.oracle.com/technetwork/topics/security/cpujan2014-1972949.html
    - CVE-2013-5891
    - CVE-2013-5908
    - CVE-2014-0386
    - CVE-2014-0393
    - CVE-2014-0401
    - CVE-2014-0402
    - CVE-2014-0412
    - CVE-2014-0420
    - CVE-2014-0437
* Upstream https://mariadb.atlassian.net/browse/MDEV-4902
  fixes compatibility with Bison 3.0 (Closes: #733002)
* Updated Russian debconf translation (Closes: #734426)
* Updated Japanese debconf translation (Closes: #735284)
* Updated French debconf translation (Closes: #736480)
* Renamed SONAME properly (Closes: #732967)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 
2
// vim: expandtab:ts=8:sw=4:softtabstop=4:
 
3
///////////////////////////////////////////////////////////////////////////////
 
4
//
 
5
/// \file       auto_decoder.c
 
6
/// \brief      Autodetect between .xz Stream and .lzma (LZMA_Alone) formats
 
7
//
 
8
//  Author:     Lasse Collin
 
9
//
 
10
//  This file has been put into the public domain.
 
11
//  You can do whatever you want with this file.
 
12
//
 
13
///////////////////////////////////////////////////////////////////////////////
 
14
 
 
15
#include "stream_decoder.h"
 
16
#include "alone_decoder.h"
 
17
 
 
18
 
 
19
struct lzma_coder_s {
 
20
        /// Stream decoder or LZMA_Alone decoder
 
21
        lzma_next_coder next;
 
22
 
 
23
        uint64_t memlimit;
 
24
        uint32_t flags;
 
25
 
 
26
        enum {
 
27
                SEQ_INIT,
 
28
                SEQ_CODE,
 
29
                SEQ_FINISH,
 
30
        } sequence;
 
31
};
 
32
 
 
33
 
 
34
static lzma_ret
 
35
auto_decode(lzma_coder *coder, lzma_allocator *allocator,
 
36
                const uint8_t *restrict in, size_t *restrict in_pos,
 
37
                size_t in_size, uint8_t *restrict out,
 
38
                size_t *restrict out_pos, size_t out_size, lzma_action action)
 
39
{
 
40
        switch (coder->sequence) {
 
41
        case SEQ_INIT:
 
42
                if (*in_pos >= in_size)
 
43
                        return LZMA_OK;
 
44
 
 
45
                // Update the sequence now, because we want to continue from
 
46
                // SEQ_CODE even if we return some LZMA_*_CHECK.
 
47
                coder->sequence = SEQ_CODE;
 
48
 
 
49
                // Detect the file format. For now this is simple, since if
 
50
                // it doesn't start with 0xFD (the first magic byte of the
 
51
                // new format), it has to be LZMA_Alone, or something that
 
52
                // we don't support at all.
 
53
                if (in[*in_pos] == 0xFD) {
 
54
                        return_if_error(lzma_stream_decoder_init(
 
55
                                        &coder->next, allocator,
 
56
                                        coder->memlimit, coder->flags));
 
57
                } else {
 
58
                        return_if_error(lzma_alone_decoder_init(&coder->next,
 
59
                                        allocator, coder->memlimit));
 
60
 
 
61
                        // If the application wants to know about missing
 
62
                        // integrity check or about the check in general, we
 
63
                        // need to handle it here, because LZMA_Alone decoder
 
64
                        // doesn't accept any flags.
 
65
                        if (coder->flags & LZMA_TELL_NO_CHECK)
 
66
                                return LZMA_NO_CHECK;
 
67
 
 
68
                        if (coder->flags & LZMA_TELL_ANY_CHECK)
 
69
                                return LZMA_GET_CHECK;
 
70
                }
 
71
 
 
72
        // Fall through
 
73
 
 
74
        case SEQ_CODE: {
 
75
                const lzma_ret ret = coder->next.code(
 
76
                                coder->next.coder, allocator,
 
77
                                in, in_pos, in_size,
 
78
                                out, out_pos, out_size, action);
 
79
                if (ret != LZMA_STREAM_END
 
80
                                || (coder->flags & LZMA_CONCATENATED) == 0)
 
81
                        return ret;
 
82
 
 
83
                coder->sequence = SEQ_FINISH;
 
84
        }
 
85
 
 
86
        // Fall through
 
87
 
 
88
        case SEQ_FINISH:
 
89
                // When LZMA_DECODE_CONCATENATED was used and we were decoding
 
90
                // LZMA_Alone file, we need to check check that there is no
 
91
                // trailing garbage and wait for LZMA_FINISH.
 
92
                if (*in_pos < in_size)
 
93
                        return LZMA_DATA_ERROR;
 
94
 
 
95
                return action == LZMA_FINISH ? LZMA_STREAM_END : LZMA_OK;
 
96
 
 
97
        default:
 
98
                assert(0);
 
99
                return LZMA_PROG_ERROR;
 
100
        }
 
101
}
 
102
 
 
103
 
 
104
static void
 
105
auto_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
 
106
{
 
107
        lzma_next_end(&coder->next, allocator);
 
108
        lzma_free(coder, allocator);
 
109
        return;
 
110
}
 
111
 
 
112
 
 
113
static lzma_check
 
114
auto_decoder_get_check(const lzma_coder *coder)
 
115
{
 
116
        // It is LZMA_Alone if get_check is NULL.
 
117
        return coder->next.get_check == NULL ? LZMA_CHECK_NONE
 
118
                        : coder->next.get_check(coder->next.coder);
 
119
}
 
120
 
 
121
 
 
122
static lzma_ret
 
123
auto_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
 
124
                uint64_t *old_memlimit, uint64_t new_memlimit)
 
125
{
 
126
        lzma_ret ret;
 
127
 
 
128
        if (coder->next.memconfig != NULL) {
 
129
                ret = coder->next.memconfig(coder->next.coder,
 
130
                                memusage, old_memlimit, new_memlimit);
 
131
                assert(*old_memlimit == coder->memlimit);
 
132
        } else {
 
133
                // No coder is configured yet. Use the base value as
 
134
                // the current memory usage.
 
135
                *memusage = LZMA_MEMUSAGE_BASE;
 
136
                *old_memlimit = coder->memlimit;
 
137
                ret = LZMA_OK;
 
138
        }
 
139
 
 
140
        if (ret == LZMA_OK && new_memlimit != 0)
 
141
                coder->memlimit = new_memlimit;
 
142
 
 
143
        return ret;
 
144
}
 
145
 
 
146
 
 
147
static lzma_ret
 
148
auto_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
 
149
                uint64_t memlimit, uint32_t flags)
 
150
{
 
151
        lzma_next_coder_init(&auto_decoder_init, next, allocator);
 
152
 
 
153
        if (memlimit == 0)
 
154
                return LZMA_PROG_ERROR;
 
155
 
 
156
        if (flags & ~LZMA_SUPPORTED_FLAGS)
 
157
                return LZMA_OPTIONS_ERROR;
 
158
 
 
159
        if (next->coder == NULL) {
 
160
                next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
 
161
                if (next->coder == NULL)
 
162
                        return LZMA_MEM_ERROR;
 
163
 
 
164
                next->code = &auto_decode;
 
165
                next->end = &auto_decoder_end;
 
166
                next->get_check = &auto_decoder_get_check;
 
167
                next->memconfig = &auto_decoder_memconfig;
 
168
                next->coder->next = LZMA_NEXT_CODER_INIT;
 
169
        }
 
170
 
 
171
        next->coder->memlimit = memlimit;
 
172
        next->coder->flags = flags;
 
173
        next->coder->sequence = SEQ_INIT;
 
174
 
 
175
        return LZMA_OK;
 
176
}
 
177
 
 
178
 
 
179
extern LZMA_API(lzma_ret)
 
180
lzma_auto_decoder(lzma_stream *strm, uint64_t memlimit, uint32_t flags)
 
181
{
 
182
        lzma_next_strm_init(auto_decoder_init, strm, memlimit, flags);
 
183
 
 
184
        strm->internal->supported_actions[LZMA_RUN] = true;
 
185
        strm->internal->supported_actions[LZMA_FINISH] = true;
 
186
 
 
187
        return LZMA_OK;
 
188
}