Revision 9e2ffc45 libavformat/westwood.c

View differences:

libavformat/westwood.c
90 90
    /* Probabilistic content detection strategy: There is no file signature
91 91
     * so perform sanity checks on various header parameters:
92 92
     *   8000 <= sample rate (16 bits) <= 48000  ==> 40001 acceptable numbers
93
     *   flags <= 0x03 (2 LSBs are used)         ==> 4 acceptable numbers
93 94
     *   compression type (8 bits) = 1 or 99     ==> 2 acceptable numbers
94
     * There is a total of 24 bits. The number space contains 2^24 =
95
     * 16777216 numbers. There are 40001 * 2 = 80002 acceptable combinations
96
     * of numbers. There is a 80002/16777216 = 0.48% chance of a false
97
     * positive.
95
     *   first audio chunk signature (32 bits)   ==> 1 acceptable number
96
     * The number space contains 2^64 numbers. There are 40001 * 4 * 2 * 1 =
97
     * 320008 acceptable number combinations.
98 98
     */
99 99

  
100
    if (p->buf_size < AUD_HEADER_SIZE)
100
    if (p->buf_size < AUD_HEADER_SIZE + AUD_CHUNK_PREAMBLE_SIZE)
101 101
        return 0;
102 102

  
103 103
    /* check sample rate */
......
105 105
    if ((field < 8000) || (field > 48000))
106 106
        return 0;
107 107

  
108
    /* enforce the rule that the top 6 bits of this flags field are reserved (0);
109
     * this might not be true, but enforce it until deemed unnecessary */
110
    if (p->buf[10] & 0xFC)
111
        return 0;
112

  
108 113
    /* note: only check for WS IMA (type 99) right now since there is no
109 114
     * support for type 1 */
110 115
    if (p->buf[11] != 99)
111 116
        return 0;
112 117

  
118
    /* read ahead to the first audio chunk and validate the first header signature */
119
    if (AV_RL32(&p->buf[16]) != AUD_CHUNK_SIGNATURE)
120
        return 0;
121

  
113 122
    /* return 1/2 certainty since this file check is a little sketchy */
114 123
    return AVPROBE_SCORE_MAX / 2;
115 124
}

Also available in: Unified diff