~ubuntu-branches/ubuntu/lucid/mpg123/lucid

« back to all changes in this revision

Viewing changes to src/decode_i386.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2007-02-05 23:18:31 UTC
  • mfrom: (4.1.5 feisty)
  • Revision ID: james.westby@ubuntu.com-20070205231831-d9jsbodape2vfx2i
Tags: 0.61-5
src/httpget.c: Fix potential denial of service attack on premature
end-of-file from HTTP server (CVE-2007-0578). Patch taken from upstream's
0.64 release. Closes: #409296

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        decode_i386.c: decode for i386 (really faster?)
 
3
 
 
4
        copyright 1995-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
 
5
        see COPYING and AUTHORS files in distribution or http://mpg123.de
 
6
        initially written by Michael Hipp
 
7
 
 
8
        slighlty optimized for machines without autoincrement/decrement.
 
9
        The performance is highly compiler dependend. Maybe
 
10
        the decode.c version for 'normal' processor may be faster
 
11
        even for Intel processors.
 
12
*/
 
13
 
 
14
#include <stdlib.h>
 
15
#include <math.h>
 
16
#include <string.h>
 
17
 
 
18
#include "config.h"
 
19
#include "mpg123.h"
 
20
 
 
21
#if 0
 
22
 /* old WRITE_SAMPLE */
 
23
#define WRITE_SAMPLE(samples,sum,clip) \
 
24
  if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
 
25
  else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
 
26
  else { *(samples) = sum; }
 
27
#else
 
28
 /* new WRITE_SAMPLE */
 
29
 /* keep in mind that we are on known little-endian i386 here and special tricks are allowed... */
 
30
#define WRITE_SAMPLE(samples,sum,clip) { \
 
31
  double dtemp; int v; /* sizeof(int) == 4 */ \
 
32
  dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0)) + (sum);  \
 
33
  v = ((*(int *)&dtemp) - 0x80000000); \
 
34
  if( v > 32767) { *(samples) = 0x7fff; (clip)++; } \
 
35
  else if( v < -32768) { *(samples) = -0x8000; (clip)++; } \
 
36
  else { *(samples) = v; }  \
 
37
}
 
38
#endif
 
39
 
 
40
int synth_1to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt)
 
41
{
 
42
  short samples_tmp[64];
 
43
  short *tmp1 = samples_tmp + channel;
 
44
  int i,ret;
 
45
  int pnt1 = 0;
 
46
 
 
47
  ret = synth_1to1(bandPtr,channel,(unsigned char *)samples_tmp,&pnt1);
 
48
  samples += channel + *pnt;
 
49
 
 
50
  for(i=0;i<32;i++) {
 
51
    *samples = conv16to8[*tmp1>>AUSHIFT];
 
52
    samples += 2;
 
53
    tmp1 += 2;
 
54
  }
 
55
  *pnt += 64;
 
56
 
 
57
  return ret;
 
58
}
 
59
 
 
60
int synth_1to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt) 
 
61
{
 
62
  short samples_tmp[64];
 
63
  short *tmp1 = samples_tmp;
 
64
  int i,ret;
 
65
  int pnt1 = 0;
 
66
 
 
67
  ret = synth_1to1(bandPtr,0,(unsigned char *)samples_tmp,&pnt1);
 
68
  samples += *pnt;
 
69
 
 
70
  for(i=0;i<32;i++) {
 
71
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
72
    tmp1+=2;
 
73
  }
 
74
  *pnt += 32;
 
75
 
 
76
  return ret;
 
77
}
 
78
 
 
79
int synth_1to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
 
80
{
 
81
  short samples_tmp[64];
 
82
  short *tmp1 = samples_tmp;
 
83
  int i,ret;
 
84
  int pnt1 = 0;
 
85
 
 
86
  ret = synth_1to1(bandPtr,0,(unsigned char *)samples_tmp,&pnt1);
 
87
  samples += *pnt;
 
88
 
 
89
  for(i=0;i<32;i++) {
 
90
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
91
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
92
    tmp1 += 2;
 
93
  }
 
94
  *pnt += 64;
 
95
 
 
96
  return ret;
 
97
}
 
98
 
 
99
int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
 
100
{
 
101
  short samples_tmp[64];
 
102
  short *tmp1 = samples_tmp;
 
103
  int i,ret;
 
104
  int pnt1 = 0;
 
105
 
 
106
  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
 
107
  samples += *pnt;
 
108
 
 
109
  for(i=0;i<32;i++) {
 
110
    *( (short *) samples) = *tmp1;
 
111
    samples += 2;
 
112
    tmp1 += 2;
 
113
  }
 
114
  *pnt += 64;
 
115
 
 
116
  return ret;
 
117
}
 
118
 
 
119
 
 
120
int synth_1to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
 
121
{
 
122
  int i,ret;
 
123
 
 
124
  ret = synth_1to1(bandPtr,0,samples,pnt);
 
125
  samples = samples + *pnt - 128;
 
126
 
 
127
  for(i=0;i<32;i++) {
 
128
    ((short *)samples)[1] = ((short *)samples)[0];
 
129
    samples+=4;
 
130
  }
 
131
 
 
132
  return ret;
 
133
}
 
