1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Raw-byte backing store shared by every parsed-model type.
//!
//! A `Parsed*` type (`ParsedModel`, `ParsedGguf`, `ParsedPth`) holds its source
//! bytes behind a `Backing`, which is either:
//!
//! - `Backing::Mmap` — a memory-mapped view of the file, used by the path-based
//! `parse*` entry points. The OS pages bytes in lazily (no heap), the
//! **trusted-local-file fast path**. A truncated or concurrently-written file
//! can fault the mapping (`SIGBUS`), so this variant is *not* for untrusted
//! input.
//! - `Backing::Owned` — an owned `Vec<u8>` read fully into the heap, used by the
//! copy-based `parse_*_bytes` / `parse_*_from_reader` entry points. No mmap, so
//! a truncated or hostile source yields a clean `Err`, never a `SIGBUS` — the
//! **recommended path for untrusted input**.
//!
//! Both variants `Deref` to `[u8]`, so the structure parsers and tensor-data
//! accessors read the bytes identically regardless of origin.
use Deref;
/// Byte storage behind a parsed model — a memory map or an owned copy.
///
/// Crate-internal: callers never see a `Backing`; the `Parsed*` types expose
/// their bytes through `&[u8]` / `Cow<[u8]>` accessors instead.
pub