~ubuntu-branches/ubuntu/feisty/flac/feisty-security

« back to all changes in this revision

Viewing changes to src/libFLAC/format.c

  • Committer: Bazaar Package Importer
  • Author(s): Tollef Fog Heen
  • Date: 2005-11-10 12:55:33 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20051110125533-2fmlml8wnb06r5vg
Tags: 1.1.2-3ubuntu1
* Merge with Debian
  - We did the C++ transition earlier than Debian, so add c2 suffix to
    liboggflac++ and libflac++

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* libFLAC - Free Lossless Audio Codec library
2
 
 * Copyright (C) 2000,2001,2002,2003,2004  Josh Coalson
 
2
 * Copyright (C) 2000,2001,2002,2003,2004,2005  Josh Coalson
3
3
 *
4
4
 * Redistribution and use in source and binary forms, with or without
5
5
 * modification, are permitted provided that the following conditions
56
56
 
57
57
#if defined _MSC_VER || defined __MINW32__
58
58
/* yet one more hack because of MSVC6: */
59
 
FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.1.1 20041001";
 
59
FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.1.2 20050205";
60
60
#else
61
 
FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20041001";
 
61
FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20050205";
62
62
#endif
63
63
 
64
64
FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
254
254
        return j;
255
255
}
256
256
 
 
257
static __inline unsigned utf8len_(const FLAC__byte *utf8)
 
258
{
 
259
        FLAC__ASSERT(0 != utf8);
 
260
        if ((utf8[0] & 0x80) == 0)
 
261
                return 1;
 
262
        else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80)
 
263
                return 2;
 
264
        else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80)
 
265
                return 3;
 
266
        else
 
267
                return 0;
 
268
}
 
269
 
 
270
FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
 
271
{
 
272
        char c;
 
273
        for(c = *name; c; c = *(++name))
 
274
                if(c < 0x20 || c == 0x3d || c > 0x7d)
 
275
                        return false;
 
276
        return true;
 
277
}
 
278
 
 
279
FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
 
280
{
 
281
        if(length == (unsigned)(-1)) {
 
282
                while(*value) {
 
283
                        unsigned n = utf8len_(value);
 
284
                        if(n == 0)
 
285
                                return false;
 
286
                        value += n;
 
287
                }
 
288
        }
 
289
        else {
 
290
                const FLAC__byte *end = value + length;
 
291
                while(value < end) {
 
292
                        unsigned n = utf8len_(value);
 
293
                        if(n == 0)
 
294
                                return false;
 
295
                        value += n;
 
296
                }
 
297
                if(value != end)
 
298
                        return false;
 
299
        }
 
300
        return true;
 
301
}
 
302
 
 
303
FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
 
304
{
 
305
        const FLAC__byte *s, *end;
 
306
 
 
307
        for(s = entry, end = s + length; s < end && *s != '='; s++) {
 
308
                if(*s < 0x20 || *s > 0x7D)
 
309
                        return false;
 
310
        }
 
311
        if(s == end)
 
312
                return false;
 
313
 
 
314
        s++; /* skip '=' */
 
315
 
 
316
        while(s < end) {
 
317
                unsigned n = utf8len_(s);
 
318
                if(n == 0)
 
319
                        return false;
 
320
                s += n;
 
321
        }
 
322
        if(s != end)
 
323
                return false;
 
324
 
 
325
        return true;
 
326
}
 
327
 
257
328
FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
258
329
{
259
330
        unsigned i, j;