#7025·ncnn

Concat::forward(AVX 和通用 x86 内核) 在多尺度 YOLO 导出时发生堆缓冲区溢出

作者: sergshadrap创建于 2026年9月25日更新于 2026年9月29日

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."