Views
No views yet
size_t from binary model files and multiplies them without overflow checking for heap allocation.1// CPUMatrix.h:535-536
2size_t numRows, numCols;
3stream >> matrixName >> format >> numRows >> numCols; // from file
4ElemType* d_array = new ElemType[numRows * numCols]; // NO OVERFLOW CHECKGPUMatrix.h:657.| File | Description |
|---|---|
poc_cntk_cpumatrix_overflow.py | Demonstrates the integer overflow with crafted dimensions |
Crafted .model/.dnn file
→ ComputationNetwork::Read() [ComputationNetwork.cpp:323]
→ ReadPersistableParameters() [ComputationNetwork.cpp:255]
→ node->Load(fstream, modelVersion) [ComputationNetwork.cpp:299]
→ operator>>(File&, CPUMatrix&) [CPUMatrix.h:525]
→ new ElemType[numRows * numCols] [CPUMatrix.h:536] ← OVERFLOW| numRows | numCols | Product (size_t) | Allocation |
|---|---|---|---|
2^32 | 2^32 | wraps to 0 | 0 bytes |
SIZE_MAX | 2 | wraps to SIZE_MAX-1 | near-max |
2^33+1 | 2^31 | wraps to 2^31 | 8 GB |