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

« back to all changes in this revision

Viewing changes to storage/tokudb/ft-index/ft/x1764.cc

  • 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: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
 
3
#ident "$Id$"
 
4
/*
 
5
COPYING CONDITIONS NOTICE:
 
6
 
 
7
  This program is free software; you can redistribute it and/or modify
 
8
  it under the terms of version 2 of the GNU General Public License as
 
9
  published by the Free Software Foundation, and provided that the
 
10
  following conditions are met:
 
11
 
 
12
      * Redistributions of source code must retain this COPYING
 
13
        CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
 
14
        DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
 
15
        PATENT MARKING NOTICE (below), and the PATENT RIGHTS
 
16
        GRANT (below).
 
17
 
 
18
      * Redistributions in binary form must reproduce this COPYING
 
19
        CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
 
20
        DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
 
21
        PATENT MARKING NOTICE (below), and the PATENT RIGHTS
 
22
        GRANT (below) in the documentation and/or other materials
 
23
        provided with the distribution.
 
24
 
 
25
  You should have received a copy of the GNU General Public License
 
26
  along with this program; if not, write to the Free Software
 
27
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
28
  02110-1301, USA.
 
29
 
 
30
COPYRIGHT NOTICE:
 
31
 
 
32
  TokuDB, Tokutek Fractal Tree Indexing Library.
 
33
  Copyright (C) 2007-2013 Tokutek, Inc.
 
34
 
 
35
DISCLAIMER:
 
36
 
 
37
  This program is distributed in the hope that it will be useful, but
 
38
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
39
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
40
  General Public License for more details.
 
41
 
 
42
UNIVERSITY PATENT NOTICE:
 
43
 
 
44
  The technology is licensed by the Massachusetts Institute of
 
45
  Technology, Rutgers State University of New Jersey, and the Research
 
46
  Foundation of State University of New York at Stony Brook under
 
47
  United States of America Serial No. 11/760379 and to the patents
 
48
  and/or patent applications resulting from it.
 
49
 
 
50
PATENT MARKING NOTICE:
 
51
 
 
52
  This software is covered by US Patent No. 8,185,551.
 
53
  This software is covered by US Patent No. 8,489,638.
 
54
 
 
55
PATENT RIGHTS GRANT:
 
56
 
 
57
  "THIS IMPLEMENTATION" means the copyrightable works distributed by
 
58
  Tokutek as part of the Fractal Tree project.
 
59
 
 
60
  "PATENT CLAIMS" means the claims of patents that are owned or
 
61
  licensable by Tokutek, both currently or in the future; and that in
 
62
  the absence of this license would be infringed by THIS
 
63
  IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
 
64
 
 
65
  "PATENT CHALLENGE" shall mean a challenge to the validity,
 
66
  patentability, enforceability and/or non-infringement of any of the
 
67
  PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
 
68
 
 
69
  Tokutek hereby grants to you, for the term and geographical scope of
 
70
  the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
 
71
  irrevocable (except as stated in this section) patent license to
 
72
  make, have made, use, offer to sell, sell, import, transfer, and
 
73
  otherwise run, modify, and propagate the contents of THIS
 
74
  IMPLEMENTATION, where such license applies only to the PATENT
 
75
  CLAIMS.  This grant does not include claims that would be infringed
 
76
  only as a consequence of further modifications of THIS
 
77
  IMPLEMENTATION.  If you or your agent or licensee institute or order
 
78
  or agree to the institution of patent litigation against any entity
 
79
  (including a cross-claim or counterclaim in a lawsuit) alleging that
 
80
  THIS IMPLEMENTATION constitutes direct or contributory patent
 
81
  infringement, or inducement of patent infringement, then any rights
 
82
  granted to you under this License shall terminate as of the date
 
83
  such litigation is filed.  If you or your agent or exclusive
 
84
  licensee institute or order or agree to the institution of a PATENT
 
85
  CHALLENGE, then Tokutek may terminate any rights granted to you
 
86
  under this License.
 
87
*/
 
88
 
 
89
#ident "Copyright (c) 2007-2013 Tokutek Inc.  All rights reserved."
 
90
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
 
91
 
 
92
#include <toku_stdlib.h>
 
93
#include <toku_include/toku_portability.h>
 
94
 
 
95
#include "x1764.h"
 
96
 
 
97
#define PRINT 0
 
98
 
 
99
uint32_t x1764_memory_simple (const void *buf, int len)
 
100
{
 
101
    const uint64_t *CAST_FROM_VOIDP(lbuf, buf);
 
102
    uint64_t c=0;
 
103
    while (len>=8) {
 
104
        c = c*17 + *lbuf;
 
105
        if (PRINT) printf("%d: c=%016" PRIx64 " sum=%016" PRIx64 "\n", __LINE__, *lbuf, c);
 
106
        lbuf++;
 
107
        len-=8;
 
108
    }
 
109
    if (len>0) {
 
110
        const uint8_t *cbuf=(uint8_t*)lbuf;
 
111
        int i;
 
112
        uint64_t input=0;
 
113
        for (i=0; i<len; i++) {
 
114
            input |= ((uint64_t)(cbuf[i]))<<(8*i);
 
115
        }
 
116
        c = c*17 + input;
 
117
    }
 
118
    return ~((c&0xFFFFFFFF) ^ (c>>32));
 
119
}
 
