mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:07:34 +00:00
LibAudio: Don't read too much bytes in FLAC
This fixes crash when reading the end of the file. The logic is mostly borrowed from WavLoader.
This commit is contained in:
parent
73fc2b3748
commit
69c7b66f06
1 changed files with 8 additions and 3 deletions
|
@ -210,8 +210,13 @@ void FlacLoaderPlugin::seek(const int position)
|
||||||
RefPtr<Buffer> FlacLoaderPlugin::get_more_samples([[maybe_unused]] size_t max_bytes_to_read_from_input)
|
RefPtr<Buffer> FlacLoaderPlugin::get_more_samples([[maybe_unused]] size_t max_bytes_to_read_from_input)
|
||||||
{
|
{
|
||||||
Vector<Frame> samples;
|
Vector<Frame> samples;
|
||||||
size_t remaining_samples = max_bytes_to_read_from_input;
|
ssize_t remaining_samples = m_total_samples - m_loaded_samples;
|
||||||
while (remaining_samples > 0) {
|
if (remaining_samples <= 0) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t samples_to_read = min(max_bytes_to_read_from_input, remaining_samples);
|
||||||
|
while (samples_to_read > 0) {
|
||||||
if (!m_current_frame.has_value()) {
|
if (!m_current_frame.has_value()) {
|
||||||
next_frame();
|
next_frame();
|
||||||
if (!m_error_string.is_empty()) {
|
if (!m_error_string.is_empty()) {
|
||||||
|
@ -227,7 +232,7 @@ RefPtr<Buffer> FlacLoaderPlugin::get_more_samples([[maybe_unused]] size_t max_by
|
||||||
if (m_current_frame_data.size() == 0) {
|
if (m_current_frame_data.size() == 0) {
|
||||||
m_current_frame.clear();
|
m_current_frame.clear();
|
||||||
}
|
}
|
||||||
--remaining_samples;
|
--samples_to_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Buffer::create_with_samples(move(samples));
|
return Buffer::create_with_samples(move(samples));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue