Dataset Viewer

The dataset viewer is not available because its heuristics could not detect any supported data files. You can try uploading some data files, or configuring the data files location manually.

YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

ncnn blob index OOB — heap-buffer-overflow WRITE

Vulnerability

CWE-787: Out-of-bounds Write in ncnn model loading (net.cpp).

In Net::load_param_bin(), blob indices read from the binary .param.bin file are used directly as vector subscripts without bounds checking:

// net.cpp:1559-1564
int bottom_blob_index;
READ_VALUE(bottom_blob_index)           // from file, no validation
Blob& blob = d->blobs[bottom_blob_index]; // OOB if >= blob_count
blob.consumer = i;                       // HEAP BUFFER OVERFLOW WRITE

In Net::load_param() (text format), blob_count in the header controls vector allocation, but no check ensures blob_index (incremented per top blob) stays in bounds:

// net.cpp:1208-1216
Blob& blob = d->blobs[blob_index];      // OOB if blob_index >= blob_count
blob.name = std::string(blob_name);      // WRITE to OOB Blob
blob.producer = i;                       // WRITE to OOB Blob

ASAN Traces

Binary format — WRITE of size 4:

ERROR: AddressSanitizer: heap-buffer-overflow
WRITE of size 4
  #0 ncnn::Net::load_param_bin() net.cpp:1564

Text format — heap-buffer-overflow via string assignment:

ERROR: AddressSanitizer: heap-buffer-overflow
READ of size 8 (string move-assign to OOB Blob)
  #0 ncnn::Net::load_param() net.cpp:1213

Reproduction

git clone https://github.com/Tencent/ncnn.git && cd ncnn && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo \
  -DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer" \
  -DCMAKE_C_FLAGS="-fsanitize=address -fno-omit-frame-pointer" \
  -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" \
  -DNCNN_VULKAN=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF \
  -DNCNN_BUILD_TESTS=OFF -DNCNN_OPENMP=OFF
make -j$(nproc) ncnn
g++ -fsanitize=address -fno-omit-frame-pointer -O1 -g -DNDEBUG \
  -I../src -I./src harness.cpp -L./src -lncnn -lpthread -o harness
python3 craft_malicious_ncnn.py
./harness malicious.param.bin   # binary format: WRITE OOB
./harness malicious.param       # text format: WRITE OOB

Fix

Add bounds checking before accessing d->blobs[]:

// Binary format (load_param_bin):
if (bottom_blob_index < 0 || bottom_blob_index >= (int)d->blobs.size()) {
    NCNN_LOGE("invalid bottom_blob_index %d", bottom_blob_index);
    return -1;
}

// Text format (load_param):
if (blob_index >= (int)d->blobs.size()) {
    NCNN_LOGE("blob_index %d exceeds blob_count", blob_index);
    return -1;
}
Downloads last month
43