120
 
 
121
uint32_t x1764_memory (const void *vbuf, int len)
 
122
{
 
123
    const uint8_t *CAST_FROM_VOIDP(buf, vbuf);
 
124
    int len_4_words = 4*sizeof(uint64_t);
 
125
    uint64_t suma=0, sumb=0, sumc=0, sumd=0;
 
126
    while (len >= len_4_words) {
 
127
        suma = suma*(17LL*17LL*17LL*17LL) + *(uint64_t*)(buf +0*sizeof(uint64_t));
 
128
        sumb = sumb*(17LL*17LL*17LL*17LL) + *(uint64_t*)(buf +1*sizeof(uint64_t));
 
129
        sumc = sumc*(17LL*17LL*17LL*17LL) + *(uint64_t*)(buf +2*sizeof(uint64_t));
 
130
        sumd = sumd*(17LL*17LL*17LL*17LL) + *(uint64_t*)(buf +3*sizeof(uint64_t));
 
131
        buf += len_4_words;
 
132
        len -= len_4_words;
 
133
    }
 
134
    uint64_t sum = suma*17L*17L*17L + sumb*17L*17L + sumc*17L + sumd;
 
135
    assert(len>=0);
 
136
    while ((uint64_t)len>=sizeof(uint64_t)) {
 
137
        sum = sum*17 + *(uint64_t*)buf;
 
138
        buf+=sizeof(uint64_t);
 
139
        len-=sizeof(uint64_t);
 
140
    }
 
141
    if (len>0) {
 
142
        uint64_t tailsum = 0;
 
143
        for (int i=0; i<len; i++) {
 
144
            tailsum |= ((uint64_t)(buf[i]))<<(8*i);
 
145
        }
 
146
        sum = sum*17 + tailsum;
 
147
    }
 
148
    return ~((sum&0xFFFFFFFF) ^ (sum>>32));
 
149
}
 
150
 
 
151
 
 
152
void x1764_init(struct x1764 *l) {
 
153
    l->sum=0;
 
154
    l->input=0;
 
155
    l->n_input_bytes=0;
 
156
}
 
