Skip to main content

import

Function import 

Source
pub fn import(blob: &[u8], fds: &[RawFd]) -> Result<TensorDyn>
Expand description

Reconstruct a tensor from a blob.

Import dups every fd it retains, so the result is fully independent and the source tensor may die immediately. In inline mode the result is a new allocation holding a copy of the carried bytes.

fds is the table that travelled beside the blob; a reference-mode plane’s handle indexes into it. Pass an empty slice for an inline blob, and on Windows for a reference-mode one too: a D3D11 texture is named by the NT handle values in the plane’s BlobPlane::handle_bytes, and this duplicates them out of the exporting process (the header’s pid) with OpenProcess(PROCESS_DUP_HANDLE) when that is not this process. The duplication is what makes the import independent there, exactly as dup does on Unix. Both the pid and the handle values are blob fields, so a hostile blob can steer that probe – see BlobHeader::pid for what it can and cannot reach.

blob is untrusted: it may come from another wheel, another process, or a network. Every length has already been bounded by BlobView::parse; this function adds the semantic checks that parsing alone cannot make, and every index is bounded against fds before use.