summaryrefslogtreecommitdiff
path: root/Meta/Lagom/Fuzzers
diff options
context:
space:
mode:
authorkleines Filmröllchen <malu.bertsch@gmail.com>2021-11-27 17:00:19 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-11-28 13:33:51 -0800
commit96d02a3e753b53533d2aaf50e2dd2d92738f0e29 (patch)
tree9824e7c67eda20af029054380108ca96e5a9697a /Meta/Lagom/Fuzzers
parentec8bd8116d4683ae51897e8e49c62823bfdd9005 (diff)
downloadserenity-96d02a3e753b53533d2aaf50e2dd2d92738f0e29.zip
LibAudio: New error propagation API in Loader and Buffer
Previously, a libc-like out-of-line error information was used in the loader and its plugins. Now, all functions that may fail to do their job return some sort of Result. The universally-used error type ist the new LoaderError, which can contain information about the general error category (such as file format, I/O, unimplemented features), an error description, and location information, such as file index or sample index. Additionally, the loader plugins try to do as little work as possible in their constructors. Right after being constructed, a user should call initialize() and check the errors returned from there. (This is done transparently by Loader itself.) If a constructor caused an error, the call to initialize should check and return it immediately. This opportunity was used to rework a lot of the internal error propagation in both loader classes, especially FlacLoader. Therefore, a couple of other refactorings may have sneaked in as well. The adoption of LibAudio users is minimal. Piano's adoption is not important, as the code will receive major refactoring in the near future anyways. SoundPlayer's adoption is also less important, as changes to refactor it are in the works as well. aplay's adoption is the best and may serve as an example for other users. It also includes new buffering behavior. Buffer also gets some attention, making it OOM-safe and thereby also propagating its errors to the user.
Diffstat (limited to 'Meta/Lagom/Fuzzers')
-rw-r--r--Meta/Lagom/Fuzzers/FuzzFlacLoader.cpp11
-rw-r--r--Meta/Lagom/Fuzzers/FuzzWAVLoader.cpp12
2 files changed, 15 insertions, 8 deletions
diff --git a/Meta/Lagom/Fuzzers/FuzzFlacLoader.cpp b/Meta/Lagom/Fuzzers/FuzzFlacLoader.cpp
index eafc31d3fe..7c32717c47 100644
--- a/Meta/Lagom/Fuzzers/FuzzFlacLoader.cpp
+++ b/Meta/Lagom/Fuzzers/FuzzFlacLoader.cpp
@@ -13,11 +13,16 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
auto flac_data = ByteBuffer::copy(data, size).release_value();
auto flac = make<Audio::FlacLoaderPlugin>(flac_data);
- if (!flac->sniff())
+ if (flac->initialize().is_error())
return 1;
- while (flac->get_more_samples())
- ;
+ for (;;) {
+ auto samples = flac->get_more_samples();
+ if (samples.is_error())
+ return 2;
+ if (samples.value()->sample_count() > 0)
+ break;
+ }
return 0;
}
diff --git a/Meta/Lagom/Fuzzers/FuzzWAVLoader.cpp b/Meta/Lagom/Fuzzers/FuzzWAVLoader.cpp
index 519fd82d8f..fd2b99d9d6 100644
--- a/Meta/Lagom/Fuzzers/FuzzWAVLoader.cpp
+++ b/Meta/Lagom/Fuzzers/FuzzWAVLoader.cpp
@@ -13,11 +13,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
auto wav_data = ByteBuffer::copy(data, size).release_value();
auto wav = make<Audio::WavLoaderPlugin>(wav_data);
- if (!wav->sniff())
- return 1;
-
- while (wav->get_more_samples())
- ;
+ for (;;) {
+ auto samples = wav->get_more_samples();
+ if (samples.is_error())
+ return 2;
+ if (samples.value()->sample_count() > 0)
+ break;
+ }
return 0;
}