From b312ce46ebee50505ef529223826f99ef81d9be6 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 14 Sep 2018 00:29:34 +0200 Subject: [PATCH] Fix single-code-{ordered,sparse}.ogg decoding error Decoding of the files single-code-ordered.ogg and single-code-sparse.ogg gave us the error that current_length was bigger than codebook_entries. But this was a bug. Apparently we were comparing current_length with codebook_entries, but the spec tells us to use current_entry instead of current_length. Now, after having changed the behaviour to follow the spec, we can decode the files successfully. The second file can be decoded by libvorbis as well, and here some discrepancy still seems to exist (25 packets with mismatches of 26 total). However, having the files decode successfully is already progress. --- dev/cmp/tests/vals.rs | 9 ++++++--- src/header.rs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dev/cmp/tests/vals.rs b/dev/cmp/tests/vals.rs index 752fc3c..0072692 100644 --- a/dev/cmp/tests/vals.rs +++ b/dev/cmp/tests/vals.rs @@ -70,9 +70,12 @@ fn test_libnogg_vals() { // We can't cmp the output here because native // libvorbis doesn't accept the file as valid ensure_okay!("single-code-nonsparse.ogg"); - //cmp_output!("single-code-ordered.ogg", 0); - // TODO fix this - //cmp_output!("single-code-sparse.ogg", 0); + ensure_okay!("single-code-ordered.ogg"); + // TODO get this number down to zero + // This test is ensuring already though that + // the file decodes without errors, which wasn't + // the case until a bug in lewton got fixed. + cmp_output!("single-code-sparse.ogg", 25); cmp_output!("sketch008-floor0.ogg", 4); cmp_output!("sketch008.ogg", 0); cmp_output!("sketch039.ogg", 0); diff --git a/src/header.rs b/src/header.rs index 363f021..ac02184 100644 --- a/src/header.rs +++ b/src/header.rs @@ -707,7 +707,7 @@ fn read_codebook(rdr :&mut BitpackCursor) -> Result { } current_entry += number; current_length += 1; - if current_length as u32 > codebook_entries { + if current_entry as u32 > codebook_entries { try!(Err(HeaderReadError::HeaderBadFormat)); } }