ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
mdl_verify_rabook.c File Reference

Strict allocation-free RBKC validation for media downloader artifacts. More...

#include <stddef.h>
#include "book_chunked.h"
#include "mdl_verify_rabook_internal.h"
#include "miniz.h"
Include dependency graph for mdl_verify_rabook.c:

Go to the source code of this file.

Data Structures

struct  mdl_rabook_io_t
 Positioned exact-read adapter state. More...

Enumerations

enum  mdl_verify_rabook_limit_t : uint32_t {
  k_rabook_chunk_bytes = 4U * 1024U * 1024U ,
  k_rabook_compressed_bytes = k_rabook_chunk_bytes + (64U * 1024U) ,
  k_rabook_scratch_bytes = 4U * 1024U * 1024U ,
  k_rabook_table_entries = 65537U ,
  k_rabook_read_calls = 1000000U
}
 Bounded strict-reader workspace profile. More...

Functions

static ra8_err_t internal_rabook_read (void *opaque, uint64_t offset, uint8_t *destination, uint32_t length)
 Serve one exact positioned RBKC read through the portable file facade.
static ra8_err_t internal_rabook_inflate (const void *source, size_t source_bytes, void *destination, size_t destination_bytes, size_t *out_bytes)
 Inflate one complete RFC 1950 chunk into caller storage.
ra8_err_t priv_mdl_verify_rabook (fw_fs_file_t *file, uint64_t size_bytes, mdl_export_workspace_t *workspace, mdl_verify_report_t *report)
 Strictly validate one borrowed RBKC .rabook file.

Detailed Description

Strict allocation-free RBKC validation for media downloader artifacts.

Adapts positioned portable-file reads to the production chunked reader and validates every RFC 1950 stream plus the complete inner RABOOK1 structure and CRC using only bounded caller workspace.

Since
0.1.0

Definition in file mdl_verify_rabook.c.

Enumeration Type Documentation

◆ mdl_verify_rabook_limit_t

enum mdl_verify_rabook_limit_t : uint32_t

Bounded strict-reader workspace profile.

Enumerator
k_rabook_chunk_bytes 

Largest inflated chunk.

k_rabook_compressed_bytes 

Largest accepted compressed zlib stream.

k_rabook_scratch_bytes 

CRC and node ownership work.

k_rabook_table_entries 

At most 65,536 RBKC chunks.

k_rabook_read_calls 

Short-read progress ceiling.

Definition at line 21 of file mdl_verify_rabook.c.

Function Documentation

◆ internal_rabook_inflate()

ra8_err_t internal_rabook_inflate ( const void * source,
size_t source_bytes,
void * destination,
size_t destination_bytes,
size_t * out_bytes )
static

Inflate one complete RFC 1950 chunk into caller storage.

Uses miniz's bounded memory inflater and reports the exact produced extent for the chunk reader's independent length check.

Parameters
[in]sourceComplete compressed stream.
[in]source_bytesCompressed stream extent.
[out]destinationInflated destination.
[in]destination_bytesWritable destination extent.
[out]out_bytesExact inflated extent on success.
Returns
Canonical inflate status.
Return values
k_ra8_okThe zlib stream inflated completely.
k_ra8_err_validation_failedThe stream was malformed or oversized.
Precondition
Pointer arguments are non-NULL and spans match their byte counts.
Source and destination storage do not overlap.
Postcondition
Success initializes out_bytes and that many destination bytes.
Failure does not publish a usable output extent.
Note
Performs no allocation and retains no stream state.
Since
0.1.0

Definition at line 101 of file mdl_verify_rabook.c.

References k_ra8_err_validation_failed, and k_ra8_ok.

Referenced by priv_mdl_verify_rabook().

◆ internal_rabook_read()

ra8_err_t internal_rabook_read ( void * opaque,
uint64_t offset,
uint8_t * destination,
uint32_t length )
static

Serve one exact positioned RBKC read through the portable file facade.

Bounds the range against the snapshotted extent, seeks once, then tolerates positive short reads under a fixed progress ceiling.

Parameters
[in,out]opaqueBound mdl_rabook_io_t.
[in]offsetAbsolute source byte offset.
[out]destinationDestination spanning length bytes.
[in]lengthExact requested byte count.
Returns
Portable seek/read or range status.
Return values
k_ra8_okExactly length bytes were copied.
k_ra8_err_out_of_rangeThe requested range exceeds the snapshot.
k_ra8_err_invalid_stateThe backend stopped making progress.
Precondition
All pointers are non-NULL and the file remains open.
destination spans length writable bytes.
Postcondition
Success initializes the complete destination span.
Failure never claims a complete transfer.
Note
Not thread-safe for a shared file cursor.
Since
0.1.0

Definition at line 58 of file mdl_verify_rabook.c.

References fw_fs_read(), fw_fs_seek(), k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_err_out_of_range, k_ra8_ok, and k_rabook_read_calls.

Referenced by priv_mdl_verify_rabook().

◆ priv_mdl_verify_rabook()

ra8_err_t priv_mdl_verify_rabook ( fw_fs_file_t * file,
uint64_t size_bytes,
mdl_export_workspace_t * workspace,
mdl_verify_report_t * report )

Strictly validate one borrowed RBKC .rabook file.

Opens the callback-driven chunk reader, validates every compressed stream and the complete inner RABOOK1 structure/CRC, then reports bounded chapter and image counts.

Parameters
[in,out]fileBorrowed readable and seekable file.
[in]size_bytesImmutable complete file extent.
[in,out]workspaceExclusive caller-owned validation arena.
[out]reportCandidate report populated only on success.
Returns
Strict reader, workspace, or portable-file status.
Return values
k_ra8_okEvery outer and inner byte passed strict validation.
k_ra8_err_invalid_sizeA wire or caller-workspace bound was exceeded.
k_ra8_err_validation_failedA zlib stream or RABOOK1 structure failed.
Precondition
All pointers are non-NULL and file remains open for the call.
workspace was reset by the owning verifier and is exclusively mutable.
Postcondition
Success initializes RABOOK counts in report.
The borrowed file remains open; its final cursor is unspecified.
Note
Not thread-safe for a shared file or workspace.
Since
0.1.0

Definition at line 120 of file mdl_verify_rabook.c.

References book_header_t::author_off, book_chunked_open(), book_chunked_validate_strict(), book_header_t::chapter_count, book_header_t::identifier_off, book_header_t::image_count, internal_rabook_inflate(), internal_rabook_read(), k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_ok, k_rabook_chunk_bytes, k_rabook_compressed_bytes, k_rabook_scratch_bytes, k_rabook_table_entries, mdl_export_workspace_take(), RA8_PRIV, and book_header_t::title_off.

Referenced by internal_verify_borrowed().