134
 
 
135
int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
 
136
{
 
137
#ifndef PENTIUM_OPT
 
138
  static real buffs[2][2][0x110];
 
139
  static const int step = 2;
 
140
  static int bo = 1;
 
141
  short *samples = (short *) (out + *pnt);
 
142
 
 
143
  real *b0,(*buf)[0x110];
 
144
  int clip = 0; 
 
145
  int bo1;
 
146
#endif
 
147
 
 
148
  if(have_eq_settings)
 
149
        do_equalizer(bandPtr,channel);
 
150
 
 
151
#ifndef PENTIUM_OPT
 
152
  if(!channel) {
 
153
    bo--;
 
154
    bo &= 0xf;
 
155
    buf = buffs[0];
 
156
  }
 
157
  else {
 
158
    samples++;
 
159
    buf = buffs[1];
 
160
  }
 
161
 
 
162
  if(bo & 0x1) {
 
163
    b0 = buf[0];
 
164
    bo1 = bo;
 
165
    dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
 
166
  }
 
167
  else {
 
168
    b0 = buf[1];
 
169
    bo1 = bo+1;
 
170
    dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
 
171
  }
 
172
  
 
173
  {
 
174
    register int j;
 
175
    real *window = decwin + 16 - bo1;
 
176
 
 
177
    for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
 
178
    {
 
179
      real sum;
 
180
      sum  = window[0x0] * b0[0x0];
 
181
      sum -= window[0x1] * b0[0x1];
 
182
      sum += window[0x2] * b0[0x2];
 
183
      sum -= window[0x3] * b0[0x3];
 
184
      sum += window[0x4] * b0[0x4];
 
185
      sum -= window[0x5] * b0[0x5];
 
186
      sum += window[0x6] * b0[0x6];
 
187
      sum -= window[0x7] * b0[0x7];
 
188
      sum += window[0x8] * b0[0x8];
 
189
      sum -= window[0x9] * b0[0x9];
 
190
      sum += window[0xA] * b0[0xA];
 
191
      sum -= window[0xB] * b0[0xB];
 
192
      sum += window[0xC] * b0[0xC];
 
193
      sum -= window[0xD] * b0[0xD];
 
194
      sum += window[0xE] * b0[0xE];
 
195
      sum -= window[0xF] * b0[0xF];
 
196
 
 
197
      WRITE_SAMPLE(samples,sum,clip);
 
198
    }
 
199
 
 
200
    {
 
201
      real sum;
 
202
      sum  = window[0x0] * b0[0x0];
 
203
      sum += window[0x2] * b0[0x2];
 
204
      sum += window[0x4] * b0[0x4];
 
205
      sum += window[0x6] * b0[0x6];
 
206
      sum += window[0x8] * b0[0x8];
 
207
      sum += window[0xA] * b0[0xA];
 
208
      sum += window[0xC] * b0[0xC];
 
209
      sum += window[0xE] * b0[0xE];
 
210
      WRITE_SAMPLE(samples,sum,clip);
 
211
      b0-=0x10,window-=0x20,samples+=step;
 
212
    }
 
213
    window += bo1<<1;
 
214
 
 
215
    for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
 
216
    {
 
217
      real sum;
 
218
      sum = -window[-0x1] * b0[0x0];
 
219
      sum -= window[-0x2] * b0[0x1];
 
220
      sum -= window[-0x3] * b0[0x2];
 
221
      sum -= window[-0x4] * b0[0x3];
 
222
      sum -= window[-0x5] * b0[0x4];
 
223
      sum -= window[-0x6] * b0[0x5];
 
224
      sum -= window[-0x7] * b0[0x6];
 
225
      sum -= window[-0x8] * b0[0x7];
 
226
      sum -= window[-0x9] * b0[0x8];
 
227
      sum -= window[-0xA] * b0[0x9];
 
228
      sum -= window[-0xB] * b0[0xA];
 
229
      sum -= window[-0xC] * b0[0xB];
 
230
      sum -= window[-0xD] * b0[0xC];
 
231
      sum -= window[-0xE] * b0[0xD];
 
232
      sum -= window[-0xF] * b0[0xE];
 
233
      sum -= window[-0x0] * b0[0xF];
 
234
 
 
235
      WRITE_SAMPLE(samples,sum,clip);
 
236
    }
 
237
  }
 
238
  *pnt += 128;
 
239
 
 
240
  return clip;
 
241
#elif defined(USE_MMX)
 
242
  {
 
243
    static short buffs[2][2][0x110];
 
244
    static int bo = 1;
 
245
    short *samples = (short *) (out + *pnt);
 
246
    synth_1to1_MMX(bandPtr, channel, samples, (short *) buffs, &bo); 
 
247
    *pnt += 128;
 
248
    return 0;
 
249
  } 
 
250
#else
 
251
  {
 
252
    int ret;
 
253
    ret = synth_1to1_pent(bandPtr,channel,out+*pnt);
 
254
    *pnt += 128;
 
255
    return ret;
 
256
  }
 
257
#endif
 
258
}