Heap-buffer-overflow in Concat::forward (AVX and generic x86 kernel) with multi-scale YOLO export
error log | 日志或报错信息 | ログ
AVX build: ==16564==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x632000045844 WRITE of size 73728 at 0x632000045844 thread T0 #0 ... (libasan) #1 ncnn::Concat_x86_avx::forward(std::vector<ncnn::Mat, std::allocatorncnn::Mat > const&, std::vector<ncnn::Mat, std::allocatorncnn::Mat >&, ncnn::Option const&) const #2 ncnn::NetPrivate::do_forward_layer(...) #3 ncnn::NetPrivate::forward_layer(...) [recurses through the graph] ... #45 ncnn::Extractor::extract(int, ncnn::Mat&, int)
0x632000045844 is located 0 bytes to the right of 86084-byte region [0x632000030800,0x632000045844) allocated by thread T0 here: #0 posix_memalign (libasan) #1 ncnn::PoolAllocator::fastMalloc(unsigned long)
Non-AVX build (rebuilt with -DNCNN_AVX2=OFF -DNCNN_AVX=OFF), identical size/offset: ==4778==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x63200023d844 WRITE of size 73728 at 0x63200023d844 thread T0 #0 ... (libasan) #1 ncnn::Concat_x86::forward(std::vector<ncnn::Mat, std::allocatorncnn::Mat > const&, std::vector<ncnn::Mat, std::allocatorncnn::Mat >&, ncnn::Option const&) const #2 ncnn::NetPrivate::do_forward_layer(...) ... 0x63200023d844 is located 0 bytes to the right of 86084-byte region [0x632000228800,0x63200023d844) allocated by thread T0 here: #0 posix_memalign (libasan) #1 ncnn::PoolAllocator::fastMalloc(unsigned long)
context | 编译/运行环境 | バックグラウンド
ncnn: reproduced on tag 20260526 (commit e54f7b1) and on current master as of Sept 2026 Platform: x86_64, Ubuntu on WSL2 Compiler: gcc, built with -fsanitize=address -O0 -g Reproduced both with default build and with -DNCNN_AVX2=OFF -DNCNN_AVX=OFF (same overflow, same size/offset, in Concat_x86_avx and Concat_x86 respectively)
Model: yolo26n.pt, exported via Ultralytics: yolo export model=yolo26n.pt format=ncnn quantize=16 imgsz=384,224 Input blob: in0, output blob: out0 Input tensor: 384x224 RGB
how to reproduce | 复现步骤 | 再現方法
1 Export a YOLO26n model to ncnn fp16 as above (or use attached .param/.bin). 2 Build a minimal test harness against ncnn with -fsanitize=address, load the model, create one ncnn::Extractor, feed a 384x224 RGB in0, and call ex.extract("out0", out). 3 Run under ASan — crashes on the very first inference call.
more | 其他 | その他
I originally found this while investigating what looked like a steady memory leak across repeated inference calls (free memory dropped every call, never recovered even after manually clearing my PoolAllocators). Bisecting by extracting different intermediate blobs eventually pointed at a Concat layer, and ASan confirmed a real heap-buffer-overflow rather than a leak — my best guess is that in normal (non-ASan) runs this usually lands in slack space inside a reused pool allocator block, so it goes unnoticed, but it likely still corrupts adjacent allocator bookkeeping over many calls, which would explain the apparent "leak."
The graph has several Concat layers joining the three YOLO detection scales, which have different anchor counts (1344/336/84) — I suspect the output size calculation for one of these is off for this particular combination of input shapes, but haven't pinned down the exact layer name yet. Happy to attach the .param/.bin files and/or a minimal repro .cpp if that would help narrow it down.
yolo26n_ncnn_model.zip — the exact .param/.bin used in both traces above (fp16 export, 384x224 input, in0/out0 blob names). mpptest.zip — the actual test harness used to find/confirm this. Build with: g++ -O0 -g -fsanitize=address -I/src -I/build/src -o mpptest_asan mpptest.cpp /build/src/libncnn.a -lpthread -fopenmp -lm then run: ./mpptest_asan yolo26n-fp16.param yolo26n-fp16.bin Note: this harness pulls a frame from a live MJPEG stream (fetch_one_frame(), reading the URL from mppnet.conf or defaulting to http://127.0.0.1/mjpeg) — it needs a reachable MJPEG source to get past frame capture before it reaches the crash. If you don't have one handy, the crash itself doesn't depend on real frame content — any 384x224x3 buffer fed into ncnn::Mat::from_pixels_resize and then ex.extract("out0", out) should reproduce it; happy to strip the networking part out into a minimal version if that's easier for you to run. yolo26n_ncnn_model.zip
Source: Tencent/ncnn