Commit c252f402 authored by conrad's avatar conrad

Fix size parsing error in auto_vorbis()

Patch by Ian Malone: If the size for the mode section doesn't match
the number counted back then allow going forward one block and trying
again. oggzinfo with and without this change produce the same results
on about 1500 vorbis files (though they're mostly encoded using the
same quality setting).
See http://lists.xiph.org/pipermail/vorbis-dev/2009-March/019823.html

git-svn-id: http://svn.annodex.net/liboggz/trunk@3904 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 8415f241
......@@ -686,6 +686,7 @@ static ogg_int64_t
auto_calc_vorbis(ogg_int64_t now, oggz_stream_t *stream, ogg_packet *op) {
auto_calc_vorbis_info_t *info;
int ii;
if (stream->calculate_data == NULL) {
/*
......@@ -821,19 +822,32 @@ auto_calc_vorbis(ogg_int64_t now, oggz_stream_t *stream, ogg_packet *op) {
}
if (offset > 4) {
size_check = (current_pos[0] >> (offset - 5)) & 0x3F;
} else {
/* mask part of byte from current_pos */
size_check = (current_pos[0] & ((1 << (offset + 1)) - 1));
/* shift to appropriate position */
size_check <<= (5 - offset);
/* or in part of byte from current_pos - 1 */
size_check |= (current_pos[-1] & ~((1 << (offset + 3)) - 1)) >>
(offset + 3);
/* Give ourselves a chance to recover if we went back too far by using
* the size check. */
for (ii=0; ii < 2; ii++) {
if (offset > 4) {
size_check = (current_pos[0] >> (offset - 5)) & 0x3F;
} else {
/* mask part of byte from current_pos */
size_check = (current_pos[0] & ((1 << (offset + 1)) - 1));
/* shift to appropriate position */
size_check <<= (5 - offset);
/* or in part of byte from current_pos - 1 */
size_check |= (current_pos[-1] & ~((1 << (offset + 3)) - 1)) >>
(offset + 3);
}
size_check += 1;
if (size_check == size) {
break;
}
offset = (offset + 1) % 8;
if (offset == 0)
current_pos += 1;
current_pos += 5;
size -= 1;
}
size_check += 1;
#ifdef DEBUG
if (size_check != size)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment