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

« back to all changes in this revision

Viewing changes to readers.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-09-07 15:57:57 UTC
  • Revision ID: james.westby@ubuntu.com-20040907155757-pgypftl9bt2uqyyl
Tags: 0.59r-16
* layer2.c: Fix buffer overflow in layer2 decoder (CVE ID CAN-2004-0805).
* Makefile: Fix compiler options to build for generic targets on ARM,
  but optimise for xscale. Closes: #261255
* README.3DNOW, dct36_3dnow.s, dct64_3dnow.s, decode_3dnow.s,
  decode_i386.c, equalizer_3dnow.s, getcpuflags.s, layer3.c, mpg123.c,
  mpg123.h, tabinit.c, debian/rules: Apply patch by KIMURA Takuhiro and
  Syuuhei Kashiyama to fix errors in 3dnow-optimised decoding.
  Thanks to Alberto Garcia for the patch-merging. Closes: #242212
* debian/prerm: De-register mp3-decoder alternative. Closes: #222982
* debian/changelog: Convert to utf8.
* debian/control: Bump standards version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
/*******************************************************************
22
22
 * stream based operation
23
23
 */
24
 
static int fullread(int fd,unsigned char *buf,int count)
 
24
static int fullread(struct reader *rds,unsigned char *buf,int count)
25
25
{
26
26
  int ret,cnt=0;
27
27
 
 
28
  /*
 
29
   * We check against READER_ID3TAG instead of rds->filelen >= 0 because
 
30
   * if we got the ID3 TAG we know we have the end of the file.  If we
 
31
   * don't have an ID3 TAG, then it is possible the file has grown since
 
32
   * we started playing, so we want to keep reading from it if possible.
 
33
   */
 
34
  if ((rds->flags & READER_ID3TAG) && rds->filepos + count > rds->filelen)
 
35
    count = rds->filelen - rds->filepos;
28
36
  while(cnt < count) {
29
 
    ret = read(fd,buf+cnt,count-cnt);
 
37
    ret = read(rds->filept,buf+cnt,count-cnt);
30
38
    if(ret < 0)
31
39
      return ret;
32
40
    if(ret == 0)
33
41
      break;
 
42
    rds->filepos += ret;
34
43
    cnt += ret;
35
44
  } 
36
45
 
37
46
  return cnt;
38
47
}
39
48
 
 
49
static off_t stream_lseek(struct reader *rds, off_t pos, int whence)
 
50
{
 
51
  off_t ret;
 
52
 
 
53
  ret = lseek(rds->filept, pos, whence);
 
54
  if (ret >= 0)
 
55
    rds->filepos = ret;
 
56
 
 
57
  return ret;
 
58
}
 
59
 
