decoder/ffmpeg: fix crash due to wrong avio_alloc_context() call
Allocate the buffer dynamically using av_malloc(), and free AVIOContext.buffer in the destructor, as mandated by the libavformat documentation. Fixes http://bugs.musicpd.org/view.php?id=4446
This commit is contained in:
parent
a7ee64a25b
commit
1958f78cc1
2
NEWS
2
NEWS
@ -1,6 +1,8 @@
|
|||||||
ver 0.19.11 (not yet released)
|
ver 0.19.11 (not yet released)
|
||||||
* tags
|
* tags
|
||||||
- ape: fix buffer overflow
|
- ape: fix buffer overflow
|
||||||
|
* decoder
|
||||||
|
- ffmpeg: fix crash due to wrong avio_alloc_context() call
|
||||||
* encoder
|
* encoder
|
||||||
- flac: fix crash with 32 bit playback
|
- flac: fix crash with 32 bit playback
|
||||||
|
|
||||||
|
@ -92,15 +92,15 @@ struct AvioStream {
|
|||||||
|
|
||||||
AVIOContext *io;
|
AVIOContext *io;
|
||||||
|
|
||||||
unsigned char buffer[8192];
|
|
||||||
|
|
||||||
AvioStream(Decoder *_decoder, InputStream &_input)
|
AvioStream(Decoder *_decoder, InputStream &_input)
|
||||||
:decoder(_decoder), input(_input), io(nullptr) {}
|
:decoder(_decoder), input(_input), io(nullptr) {}
|
||||||
|
|
||||||
~AvioStream() {
|
~AvioStream() {
|
||||||
if (io != nullptr)
|
if (io != nullptr) {
|
||||||
|
av_free(io->buffer);
|
||||||
av_free(io);
|
av_free(io);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Open();
|
bool Open();
|
||||||
};
|
};
|
||||||
@ -153,11 +153,20 @@ mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence)
|
|||||||
bool
|
bool
|
||||||
AvioStream::Open()
|
AvioStream::Open()
|
||||||
{
|
{
|
||||||
io = avio_alloc_context(buffer, sizeof(buffer),
|
constexpr size_t BUFFER_SIZE = 8192;
|
||||||
|
auto buffer = (unsigned char *)av_malloc(BUFFER_SIZE);
|
||||||
|
if (buffer == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
io = avio_alloc_context(buffer, BUFFER_SIZE,
|
||||||
false, this,
|
false, this,
|
||||||
mpd_ffmpeg_stream_read, nullptr,
|
mpd_ffmpeg_stream_read, nullptr,
|
||||||
input.IsSeekable()
|
input.IsSeekable()
|
||||||
? mpd_ffmpeg_stream_seek : nullptr);
|
? mpd_ffmpeg_stream_seek : nullptr);
|
||||||
|
/* If avio_alloc_context() fails, who frees the buffer? The
|
||||||
|
libavformat API documentation does not specify this, it
|
||||||
|
only says that AVIOContext.buffer must be freed in the end,
|
||||||
|
however no AVIOContext exists in that failure code path. */
|
||||||
return io != nullptr;
|
return io != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user