157
 
 
158
void x1764_add (struct x1764 *l, const void *vbuf, int len) {
 
159
    if (PRINT) printf("%d: n_input_bytes=%d len=%d\n", __LINE__, l->n_input_bytes, len);
 
160
    int n_input_bytes = l->n_input_bytes;
 
161
    const unsigned char *CAST_FROM_VOIDP(cbuf, vbuf);
 
162
    // Special case short inputs
 
163
    if (len==1) {
 
164
        uint64_t input = l->input | ((uint64_t)(*cbuf))<<(8*n_input_bytes);
 
165
        n_input_bytes++;
 
166
        if (n_input_bytes==8) {
 
167
            l->sum = l->sum*17 + input;
 
168
            l->n_input_bytes = 0;
 
169
            l->input = 0;
 
170
        } else {
 
171
            l->input = input;
 
172
            l->n_input_bytes = n_input_bytes;
 
173
        }
 
174
        return;
 
175
    } else if (len==2) {
 
176
        uint64_t input = l->input;
 
177
        uint64_t thisv = ((uint64_t)(*(uint16_t*)cbuf));
 
178
        if (n_input_bytes==7) {
 
179
            l->sum = l->sum*17 + (input | (thisv<<(8*7)));
 
180
            l->input = thisv>>8;
 
181
            l->n_input_bytes = 1;
 
182
        } else if (n_input_bytes==6) {
 
183
            l->sum = l->sum*17 + (input | (thisv<<(8*6)));
 
184
            l->input = 0;
 
185
            l->n_input_bytes = 0;
 
186
        } else {
 
187
            l->input = input | (thisv<<(8*n_input_bytes));
 
188
            l->n_input_bytes += 2;
 
189
        }
 
190
        return;
 
191
    }
 
192
 
 
193
    uint64_t sum;
 
194
    //assert(len>=0);
 
195
    if (n_input_bytes) {
 
196
        uint64_t input = l->input;
 
197
        if (len>=8) {
 
198
            sum = l->sum;
 
199
            while (len>=8) {
 
200
                uint64_t thisv = *(uint64_t*)cbuf;
 
201
                input |= thisv<<(8*n_input_bytes);
 
202
                sum = sum*17 + input;
 
203
                if (PRINT) printf("%d: input=%016" PRIx64 " sum=%016" PRIx64 "\n", __LINE__, input, sum);
 
204
                input = thisv>>(8*(8-n_input_bytes));
 
205
                if (PRINT) printf("%d: input=%016" PRIx64 "\n", __LINE__, input);
 
206
                len-=8;
 
207
                cbuf+=8;
 
208
                // n_input_bytes remains unchanged
 
209
                if (PRINT) printf("%d: n_input_bytes=%d len=%d\n", __LINE__, l->n_input_bytes, len);
 
210
            }
 
211
            l->sum = sum;
 
212
        }
 
213
        if (len>=4) {
 
214
            uint64_t thisv = *(uint32_t*)cbuf;
 
215
            if (n_input_bytes<4) {
 
216
                input |= thisv<<(8*n_input_bytes);
 
217
                if (PRINT) printf("%d: input=%016" PRIx64 "\n", __LINE__, input);
 
218
                n_input_bytes+=4;
 
219
            } else {
 
220
                input |= thisv<<(8*n_input_bytes);
 
221
                l->sum = l->sum*17 + input;
 
222
                if (PRINT) printf("%d: input=%016" PRIx64 " sum=%016" PRIx64 "\n", __LINE__, input, l->sum);
 
223
                input = thisv>>(8*(8-n_input_bytes));
 
224
                n_input_bytes-=4;
 
225
                if (PRINT) printf("%d: input=%016" PRIx64 " n_input_bytes=%d\n", __LINE__, input, n_input_bytes);
 
226
            }
 
227
            len-=4;
 
228
            cbuf+=4;
 
229
            if (PRINT) printf("%d: len=%d\n", __LINE__, len);
 
230
        }
 
231
        //assert(n_input_bytes<=8);
 
232
        while (n_input_bytes<8 && len) {
 
233
            input |= ((uint64_t)(*cbuf))<<(8*n_input_bytes);
 
234
            n_input_bytes++;
 
235
            cbuf++;
 
236
            len--;
 
237
        }
 
238
        //assert(len>=0);
 
239
        if (n_input_bytes<8) {
 
240
            //assert(len==0);
 
241
            l->input = input;
 
242
            l->n_input_bytes = n_input_bytes;
 
243
            if (PRINT) printf("%d: n_input_bytes=%d\n", __LINE__, l->n_input_bytes);
 
244
            return;
 
245
        }
 
246
        sum = l->sum*17 + input;
 
247
    } else {
 
248
        //assert(len>=0);
 
249
        sum = l->sum;
 
250
    }
 
251
    //assert(len>=0);
 
252
    while (len>=8) {
 
253
        sum = sum*17 + *(uint64_t*)cbuf;
 
254
        cbuf+=8;
 
255
        len -=8;
 
256
    }
 
257
    l->sum = sum;
 
258
    n_input_bytes = 0;
 
259
    uint64_t input;
 
260
    l->n_input_bytes = len;
 
261
    // Surprisingly, the loop is the fastest on bradley's laptop.
 
262
    if (1) {
 
263
        int i;
 
264
        input=0;
 
265
        for (i=0; i<len; i++) {
 
266
            input |= ((uint64_t)(cbuf[i]))<<(8*i);
 
267
        }
 
268
    } else if (0) {
 
269
        switch (len) {
 
270
        case 7: input = ((uint64_t)(*(uint32_t*)(cbuf))) | (((uint64_t)(*(uint16_t*)(cbuf+4)))<<32) | (((uint64_t)(*(cbuf+4)))<<48); break;
 
271
        case 6: input = ((uint64_t)(*(uint32_t*)(cbuf))) | (((uint64_t)(*(uint16_t*)(cbuf+4)))<<32); break;
 
272
        case 5: input = ((uint64_t)(*(uint32_t*)(cbuf))) | (((uint64_t)(*(cbuf+4)))<<32); break;
 
273
        case 4: input = ((uint64_t)(*(uint32_t*)(cbuf))); break;
 
274
        case 3: input = ((uint64_t)(*(uint16_t*)(cbuf))) | (((uint64_t)(*(cbuf+2)))<<16); break;
 
275
        case 2: input = ((uint64_t)(*(uint16_t*)(cbuf))); break;
 
276
        case 1: input = ((uint64_t)(*cbuf)); break;
 
277
        case 0: input = 0;                      break;
 
278
        default: abort();
 
279
        }
 
280
    } else {
 
281
        input=0;
 
282
        int i=0;
 
283
        if (len>=4) { input  = ((uint64_t)(*(uint32_t*)(cbuf)));        cbuf+=4; len-=4; i=4;}
 
284
        if (len>=2) { input |= ((uint64_t)(*(uint16_t*)(cbuf)))<<(i*8); cbuf+=2; len-=2; i+=2; }
 
285
        if (len>=1) { input |= ((uint64_t)(*(uint8_t *)(cbuf)))<<(i*8); /*cbuf+=1; len-=1; i++;*/ }
 
286
    }
 
287
    l->input = input;
 
288
    if (PRINT) printf("%d: n_input_bytes=%d\n", __LINE__, l->n_input_bytes);
 
289
}
 
290
uint32_t x1764_finish (struct x1764 *l) {
 
291
    if (PRINT) printf("%d: n_input_bytes=%d\n", __LINE__, l->n_input_bytes);
 
292
    int len = l->n_input_bytes;
 
293
    if (len>0) {
 
294
        l->sum = l->sum*17 + l->input;
 
295
    }
 
296
    return ~((l->sum &0xffffffff) ^ (l->sum>>32));
 
297
}