40
60
static int default_init(struct reader *rds)
41
61
{
42
62
  char buf[128];
43
63
 
 
64
  rds->filelen = get_fileinfo(rds,buf);
44
65
  rds->filepos = 0;
45
 
  rds->filelen = get_fileinfo(rds,buf);
46
66
  
47
 
  if(rds->filelen > 0) {
 
67
  if(rds->filelen >= 0) {
48
68
    if(!strncmp(buf,"TAG",3)) {
49
69
      rds->flags |= READER_ID3TAG;
50
70
      memcpy(rds->id3buf,buf,128);
65
85
 */
66
86
static int stream_back_bytes(struct reader *rds,int bytes)
67
87
{
68
 
  if(lseek(rds->filept,-bytes,SEEK_CUR) < 0)
 
88
  if(stream_lseek(rds,-bytes,SEEK_CUR) < 0)
69
89
    return -1;
70
90
  if(param.usebuffer)
71
91
          buffer_resync();
95
115
/*
96
116
                bytes += (long)(compute_buffer_offset(fr)*compute_bpf(fr));
97
117
*/      
98
 
        if(lseek(rds->filept,-bytes,SEEK_CUR) < 0)
 
118
        if(stream_lseek(rds,-bytes,SEEK_CUR) < 0)
99
119
                return -1;
100
120
 
101
 
        if(fullread(rds->filept,buf,4) != 4)
 
121
        if(fullread(rds,buf,4) != 4)
102
122
                return -1;
103
123
 
104
124
        newhead = (buf[0]<<24) + (buf[1]<<16) + (buf[2]<<8) + buf[3];
105
125
        
106
126
        while( (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK) ) {
107
 
                if(fullread(rds->filept,buf,1) != 1)
 
127
                if(fullread(rds,buf,1) != 1)
108
128
                        return -1;
109
129
                newhead <<= 8;
110
130
                newhead |= buf[0];
111
131
                newhead &= 0xffffffff;
112
132
        }
113
133
 
114
 
        if( lseek(rds->filept,-4,SEEK_CUR) < 0)
 
134
        if( stream_lseek(rds,-4,SEEK_CUR) < 0)
115
135
                return -1;
116
136
        
117
137
        read_frame(fr);
131
151
{
132
152
  unsigned char hbuf[4];
133
153
 
134
 
  if(fullread(rds->filept,hbuf,4) != 4)
 
154
  if(fullread(rds,hbuf,4) != 4)
135
155
    return FALSE;
136
156
  
137
157
  *newhead = ((unsigned long) hbuf[0] << 24) |
146
166
{
147
167
  unsigned char hbuf;
148
168
 
149
 
  if(fullread(rds->filept,&hbuf,1) != 1)
 
169
  if(fullread(rds,&hbuf,1) != 1)
150
170
    return 0;
151
171
  *head <<= 8;
152
172
  *head |= hbuf;
156
176
 
157
177
static int stream_skip_bytes(struct reader *rds,int len)
158
178
{
159
 
  if (!param.usebuffer)
160
 
        return lseek(rds->filept,len,SEEK_CUR);
161
 
 
162
 
  else {
163
 
 
164
 
        int ret = lseek(rds->filept,len,SEEK_CUR);
165
 
        buffer_resync();
 
179
  if (rds->filelen >= 0) {
 
180
    int ret = stream_lseek(rds, len, SEEK_CUR);
 
181
    if (param.usebuffer)
 
182
      buffer_resync();
 
183
    return ret;
 
184
  } else if (len >= 0) {
 
185
    char buf[1024];
 
186
    int ret;
 
187
    while (len > 0) {
 
188
      int num = len < sizeof(buf) ? len : sizeof(buf);
 
189
      ret = fullread(rds, buf, num);
 
190
      if (ret < 0)
166
191
        return ret;
167
 
 
168
 
  }
 
192
      len -= ret;
 
193
    }
 
194
    return rds->filepos;
 
195
  } else
 
196
    return -1;
169
197
}
170
198
 
171
199
static int stream_read_frame_body(struct reader *rds,unsigned char *buf,
173
201
{
174
202
  long l;
175
203
 
176
 
  if( (l=fullread(rds->filept,buf,size)) != size)
 
204
  if( (l=fullread(rds,buf,size)) != size)
177
205
  {
178
206
    if(l <= 0)
179
207
      return 0;
185
213
 
186
214
static long stream_tell(struct reader *rds)
187
215
{
188
 
  return lseek(rds->filept,0,SEEK_CUR);
 
216
  return rds->filepos;
189
217
}
190
218
 
191
219
static void stream_rewind(struct reader *rds)
192
220
{
193
 
  lseek(rds->filept,0,SEEK_SET);
 
221
  stream_lseek(rds,0,SEEK_SET);
194
222
  if(param.usebuffer) 
195
223
          buffer_resync();
196
224
}
208
236
        }
209
237
        if(lseek(rds->filept,-128,SEEK_END) < 0)
210
238
                return -1;
211
 
        if(fullread(rds->filept,(unsigned char *)buf,128) != 128) {
 
239
        if(fullread(rds,(unsigned char *)buf,128) != 128) {
212
240
                return -1;
213
241
        }
214
242
        if(!strncmp(buf,"TAG",3)) {
439
467
 
440
468
/* open the device to read the bit stream from it */
441
469
 
442
 
void open_stream(char *bs_filenam,int fd)
 
470
int open_stream(char *bs_filenam,int fd)
443
471
{
444
472
    int i;
445
473
    int filept_opened = 1;
453
481
                else
454
482
                        filept = fd;
455
483
        }
456
 
        else if (!strncmp(bs_filenam, "http://", 7)) 
457
 
                filept = http_open(bs_filenam);
 
484
       else if (!strncmp(bs_filenam, "http://", 7))  {
 
485
               if ((filept = http_open(bs_filenam)) < 0)
 
486
                       return filept;
 
487
       }
458
488
#ifndef O_BINARY
459
489
#define O_BINARY (0)
460
490
#endif
461
491
        else if ( (filept = open(bs_filenam, O_RDONLY|O_BINARY)) < 0) {
462
492
                perror (bs_filenam);
463
 
                exit(1);
 
493
               return filept;
464
494
        }
465
495
 
466
496
    rd = NULL;
483
513
    if(rd && rd->flags & READER_ID3TAG) {
484
514
      print_id3_tag(rd->id3buf);
485
515
    }
 
516
 
 
517
    return filept;
486
518
}
487
519
 
488
520