Dataset Viewer
The dataset viewer is not available for this dataset.
Unexpected token '<', "<html> <h"... is not valid JSON

Need help to make the dataset viewer work? Make sure to review how to configure the dataset viewer, and open a discussion for direct support.

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

Check out the documentation for more information.

MNN computeShapeForBlob dims overflow + outputIndexes OOB

Vulnerability

CWE-787: Out-of-bounds Write in MNN model loading (InitNet.cpp).

Bug 1: dims overflow — heap-buffer-overflow WRITE

computeShapeForBlob() loops over Blob.dims from the model file and writes each element into a fixed dim[MNN_MAX_TENSOR_DIM=9] array. The FlatBuffers schema allows arbitrary dims vector length, but the C++ struct is fixed:

// InitNet.cpp:24-26
output->buffer().dimensions = parameter->dims()->size();  // file-controlled
for (int i = 0; i < output->buffer().dimensions; i++) {
    output->buffer().dim[i].extent = parameter->dims()->Get(i);  // OOB if > 9
}

The dim array is declared in TensorUtils.hpp:96:

halide_dimension_t dims[MNN_MAX_TENSOR_DIM];  // fixed size = 9

A Blob with 15 dims writes 6 elements past the array end, corrupting adjacent heap memory in the NativeInsideDescribe struct (280 bytes).

Bug 2: outputIndexes OOB — heap-buffer-overflow READ/WRITE

initConstTensors() uses op->outputIndexes()->data()[0] as a vector subscript without bounds checking against tensors.size():

// InitNet.cpp:52-53
auto index = op->outputIndexes()->data()[0];  // int32_t from file, unchecked
tensors[index].reset(new Tensor);              // OOB → wild pointer access

The tensors vector is sized by net->tensorName()->size(). A Const op with outputIndexes=[999] and only 1 tensorName causes OOB access.

ASAN Traces

Dims overflow — WRITE of size 4:

ERROR: AddressSanitizer: heap-buffer-overflow
WRITE of size 4 at 0x... thread T0
  #0 MNN::computeShapeForBlob() InitNet.cpp:26
  #1 MNN::initConstTensors() InitNet.cpp:60
  #2 MNN::Schedule::schedule() Schedule.cpp:303
  #3 MNN::Interpreter::createMultiPathSession() Interpreter.cpp:279
0x... is located 4 bytes after 280-byte region

Index OOB — READ of size 8 (wild pointer via shared_ptr::reset):

ERROR: AddressSanitizer: heap-buffer-overflow
READ of size 8 at 0x... thread T0 (wild pointer)
  #0 shared_ptr::reset() InitNet.cpp:53
  #1 MNN::initConstTensors() InitNet.cpp:53
  #2 MNN::Schedule::schedule() Schedule.cpp:303
  #3 MNN::Interpreter::createMultiPathSession() Interpreter.cpp:279

Reproduction

git clone --depth=1 https://github.com/alibaba/MNN.git && cd MNN && 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" \
  -DMNN_BUILD_CONVERTER=OFF -DMNN_BUILD_TOOLS=OFF -DMNN_BUILD_TEST=OFF \
  -DMNN_BUILD_DEMO=OFF -DMNN_BUILD_QUANTOOLS=OFF \
  -DMNN_OPENCL=OFF -DMNN_VULKAN=OFF -DMNN_METAL=OFF -DMNN_CUDA=OFF \
  -DMNN_OPENMP=OFF -DMNN_BUILD_TRAIN=OFF
make -j$(nproc) MNN
g++ -fsanitize=address -fno-omit-frame-pointer -O1 -g \
  -I../include harness.cpp -L. -lMNN -Wl,-rpath,. -lpthread -o harness
python3 craft_malicious_mnn.py
./harness malicious_dims.mnn    # dims overflow WRITE
./harness malicious_index.mnn   # index OOB wild pointer

Fix

// Bug 1: Cap dims to MNN_MAX_TENSOR_DIM
if (parameter->dims() != nullptr) {
    int ndims = parameter->dims()->size();
    if (ndims > MNN_MAX_TENSOR_DIM) {
        MNN_ERROR("dims count %d exceeds MNN_MAX_TENSOR_DIM\n", ndims);
        return true;
    }
    output->buffer().dimensions = ndims;
    // ...
}

// Bug 2: Bounds-check outputIndexes
auto index = op->outputIndexes()->data()[0];
if (index < 0 || index >= (int)tensors.size()) {
    code = INVALID_VALUE;
    return false;
}
Downloads last month
27