Skip to content

Fix empty string bounds check in ParamDict::load_param - #6918

Open
beilzx wants to merge 1 commit into
Tencent:masterfrom
beilzx:fix-paramdict-empty-string-bounds
Open

Fix empty string bounds check in ParamDict::load_param#6918
beilzx wants to merge 1 commit into
Tencent:masterfrom
beilzx:fix-paramdict-empty-string-bounds

Conversation

@beilzx

@beilzx beilzx commented Aug 17, 2026

Copy link
Copy Markdown

Summary

This PR fixes a heap-buffer-overflow (READ) in ParamDict::load_param when parsing string parameters in .param files.

Changes

  • Added an emptiness check (!d->params[id].s.empty() &&) before accessing s[s.size() - 1] to strip trailing quotes.
  • Prevents size_t underflow when the parsed string is empty, which previously caused an out-of-bounds heap read.

Verification

  • Reproduced the crash with the attached PoC (poc5) using AddressSanitizer.
  • After applying this patch, ./ncnn_param poc5 exits cleanly without ASAN errors.

Fixes #6915

Guard trailing-quote stripping with an emptiness check to prevent
size_t underflow and heap-buffer-overflow when parsing malformed
.param files.

Fixes Tencent#6915
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) in ParamDict::load_param string parsing (src/paramdict.cpp:387)

1 participant