mirror of
https://github.com/chenxiaolong/avbroot.git
synced 2026-06-02 06:23:34 +02:00
Replace file reopen concept with ReadAt/WriteAt traits
File reopening was conflating ownership of file-like types with the fact that they support parallel reads and writes at arbitrary offsets. The Reopen trait has now been replaced with ReadAt and WriteAt traits, which are implemented for types that support parallel I/O. If a type compatible with the standard Read/Write/Seek traits is needed, a new UserPosFile type can act as the bridge by storing its own userspace file offset. For the opposite bridge, there's MutexFile, which implements ReadAt/WriteAt by using locks to make the operations sequential. This is only really used in the tests though. This eliminates the need for the PSeekFile and SharedCursor types. The standard File and Cursor types can be used instead, and if shared ownership is needed, Arc can be used. Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
This commit is contained in:
+6
-4
@@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: 2023 Andrew Gunnerson
|
||||
// SPDX-FileCopyrightText: 2023-2025 Andrew Gunnerson
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#[cfg(not(windows))]
|
||||
@@ -7,7 +7,7 @@ mod fuzz {
|
||||
|
||||
use avbroot::{
|
||||
format::fec::FecImage,
|
||||
stream::{FromReader, SharedCursor, WriteZerosExt},
|
||||
stream::{FromReader, MutexFile, UserPosFile, WriteZerosExt},
|
||||
};
|
||||
use honggfuzz::fuzz;
|
||||
|
||||
@@ -18,12 +18,14 @@ mod fuzz {
|
||||
|
||||
let reader = Cursor::new(data);
|
||||
if let Ok(fec) = FecImage::from_reader(reader) {
|
||||
let mut input = SharedCursor::new();
|
||||
let input = MutexFile::new(Cursor::new(Vec::new()));
|
||||
|
||||
// Allow verify() to get further, but don't blow up the host
|
||||
// with excessive memory usage.
|
||||
if fec.data_size < 64 * 1024 * 1024 {
|
||||
input.write_zeros_exact(fec.data_size).unwrap();
|
||||
UserPosFile::new(&input)
|
||||
.write_zeros_exact(fec.data_size)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let _ = fec.verify(&input, &cancel_signal);
|
||||
|
||||
Reference in New Issue
Block a user