You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make page CRC verification toggleable by end-users (#44)
* Fix Cargo warning on latest Rust versions about custom cfg flags
* Make page CRC verification toggleable by end-users
These changes make the Ogg page CRC verification check toggleable at
runtime by end-users via a new `PageParsingOptions` struct that may be
passed at reader/parser construction time. I have paid special attention
to making the new feature both backwards and forwards compatible, which
led me to taking the following design choices:
- No signature of any existing public method was modified. People
looking into changing parsing behavior via the new
`PageParsingOptions` struct must use the new `*_with_parse_opts`
methods.
- Marking `PageParsingOptions` as `#[non_exhaustive]`, so that we may
add new public fields to it in the future without a semver-breaking
change. Users must always default-initialize this struct. It only
derives `Clone` too, in case we ever need to make it hold non-`Copy`
types.
- Shared ownership of the `PageParsingOptions` between different reader
structs is achieved through `Arc`s, which ensures that no struct stops
being `Send` or `Sync` with a negligble performance impact.
The `fuzzing` cfg flag is still honored after these changes by using it
to set a default value for the new `verify_hash` page parsing option
accordingly.
* Fix build with `async` feature
* Attempt to fix MSRV build
* Bump MSRV to 1.61
We required it anyway due to recent changes.
* Further CI MSRV check fixes
Copy file name to clipboardExpand all lines: src/reading.rs
+96-28Lines changed: 96 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@ use std::mem::replace;
21
21
usecrate::crc::vorbis_crc32_update;
22
22
usecrate::Packet;
23
23
use std::io::Seek;
24
+
use std::sync::Arc;
24
25
25
26
/// Error that can be raised when decoding an Ogg transport.
26
27
#[derive(Debug)]
@@ -157,6 +158,28 @@ impl OggPage {
157
158
}
158
159
}
159
160
161
+
/// A set of options that control details on how a `PageParser` parses OGG pages.
162
+
#[derive(Debug,Clone)]
163
+
#[non_exhaustive]// Allow for non-breaking field expansion: https://doc.rust-lang.org/cargo/reference/semver.html#struct-add-public-field-when-no-private
164
+
pubstructPageParsingOptions{
165
+
/// Whether the CRC checksum for the parsed pages will be verified to match
166
+
/// the page and packet data. Verifying it is the default behavior, as
167
+
/// a hash mismatch usually signals stream corruption, but specialized
168
+
/// applications may wish to deal with the contained data anyway.
169
+
pubverify_checksum:bool,
170
+
}
171
+
172
+
implDefaultforPageParsingOptions{
173
+
fndefault() -> Self{
174
+
Self{
175
+
// Do not verify checksum by default when the decoder is being fuzzed.
176
+
// This makes it easier for random input from fuzzers to reach decoding code that's
177
+
// actually interesting, instead of being rejected early due to checksum mismatch.
178
+
verify_checksum: !cfg!(fuzzing),
179
+
}
180
+
}
181
+
}
182
+
160
183
/**
161
184
Helper struct for parsing pages
162
185
@@ -178,6 +201,8 @@ pub struct PageParser {
178
201
/// after segments have been parsed, this contains the segments buffer,
179
202
/// after the packet data have been read, this contains the packets buffer.
180
203
segments_or_packets_buf:Vec<u8>,
204
+
205
+
parse_opts:Arc<PageParsingOptions>,
181
206
}
182
207
183
208
implPageParser{
@@ -193,6 +218,23 @@ impl PageParser {
193
218
/// You should allocate and fill such an array, in order to pass it to the `parse_segments`
letmut segments_buf = vec![0; page_segments];// TODO fix this, we initialize memory for NOTHING!!! Out of some reason, this is seen as "unsafe" by rustc.
826
871
tri!(self.rdr.read_exact(&mut segments_buf));
827
872
828
873
let page_siz = pg_prs.parse_segments(segments_buf);
0 commit comments