RustAudio / ogg

Ogg container decoder and encoder written in pure Rust
Other
113 stars 21 forks source link

UntilPageHeaderReader::check_arr may skip header mistakenly in very rare cases #14

Closed TonalidadeHidrica closed 3 years ago

TonalidadeHidrica commented 3 years ago

It's very nitpicking, but I think current check_arr may overlook the OggS header when there is an O right before OggS.

https://github.com/RustAudio/ogg/blob/master/src/reading.rs#L562-L572

For the first time it founds O, self.cpt_of is updated to 1. Right after that, it founds the second O, but the first match arrow does not match because of already-updated self.cpt_of, and self.cpt_of is brought back to 0. As a result, the function cannot find the OggS magic. This case also happens in OgOggs and OggOggs. It's extremely rare for such case to happen, though.

This can be fixed by removing if self.cpt_of == 0 guard in line 565.

est31 commented 3 years ago

Good catch, thanks!