1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +00:00

Ladybird+LibWeb+WebContent: Prevent out-of-bounds seeking audio elements

It's currently possible to seek to the total sample count of an audio
loader. We must limit seeking to one less than that count.

This mistake was duplicated in both AudioCodecPluginSerenity/Ladybird,
so the computation was moved to a helper in the base AudioCodecPlugin.
This commit is contained in:
Timothy Flynn 2023-06-21 19:37:10 -04:00 committed by Andreas Kling
parent 20edbb70f8
commit bcd222cfae
4 changed files with 17 additions and 16 deletions

View file

@ -40,6 +40,18 @@ ErrorOr<FixedArray<Audio::Sample>> AudioCodecPlugin::read_samples_from_loader(Au
return FixedArray<Audio::Sample>::create(resampler.resample(buffer_or_error.release_value()).span());
}
Duration AudioCodecPlugin::set_loader_position(Audio::Loader& loader, double position, Duration duration, size_t device_sample_rate)
{
if (loader.total_samples() == 0)
return current_loader_position(loader, device_sample_rate);
auto duration_value = static_cast<double>(duration.to_milliseconds()) / 1000.0;
position = position / duration_value * static_cast<double>(loader.total_samples() - 1);
loader.seek(static_cast<int>(position)).release_value_but_fixme_should_propagate_errors();
return current_loader_position(loader, device_sample_rate);
}
Duration AudioCodecPlugin::current_loader_position(Audio::Loader const& loader, size_t device_sample_rate)
{
auto samples_played = static_cast<double>(loader.loaded_samples());