- st->codec->channels = *p++;
- st->codec->sample_rate = AV_RL32(p);
- p += 8; //skip maximum and and nominal bitrate
- st->codec->bit_rate = AV_RL32(p); //Minimum bitrate
+ if (bytestream_get_le32(&p) != 0) /* vorbis_version */
+ return -1;
+
+ st->codec->channels = bytestream_get_byte(&p);
+ st->codec->sample_rate = bytestream_get_le32(&p);
+ p += 4; // skip maximum bitrate
+ st->codec->bit_rate = bytestream_get_le32(&p); // nominal bitrate
+ p += 4; // skip minimum bitrate
+
+ blocksize = bytestream_get_byte(&p);
+ bs0 = blocksize & 15;
+ bs1 = blocksize >> 4;
+
+ if (bs0 > bs1)
+ return -1;
+ if (bs0 < 6 || bs1 > 13)
+ return -1;
+
+ if (bytestream_get_byte(&p) != 1) /* framing_flag */
+ return -1;