Skip to content

fix(net): add blob_index bounds check in load_param - #6916

Open
beilzx wants to merge 1 commit into
Tencent:masterfrom
beilzx:fix-net-load-param-blob-index-bounds
Open

fix(net): add blob_index bounds check in load_param#6916
beilzx wants to merge 1 commit into
Tencent:masterfrom
beilzx:fix-net-load-param-blob-index-bounds

Conversation

@beilzx

@beilzx beilzx commented Aug 17, 2026

Copy link
Copy Markdown

Summary

A malformed .param file with an under-reported blob_count can cause blob_index to grow beyond d->blobs.size(), leading to out-of-bounds read/write via Blob& blob = d->blobs[blob_index].

Changes

  • Add blob_index >= d->blobs.size() bounds check before bottom-blob assignment
  • Add blob_index >= d->blobs.size() bounds check before top-blob assignment
  • Return -1 and clean up partial net state on out-of-range detection

Verification

  • Built with AddressSanitizer (-fsanitize=address)
  • Reproduced crash with AFL++ generated PoC (heap-buffer-overflow at net.cpp:1464)
  • After patch: ./ncnn_param poc6 exits cleanly with EXIT=0, no ASAN errors

Fixes #6913

A malformed .param file with an under-reported blob_count can cause
blob_index to grow beyond d->blobs.size(), leading to out-of-bounds
read/write via Blob& blob = d->blobs[blob_index].

This patch adds bounds checks before both bottom-blob and top-blob
indexing, returning -1 and cleaning up the partial net state when
an out-of-range index is detected.

Fixes Tencent#6913
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: heap-buffer-overflow (read/write) in Net::load_param blob index out-of-bounds (src/net.cpp:1464)

1 participant