~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_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       vli_decoder.c
 
6
/// \brief      Decodes 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_decode(lzma_vli *restrict vli, size_t *vli_pos,
 
20
                const uint8_t *restrict in, size_t *restrict in_pos,
 
21
                size_t in_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
                *vli = 0;
 
28
 
 
29
                // If there's no input, use LZMA_DATA_ERROR. This way it is
 
30
                // easy to decode VLIs from buffers that have known size,
 
31
                // and get the correct error code in case the buffer is
 
32
                // too short.
 
33
                if (*in_pos >= in_size)
 
34
                        return LZMA_DATA_ERROR;
 
35
 
 
36
        } else {
 
37
                // Initialize *vli when starting to decode a new integer.
 
38
                if (*vli_pos == 0)
 
39
                        *vli = 0;
 
40
 
 
41
                // Validate the arguments.
 
42
                if (*vli_pos >= LZMA_VLI_BYTES_MAX
 
43
                                || (*vli >> (*vli_pos * 7)) != 0)
 
44
                        return LZMA_PROG_ERROR;;
 
45
 
 
46
                if (*in_pos >= in_size)
 
47
                        return LZMA_BUF_ERROR;
 
48
        }
 
49
 
 
50
        do {
 
51
                // Read the next byte. Use a temporary variable so that we
 
52
                // can update *in_pos immediatelly.
 
53
                const uint8_t byte = in[*in_pos];
 
54
                ++*in_pos;
 
55
 
 
56
                // Add the newly read byte to *vli.
 
57
                *vli += (lzma_vli)(byte & 0x7F) << (*vli_pos * 7);
 
58
                ++*vli_pos;
 
59
 
 
60
                // Check if this is the last byte of a multibyte integer.
 
61
                if ((byte & 0x80) == 0) {
 
62
                        // We don't allow using variable-length integers as
 
63
                        // padding i.e. the encoding must use the most the
 
64
                        // compact form.
 
65
                        if (byte == 0x00 && *vli_pos > 1)
 
66
                                return LZMA_DATA_ERROR;
 
67
 
 
68
                        return vli_pos == &vli_pos_internal
 
69
                                        ? LZMA_OK : LZMA_STREAM_END;
 
70
                }
 
71
 
 
72
                // There is at least one more byte coming. If we have already
 
73
                // read maximum number of bytes, the integer is considered
 
74
                // corrupt.
 
75
                //
 
76
                // If we need bigger integers in future, old versions liblzma
 
77
                // will confusingly indicate the file being corrupt istead of
 
78
                // unsupported. I suppose it's still better this way, because
 
79
                // in the foreseeable future (writing this in 2008) the only
 
80
                // reason why files would appear having over 63-bit integers
 
81
                // is that the files are simply corrupt.
 
82
                if (*vli_pos == LZMA_VLI_BYTES_MAX)
 
83
                        return LZMA_DATA_ERROR;
 
84
 
 
85
        } while (*in_pos < in_size);
 
86
 
 
87
        return vli_pos == &vli_pos_internal ? LZMA_DATA_ERROR : LZMA_OK;
 
88
}