~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/vli_encoder.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       vli_encoder.c
 
6
/// \brief      Encodes variable-length integers
 
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 "common.h"
 
16
 
 
17
 
 
18
extern LZMA_API(lzma_ret)
 
19
lzma_vli_encode(lzma_vli vli, size_t *vli_pos,
 
20
                uint8_t *restrict out, size_t *restrict out_pos,
 
21
                size_t out_size)
 
22
{
 
23
        // If we haven't been given vli_pos, work in single-call mode.
 
24
        size_t vli_pos_internal = 0;
 
25
        if (vli_pos == NULL) {
 
26
                vli_pos = &vli_pos_internal;
 
27
 
 
28
                // In single-call mode, we expect that the caller has
 
29
                // reserved enough output space.
 
30
                if (*out_pos >= out_size)
 
31
                        return LZMA_PROG_ERROR;
 
32
        } else {
 
33
                // This never happens when we are called by liblzma, but
 
34
                // may happen if called directly from an application.
 
35
                if (*out_pos >= out_size)
 
36
                        return LZMA_BUF_ERROR;
 
37
        }
 
38
 
 
39
        // Validate the arguments.
 
40
        if (*vli_pos >= LZMA_VLI_BYTES_MAX || vli > LZMA_VLI_MAX)
 
41
                return LZMA_PROG_ERROR;
 
42
 
 
43
        // Shift vli so that the next bits to encode are the lowest. In
 
44
        // single-call mode this never changes vli since *vli_pos is zero.
 
45
        vli >>= *vli_pos * 7;
 
46
 
 
47
        // Write the non-last bytes in a loop.
 
48
        while (vli >= 0x80) {
 
49
                // We don't need *vli_pos during this function call anymore,
 
50
                // but update it here so that it is ready if we need to
 
51
                // return before the whole integer has been decoded.
 
52
                ++*vli_pos;
 
53
                assert(*vli_pos < LZMA_VLI_BYTES_MAX);
 
54
 
 
55
                // Write the next byte.
 
56
                out[*out_pos] = (uint8_t)(vli) | 0x80;
 
57
                vli >>= 7;
 
58
 
 
59
                if (++*out_pos == out_size)
 
60
                        return vli_pos == &vli_pos_internal
 
61
                                        ? LZMA_PROG_ERROR : LZMA_OK;
 
62
        }
 
63
 
 
64
        // Write the last byte.
 
65
        out[*out_pos] = (uint8_t)(vli);
 
66
        ++*out_pos;
 
67
        ++*vli_pos;
 
68
 
 
69
        return vli_pos == &vli_pos_internal ? LZMA_OK : LZMA_STREAM_END;
 
70
 
 
71
}