ogg: check the validity of streams

This commit is contained in:
Frédéric Mangano 2016-03-03 13:26:28 +01:00 committed by Frédéric Mangano
parent d21517de94
commit 40bbc90786
2 changed files with 10 additions and 0 deletions

View File

@ -146,6 +146,8 @@ void ogg::Stream::downgrade()
ogg::Decoder::Decoder(std::istream &in)
: input(in)
{
if (!in)
throw std::runtime_error("invalid stream to decode");
input.exceptions(std::ifstream::badbit);
ogg_sync_init(&sync);
}
@ -209,6 +211,8 @@ bool ogg::Decoder::buff()
ogg::Encoder::Encoder(std::ostream &out)
: output(out)
{
if (!output)
throw std::runtime_error("invalid stream to decode");
output.exceptions(std::ifstream::badbit);
}

View File

@ -134,5 +134,11 @@ TEST_CASE("decoding a malicious Ogg Opus file", "[ogg]")
REQUIRE_THROWS(dec.read_page());
}
TEST_CASE("decoding a bad stream", "[ogg]")
{
std::ifstream in("uioprheuio");
REQUIRE_THROWS(std::make_shared<ogg::Decoder>(in));
}
// Encoding is trickier, and might as well be done in actions_test.cc, given
// opustags::edit_tags covers all of Encoder's regular code.