Timothy B. Terriberry
authored
In the case where we got a data packet before receiving all three headers, the old code would check to see if the second through seventh bytes matched the magic string "theora" (extremely unlikely, but possible), and if so, return TH_EBADHEADER, otherwise return TH_ENOTFORMAT. That this was not consistent was a bit non-sensical. 5a5f5bb2 changed to returning TH_EBADHEADER if we got a data packet after receiving the first header, but left the old behavior for the first packet. Change instead to explicitly return TH_ENOTFORMAT if the first header was missing (since we only check one bit of the packet to determine whether or not it's a data packet, odds are it's a packet for some other kind of data, like a Vorbis header). We continue to return TH_EBADHEADER if we see a data packet after encountering a valid header, but before reading all three. Also re-arrange the NULL checks to follow continue to allow the undocumented ability to pass in NULL for parameters which are not needed by the next header in the sequence. E.g., it's perfectly all right to pass NULL for _setup when expecting to read the comment header next. In this case we'll now return TH_EBADHEADER instead of TH_EFAULT if the packet was actually a data packet.