42typedef enum : uint32_t {
110 if ((uint64_t)n > (s->
size - s->
pos)) {
113 const size_t got = s->
read(s->
ctx, s->
pos, dst, n);
118 s->
crc = (uint32_t)mz_crc32(s->
crc, dst, n);
120 s->
pos += (uint64_t)n;
180 uint32_t xlen = (uint32_t)xl[0] | ((uint32_t)xl[1] << (uint32_t)
k_gz_shift_byte);
183 const size_t n = (xlen > (uint32_t)
sizeof(skip)) ?
sizeof(skip) : (size_t)xlen;
260 const uint32_t stored = (uint32_t)hc[0] | ((uint32_t)hc[1] << (uint32_t)
k_gz_shift_byte);
261 if (stored != want) {
322 const size_t want = (remain > (uint64_t)
sizeof(st->
win)) ?
sizeof(st->
win) : (size_t)remain;
337 const mz_uint32 flags = (mz_uint32)TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF |
338 (more_input ? (mz_uint32)TINFL_FLAG_HAS_MORE_INPUT : 0U);
347 if (out_bytes > 0U) {
348 st->
crc = (uint32_t)mz_crc32(st->
crc, &st->
out[st->
total], out_bytes);
350 st->
total += out_bytes;
356 if (ts == TINFL_STATUS_DONE) {
360 if (ts == TINFL_STATUS_NEEDS_MORE_INPUT) {
363 if (ts == TINFL_STATUS_HAS_MORE_OUTPUT) {
394 const uint64_t trailer_pos = st->
src->
pos - leftover;
395 const uint64_t remain = st->
src->
size - trailer_pos;
403 const size_t got = st->
src->
read(st->
src->
ctx, trailer_pos, tr,
sizeof(tr));
404 if (got !=
sizeof(tr)) {
407 uint32_t crc_stored = 0U;
408 uint32_t isize_stored = 0U;
409 for (uint32_t i = 0U; i < 4U; ++i) {
411 isize_stored |= (uint32_t)tr[i + 4U] << ((uint32_t)
k_gz_shift_byte * i);
413 if (crc_stored != st->
crc) {
424 if (sig ==
nullptr) {
445 static const char*
const tag =
"unarch_gzip";
446 if (read ==
nullptr) {
464 .crc = (uint32_t)MZ_CRC32_INIT,
475 st.
crc = (uint32_t)MZ_CRC32_INIT;
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
ra8_err_t ra8_decomp_budget_charge_output(ra8_decomp_budget_t *b, uint64_t in_total, uint64_t out_delta)
Charge decompressed output against the cap and ratio bounds.
ra8_err_t ra8_decomp_budget_charge_iter(ra8_decomp_budget_t *b)
Charge one decode-loop turn against the iteration budget.
ra8_err_t ra8_decomp_budget_init(ra8_decomp_budget_t *b, const ra8_decomp_limits_t *limits)
Bind a budget to a policy (or the default policy) and zero it.
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_checksum_mismatch
Stored / transmitted checksum does not match computed value.
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
#define ra8_log_error(tag, message)
RA8 log error.
Loop-carried state of the windowed DEFLATE inflation.
uint8_t * out
Destination arena.
bool done
tinfl reported stream end.
ra8_decomp_budget_t budget
Unified decompression budget.
uint8_t win[k_gz_in_chunk]
Input window.
size_t total
Payload bytes produced so far.
size_t out_cap
Arena capacity.
size_t win_len
Valid bytes in the window.
size_t win_ofs
Consumed bytes in the window.
gz_src_t * src
Byte source (cursor at the window end).
uint32_t crc
Running CRC32 of the produced payload.
Cursor-tracked exact-read byte source with a running header CRC.
uint64_t pos
Next unconsumed byte offset.
bool track_crc
Fold consumed bytes into crc.
unarch_read_fn read
Byte reader over the member.
uint64_t size
Member length in bytes.
uint32_t crc
Running CRC32 of consumed bytes.
void * ctx
Context for read.
Running consumption tracker charged by a decoder against its policy.
One decompression policy: the five resource bounds decoders enforce.
ra8_err_t unarch_gzip_unwrap(unarch_read_fn read, void *ctx, uint64_t size, uint8_t *out, size_t out_cap, const ra8_decomp_limits_t *limits, size_t *out_len)
Decode one whole gzip member from a read seam into a caller arena.
static ra8_err_t internal_skip_string(gz_src_t *s)
Skip a NUL-terminated header string (FNAME / FCOMMENT), bounded.
static ra8_err_t internal_parse_header(gz_src_t *s)
Parse the whole RFC 1952 header, leaving the cursor at the data.
static ra8_err_t internal_verify_trailer(const gz_inflate_t *st)
Verify the gzip trailer against the produced payload.
gz_grammar_t
RFC 1952 constants and this decoder's loop windows.
@ k_gz_trailer_len
CRC32 + ISIZE trailer length.
@ k_gz_idx_flg
Header index of FLG.
@ k_gz_cm_deflate
The only defined compression method.
@ k_gz_flg_fhcrc
Header CRC16 present.
@ k_gz_idx_id1
Header index of ID1.
@ k_gz_isize_mask
ISIZE is the payload length mod 2^32.
@ k_gz_idx_cm
Header index of CM.
@ k_gz_hdr_fixed
Fixed header length in bytes.
@ k_gz_xlen_bytes
FEXTRA length-field size.
@ k_gz_shift_byte
Bits per byte for LE assembly.
@ k_gz_fhcrc_bytes
FHCRC field size.
@ k_gz_flg_fcomment
Comment present.
@ k_gz_in_chunk
Input refill window per pass.
@ k_gz_flg_fextra
Extra field present.
@ k_gz_out_window
Output window per pass (charge granularity for bomb detection).
@ k_gz_flg_reserved
Reserved bits: must be zero.
@ k_gz_crc16_mask
FHCRC is the low 16 CRC32 bits.
@ k_gz_flg_fname
Original file name present.
@ k_gz_idx_id2
Header index of ID2.
static ra8_err_t internal_skip_fextra(gz_src_t *s)
Skip the FEXTRA subfield block (RFC 1952 XLEN + XLEN bytes), bounded.
static ra8_err_t internal_inflate_pass(gz_inflate_t *st)
Run one refill + inflate pass of the DEFLATE loop.
static ra8_err_t internal_src_take(gz_src_t *s, uint8_t *dst, size_t n)
Consume exactly n bytes from the source into dst.
static tinfl_decompressor s_gz_inflator
The single-client tinfl state (too large for a task stack).
bool unarch_gzip_magic(const uint8_t *sig, size_t sig_len)
Whether sig begins with the gzip member magic (1F 8B).
Clean-room gzip member decoder (RFC 1952) over the miniz DEFLATE core.
@ k_unarch_gzip_str_max
Max FNAME / FCOMMENT bytes accepted.
@ k_unarch_gzip_sig_len
Magic length (1F 8B).
size_t(* unarch_read_fn)(void *ctx, uint64_t offset, void *buf, size_t len)
Seek+read backing over an archive's bytes.