~siretart/xine-lib/ubuntu

« back to all changes in this revision

Viewing changes to src/libfaad/huffman.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-12-15 13:13:45 UTC
  • mfrom: (0.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051215131345-8n4osv1j7fy9c1s1
* SECURITY UPDATE: Fix arbitrary code execution with crafted PNG images in
  embedded ffmpeg copy.
* src/libffmpeg/libavcodec/utils.c, avcodec_default_get_buffer(): Apply
  upstream patch to fix buffer overflow on decoding of small PIX_FMT_PAL8
  PNG files.
* References:
  CVE-2005-4048
  http://mplayerhq.hu/pipermail/ffmpeg-devel/2005-November/005333.html
  http://www1.mplayerhq.hu/cgi-bin/cvsweb.cgi/ffmpeg/libavcodec/
  utils.c.diff?r1=1.161&r2=1.162&cvsroot=FFMpeg

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
** Commercial non-GPL licensing of this software is possible.
23
23
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
24
24
**
25
 
** $Id: huffman.c,v 1.4 2004/12/03 01:15:30 tmattern Exp $
 
25
** $Id: huffman.c,v 1.5 2005/10/29 23:57:06 tmmm Exp $
26
26
**/
27
27
 
28
28
#include "common.h"
50
50
static uint8_t huffman_binary_pair(uint8_t cb, bitfile *ld, int16_t *sp);
51
51
static uint8_t huffman_binary_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp);
52
52
static int16_t huffman_codebook(uint8_t i);
 
53
static void vcb11_check_LAV(uint8_t cb, int16_t *sp);
53
54
 
54
55
int8_t huffman_scale_factor(bitfile *ld)
55
56
{
120
121
static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp)
121
122
{
122
123
    uint8_t neg, i;
123
 
    int32_t j;
124
 
        int32_t off;
 
124
    int16_t j;
 
125
        int16_t off;
125
126
 
126
127
    if (sp < 0)
127
128
    {
143
144
        }
144
145
    }
145
146
 
146
 
    off = faad_getbits(ld, i
 
147
    off = (int16_t)faad_getbits(ld, i
147
148
        DEBUGVAR(1,9,"huffman_getescape(): escape"));
148
149
 
149
150
    j = off | (1<<i);
310
311
    else        return (int16_t)data & 0xFFFF;
311
312
}
312
313
 
 
314
static void vcb11_check_LAV(uint8_t cb, int16_t *sp)
 
315
{
 
316
    static const uint16_t vcb11_LAV_tab[] = {
 
317
        16, 31, 47, 63, 95, 127, 159, 191, 223,
 
318
        255, 319, 383, 511, 767, 1023, 2047
 
319
    };
 
320
    uint16_t max = 0;
 
321
 
 
322
    if (cb < 16 || cb > 31)
 
323
        return;
 
324
 
 
325
    max = vcb11_LAV_tab[cb - 16];
 
326
 
 
327
    if ((abs(sp[0]) > max) || (abs(sp[1]) > max))
 
328
    {
 
329
        sp[0] = 0;
 
330
        sp[1] = 0;
 
331
    }
 
332
}
 
333
 
313
334
uint8_t huffman_spectral_data(uint8_t cb, bitfile *ld, int16_t *sp)
314
335
{
315
336
    switch (cb)
336
357
        sp[0] = huffman_codebook(0); sp[1] = huffman_codebook(1); 
337
358
        return err; }
338
359
    case 11:
 
360
    {
 
361
        uint8_t err = huffman_2step_pair_sign(11, ld, sp);
 
362
        sp[0] = huffman_getescape(ld, sp[0]);
 
363
        sp[1] = huffman_getescape(ld, sp[1]);
 
364
        return err;
 
365
    }
339
366
#ifdef ERROR_RESILIENCE
340
367
    /* VCB11 uses codebook 11 */
341
368
    case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23:
342
369
    case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
343
 
        /* TODO: If ER is used, some extra error checking should be done */
 
370
    {
 
371
        uint8_t err = huffman_2step_pair_sign(11, ld, sp);
 
372
        sp[0] = huffman_getescape(ld, sp[0]);
 
373
        sp[1] = huffman_getescape(ld, sp[1]);
 
374
 
 
375
        /* check LAV (Largest Absolute Value) */
 
376
        /* this finds errors in the ESCAPE signal */
 
377
        vcb11_check_LAV(cb, sp);
 
378
 
 
379
        return err;
 
380
    }
344
381
#endif
345
 
    {
346
 
        uint8_t err = huffman_2step_pair_sign(11, ld, sp);
347
 
        sp[0] = huffman_getescape(ld, sp[0]);
348
 
        sp[1] = huffman_getescape(ld, sp[1]);
349
 
        return err;
350
 
    }
351
382
    default:
352
383
        /* Non existent codebook number, something went wrong */
353
384
        return 11;
369
400
    uint32_t cw;
370
401
    uint16_t offset = 0;
371
402
    uint8_t extra_bits;
372
 
    uint8_t i;
 
403
    uint8_t i, vcb11 = 0;
373
404
 
374
405
 
375
406
    switch (cb)
406
437
    case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23:
407
438
    case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
408
439
 
409
 
        /* TODO: If ER is used, some extra error checking should be done */
410
440
        if (cb >= 16)
 
441
        {
 
442
            /* store the virtual codebook */
 
443
            vcb11 = cb;
411
444
            cb = 11;
 
445
        }
412
446
            
413
447
        cw = showbits_hcr(ld, hcbN[cb]);
414
448
        offset = hcb_table[cb][cw].offset;
463
497
    }
464
498
 
465
499
        /* decode sign bits */
466
 
    if (unsigned_cb[cb]) {
467
 
 
 
500
    if (unsigned_cb[cb])
 
501
    {
468
502
        for(i = 0; i < ((cb < FIRST_PAIR_HCB) ? QUAD_LEN : PAIR_LEN); i++)
469
503
        {
470
504
            if(sp[i])
500
534
                    if (b == 0)
501
535
                        break;
502
536
                }
503
 
// TODO: here we would need to test "off" if VCB11 is used!
 
537
 
504
538
                if (getbits_hcr(ld, i, &off))
505
539
                    return -1;
506
540
                j = off + (1<<i);
507
541
                sp[k] = (int16_t)((neg) ? -j : j);
508
542
            }
509
543
        }
 
544
 
 
545
        if (vcb11 != 0)
 
546
        {
 
547
            /* check LAV (Largest Absolute Value) */
 
548
            /* this finds errors in the ESCAPE signal */
 
549
            vcb11_check_LAV(vcb11, sp);
 
550
        }
510
551
    }    
511
552
    return ld->len;
512
553
}