* fix crash reading past end of memory-mapped model file
DataReaderFromMemory used by mapped model loading was unbounded:
read()/reference() advanced past the mapped region, so a truncated
or corrupt .bin crashed with an access violation inside
ModelBinFromDataReader instead of failing cleanly.
Add a size-aware DataReaderFromMemory ctor that clamps reads and
fails references past the end, use it in the mapped branches of
Net::load_model, and propagate load_model()'s return value which
was previously dropped.
* fix bounded memory reader scans and add loading regressions
* f
* reuse bounded memory reader scan buffer
---------
Co-authored-by: Dr3ladwyn <Dr3ladwyn@users.noreply.github.com>
Co-authored-by: nihui <nihuini@tencent.com>
* Harden Net graph loading and metadata validation
Apply count and blob index validation from Tencent/ncnn PRs #6902,
#6916, #6922 and #6949 to both text and binary graph loading. Bound
header counts to 1,000,000 while preserving repeated blob references
and zero-output layers.
Validate text integer tokens and name lengths, shape hint types,
record lengths and extent arithmetic, feature masks, layer type tags,
and one-blob layer connection counts. Guard missing producers during
extraction and handle null custom layer creators.
Own partially loaded layers before reading their connections, honor
registered destroyers on all failure and CPU replacement paths, and
clear stale graph metadata when reloading or rejecting a model.
Add in-memory Net regressions for malformed and truncated inputs, valid
shape layouts, reload isolation, custom layer lifetime and external
inputs, without requiring filesystem access.
Validated with native tests, SqueezeNet inference, ASan/UBSan and
32-bit big-endian PowerPC tests; compile checked Vulkan and reduced
C++03 configurations.
Sources:
https://github.com/Tencent/ncnn/pull/6902https://github.com/Tencent/ncnn/pull/6916https://github.com/Tencent/ncnn/pull/6922https://github.com/Tencent/ncnn/pull/6949
Co-authored-by: kaltsit-10 <kaltsit-10@users.noreply.github.com>
Co-authored-by: beilzx <2069360659@qq.com>
Co-authored-by: ktz03 <2484593937@qq.com>