mirror of
https://github.com/fmang/opustags.git
synced 2025-03-14 08:30:08 +01:00
ogg: check the validity of streams
This commit is contained in:
parent
d21517de94
commit
40bbc90786
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user